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