| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Onboarding; |
| 4 |
|
| 5 |
use Give\Form\Template\Options as TemplateOptions; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 2.8.0 |
| 9 |
*/ |
| 10 |
class DefaultFormFactory |
| 11 |
{ |
| 12 |
|
| 13 |
/** |
| 14 |
* Green to match the Onboarding Wizard. |
| 15 |
* |
| 16 |
* @since 2.8.0 |
| 17 |
* @var string; |
| 18 |
* |
| 19 |
*/ |
| 20 |
protected $primaryColor = '#4fa651'; |
| 21 |
|
| 22 |
/** |
| 23 |
* @since 2.8.0 |
| 24 |
* @return int $formID |
| 25 |
* |
| 26 |
*/ |
| 27 |
public function make() |
| 28 |
{ |
| 29 |
$formID = wp_insert_post( |
| 30 |
[ |
| 31 |
'post_title' => 'Donation Form', |
| 32 |
'post_type' => 'give_forms', |
| 33 |
'post_status' => 'publish', // @TODO: Preview needs to work with Draft status. |
| 34 |
'meta_input' => [ |
| 35 |
'_give_onboarding_default_form' => 1, |
| 36 |
'_give_levels_minimum_amount' => 10, |
| 37 |
'_give_levels_maximim_amount' => 250, |
| 38 |
'_give_form_template' => 'sequoia', |
| 39 |
'_give_form_status' => 'open', |
| 40 |
'_give_sequoia_form_template_settings' => $this->getTemplateConfig(), |
| 41 |
'_give_checkout_label' => __('Donate Now', 'give'), |
| 42 |
'_give_display_style' => 'buttons', |
| 43 |
'_give_payment_display' => 'button', |
| 44 |
'_give_form_floating_labels' => 'disabled', |
| 45 |
'_give_reveal_label' => __('Donate Now', 'give'), |
| 46 |
'_give_display_content' => 'disabled', |
| 47 |
'_give_content_placement' => '', |
| 48 |
'_give_form_content' => '', |
| 49 |
'_give_price_option' => 'multi', |
| 50 |
'_give_set_price' => 1, |
| 51 |
'_give_custom_amount' => 'enabled', |
| 52 |
'_give_donation_levels' => $this->getDonationLevels(), |
| 53 |
'_give_default_gateway' => 'global', |
| 54 |
'_give_name_title_prefix' => 'global', |
| 55 |
'_give_title_prefixes' => '', |
| 56 |
'_give_company_field' => 'global', |
| 57 |
'_give_anonymous_donation' => 'global', |
| 58 |
'_give_donor_comment' => 'global', |
| 59 |
'_give_logged_in_only' => 'enabled', |
| 60 |
'_give_show_register_form' => 'none', |
| 61 |
'_give_goal_option' => 'disabled', |
| 62 |
'_give_goal_format' => 'amount', |
| 63 |
'_give_set_goal' => 10000, |
| 64 |
'_give_number_of_donor_goal' => 100, |
| 65 |
'_give_goal_color' => $this->primaryColor, |
| 66 |
'_give_close_form_when_goal_achieved' => 'disabled', |
| 67 |
'_give_form_goal_achieved_message' => __( |
| 68 |
'Thank you to all our donors, we have met our fundraising goal.', |
| 69 |
'give' |
| 70 |
), |
| 71 |
'_give_terms_option' => 'global', |
| 72 |
'_give_agree_label' => __('Agree to terms?', 'give'), |
| 73 |
'_give_agree_text' => __('The terms can be customized in the donation form settings.', 'give'), |
| 74 |
'give_stripe_per_form_accounts' => 'disabled', // Note: Doesn't use underscore prefix. |
| 75 |
'_give_default_stripe_account' => '', |
| 76 |
'_give_email_options' => 'global', |
| 77 |
'_give_email_template' => 'default', |
| 78 |
'_give_email_logo' => '', |
| 79 |
'_give_from_name' => get_bloginfo('name'), |
| 80 |
'_give_from_email' => get_bloginfo('admin_email'), |
| 81 |
'_give_new-donation_notification' => 'global', |
| 82 |
'_give_new-donation_email_subject' => sprintf('%s - #{payment_id}', __('New Donation', 'give')), |
| 83 |
'_give_new-donation_email_header' => __('New Donation!', 'give'), |
| 84 |
'_give_new-donation_email_message' => give_get_default_donation_notification_email(), |
| 85 |
'_give_new-donation_email_content_type' => 'text/html', |
| 86 |
'_give_new-donation_recipient' => [ |
| 87 |
'email' => get_bloginfo('admin_email'), |
| 88 |
], |
| 89 |
'_give_donation-receipt_notification' => 'global', |
| 90 |
'_give_donation-receipt_email_subject' => __('Donation Receipt', 'give'), |
| 91 |
'_give_donation-receipt_email_header' => __('Donation Receipt', 'give'), |
| 92 |
'_give_donation-receipt_email_mesage' => give_get_default_donation_receipt_email(), |
| 93 |
'_give_donation-receipt_email_content_type' => 'text/html', |
| 94 |
'_give_form_goal_progress' => -1, |
| 95 |
'_give_offline_checkout_notes' => '<em>You can customize instructions in the forms settings.</em>' |
| 96 |
. '<br /><br />' |
| 97 |
. '<strong>Please make checks payable to "{sitename}".</strong>' |
| 98 |
. '<br /><br />' |
| 99 |
. 'Your donation is greatly appreciated!', |
| 100 |
], |
| 101 |
] |
| 102 |
); |
| 103 |
|
| 104 |
return $formID; |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Default values extracted from src/Views/Form/Templates/Sequoia/optionConfig.php |
| 109 |
* |
| 110 |
* Updates the default primary_color to match the Onboarding Wizard. |
| 111 |
* |
| 112 |
* @since 2.16.2 add new visual appearance settings |
| 113 |
* @since 2.8.0 |
| 114 |
* @return array |
| 115 |
* |
| 116 |
*/ |
| 117 |
public function getTemplateConfig() |
| 118 |
{ |
| 119 |
return [ |
| 120 |
'introduction' => [ |
| 121 |
'enabled' => 'enabled', |
| 122 |
'headline' => __('Support Our Cause', 'give'), |
| 123 |
'description' => __( |
| 124 |
'Help our organization by donating today! All donations go directly to making a difference for our cause.', |
| 125 |
'give' |
| 126 |
), |
| 127 |
'image' => GIVE_PLUGIN_URL . 'build/assets/dist/images/onboarding-preview-form-image.min.jpg', |
| 128 |
'primary_color' => $this->primaryColor, |
| 129 |
'donate_label' => __('Donate Now', 'give'), |
| 130 |
], |
| 131 |
'payment_amount' => [ |
| 132 |
'header_label' => __('Choose Amount', 'give'), |
| 133 |
'content' => sprintf( |
| 134 |
__( |
| 135 |
'How much would you like to donate? As a contributor to %s we make sure your donation goes directly to supporting our cause.', |
| 136 |
'give' |
| 137 |
), |
| 138 |
get_bloginfo('sitename') |
| 139 |
), |
| 140 |
'next_label' => __('Continue', 'give'), |
| 141 |
], |
| 142 |
'visual_appearance' => [ |
| 143 |
'decimals_enabled' => 'disabled', |
| 144 |
'primary_color' => '#28C77B', |
| 145 |
'google-fonts' => 'enabled', |
| 146 |
], |
| 147 |
'payment_information' => [ |
| 148 |
'header_label' => __('Add Your Information', 'give'), |
| 149 |
'headline' => __("Who's giving today?", 'give'), |
| 150 |
'description' => __('We’ll never share this information with anyone.', 'give'), |
| 151 |
'donation_summary_enabled' => 'enabled', |
| 152 |
'donation_summary_heading' => __('Here\'s what you\'re about to donate:', 'give'), |
| 153 |
'donation_summary_location' => 'give_donation_form_before_submit', |
| 154 |
TemplateOptions::getCheckoutLabelField(), |
| 155 |
], |
| 156 |
'thank-you' => [ |
| 157 |
'image' => '', |
| 158 |
'headline' => __('A great big thank you!', 'give'), |
| 159 |
'description' => __( |
| 160 |
'{name}, your contribution means a lot and will be put to good use in making a difference. We’ve sent your donation receipt to {donor_email}. ', |
| 161 |
'give' |
| 162 |
), |
| 163 |
'sharing' => 'enabled', |
| 164 |
'sharing_instruction' => __( |
| 165 |
'Help spread the word by sharing your support with your friends and followers!', |
| 166 |
'give' |
| 167 |
), |
| 168 |
'twitter_message' => __("I just gave to this cause. Who's next?", 'give'), |
| 169 |
], |
| 170 |
]; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Default values forked from includes/admin/forms/class-metabox-form-data.php |
| 175 |
* |
| 176 |
* @since 2.8.0 |
| 177 |
* @since 2.13.3 Donation level id and amount value changed to string |
| 178 |
* @return array |
| 179 |
* |
| 180 |
*/ |
| 181 |
public function getDonationLevels() |
| 182 |
{ |
| 183 |
return [ |
| 184 |
[ |
| 185 |
'_give_id' => |
| 186 |
[ |
| 187 |
'level_id' => '0', |
| 188 |
], |
| 189 |
'_give_amount' => give_sanitize_amount_for_db(10), |
| 190 |
], |
| 191 |
[ |
| 192 |
'_give_id' => |
| 193 |
[ |
| 194 |
'level_id' => '1', |
| 195 |
], |
| 196 |
'_give_amount' => give_sanitize_amount_for_db(25), |
| 197 |
], |
| 198 |
[ |
| 199 |
'_give_id' => |
| 200 |
[ |
| 201 |
'level_id' => '2', |
| 202 |
], |
| 203 |
'_give_amount' => give_sanitize_amount_for_db(50), |
| 204 |
], |
| 205 |
[ |
| 206 |
'_give_id' => |
| 207 |
[ |
| 208 |
'level_id' => '3', |
| 209 |
], |
| 210 |
'_give_amount' => give_sanitize_amount_for_db(100), |
| 211 |
'_give_default' => 'default', |
| 212 |
], |
| 213 |
[ |
| 214 |
'_give_id' => |
| 215 |
[ |
| 216 |
'level_id' => '5', |
| 217 |
], |
| 218 |
'_give_amount' => give_sanitize_amount_for_db(250), |
| 219 |
], |
| 220 |
]; |
| 221 |
} |
| 222 |
} |
| 223 |
|