← All changes
|
includes/admin/forms/class-metabox-form-data.php
+724
-539
2.3.0
→
4.18.0
View file →
| @@ -5,13 +5,19 @@ | ||
| 5 | 5 | * Displays the form data box, tabbed, with several panels. |
| 6 | 6 | * |
| 7 | 7 | * @package Give |
| 8 | 8 | * @subpackage Classes/Give_MetaBox_Form_Data |
| 9 | - * @copyright Copyright (c) 2016, WordImpress | |
| 9 | + * @copyright Copyright (c) 2016, GiveWP | |
| 10 | 10 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 11 | 11 | * @since 1.8 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | +use Give\Form\Template; | |
| 15 | +use Give\FormAPI\Fields; | |
| 16 | +use Give\FormAPI\Section; | |
| 17 | +use Give\Helpers\Form\Template as FormTemplateUtils; | |
| 18 | +use Give\Views\Admin\UpsellNotice; | |
| 19 | + | |
| 14 | 20 | /** |
| 15 | 21 | * Give_Meta_Box_Form_Data Class. |
| 16 | 22 | */ |
| 17 | 23 | class Give_MetaBox_Form_Data { |
| @@ -21,9 +27,9 @@ | ||
| 21 | 27 | * |
| 22 | 28 | * @since 1.8 |
| 23 | 29 | * @var array |
| 24 | 30 | */ |
| 25 | - private $settings = array(); | |
| 31 | + private $settings = []; | |
| 26 | 32 | |
| 27 | 33 | /** |
| 28 | 34 | * Metabox ID. |
| 29 | 35 | * |
| @@ -48,23 +54,25 @@ | ||
| 48 | 54 | $this->metabox_id = 'give-metabox-form-data'; |
| 49 | 55 | $this->metabox_label = __( 'Donation Form Options', 'give' ); |
| 50 | 56 | |
| 51 | 57 | // Setup. |
| 52 | - add_action( 'admin_init', array( $this, 'setup' ) ); | |
| 58 | + add_action( 'admin_init', [ $this, 'setup' ] ); | |
| 53 | 59 | |
| 54 | 60 | // Add metabox. |
| 55 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10 ); | |
| 61 | + add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ], 10 ); | |
| 56 | 62 | |
| 57 | 63 | // Save form meta. |
| 58 | - add_action( 'save_post_give_forms', array( $this, 'save' ), 10, 2 ); | |
| 64 | + add_action( 'save_post_give_forms', [ $this, 'save' ], 10, 2 ); | |
| 59 | 65 | |
| 66 | + add_action( 'give_save__give_form_template', [ $this, 'save_form_template_settings' ], 10, 3 ); | |
| 67 | + | |
| 60 | 68 | // cmb2 old setting loaders. |
| 61 | 69 | // add_filter( 'give_metabox_form_data_settings', array( $this, 'cmb2_metabox_settings' ) ); |
| 62 | 70 | // Add offline donations options. |
| 63 | - add_filter( 'give_metabox_form_data_settings', array( $this, 'add_offline_donations_setting_tab' ), 0, 1 ); | |
| 71 | + add_filter( 'give_metabox_form_data_settings', [ $this, 'add_offline_donations_setting_tab' ], 0, 1 ); | |
| 64 | 72 | |
| 65 | 73 | // Maintain active tab query parameter after save. |
| 66 | - add_filter( 'redirect_post_location', array( $this, 'maintain_active_tab' ), 10, 2 ); | |
| 74 | + add_filter( 'redirect_post_location', [ $this, 'maintain_active_tab' ], 10, 2 ); | |
| 67 | 75 | } |
| 68 | 76 | |
| 69 | 77 | /** |
| 70 | 78 | * Setup metabox related data. |
| @@ -78,14 +86,14 @@ | ||
| 78 | 86 | } |
| 79 | 87 | |
| 80 | 88 | |
| 81 | 89 | /** |
| 82 | - * Get metabox settings | |
| 83 | - * | |
| 84 | - * @since 1.8 | |
| 85 | - * | |
| 86 | - * @return array | |
| 87 | - */ | |
| 90 | + * Get metabox settings | |
| 91 | + * | |
| 92 | + * @since 1.8 | |
| 93 | + * | |
| 94 | + * @return array | |
| 95 | + */ | |
| 88 | 96 | function get_settings() { |
| 89 | 97 | $post_id = give_get_admin_post_id(); |
| 90 | 98 | $price_placeholder = give_format_decimal( '1.00', false, false ); |
| 91 | 99 | |
| @@ -91,519 +99,571 @@ | ||
| 91 | 99 | |
| 92 | 100 | // Start with an underscore to hide fields from custom fields list |
| 93 | 101 | $prefix = '_give_'; |
| 94 | 102 | |
| 95 | - $settings = array( | |
| 103 | + $settings = [ | |
| 96 | 104 | /** |
| 105 | + * Theme Options | |
| 106 | + */ | |
| 107 | + 'form_template_options' => apply_filters( | |
| 108 | + 'give_form_template_options', | |
| 109 | + [ | |
| 110 | + 'id' => 'form_template_options', | |
| 111 | + 'title' => __( 'Form Template', 'give' ), | |
| 112 | + 'icon-html' => '<i class="fas fa-palette"></i>', | |
| 113 | + 'fields' => [ | |
| 114 | + [ | |
| 115 | + 'id' => $prefix . 'form_template', | |
| 116 | + 'name' => 'form_template', | |
| 117 | + 'type' => 'hidden', | |
| 118 | + 'default' => '', | |
| 119 | + ], | |
| 120 | + ], | |
| 121 | + ] | |
| 122 | + ), | |
| 123 | + | |
| 124 | + /** | |
| 97 | 125 | * Repeatable Field Groups |
| 98 | 126 | */ |
| 99 | - 'form_field_options' => apply_filters( 'give_forms_field_options', array( | |
| 100 | - 'id' => 'form_field_options', | |
| 101 | - 'title' => __( 'Donation Options', 'give' ), | |
| 102 | - 'icon-html' => '<span class="give-icon give-icon-heart"></span>', | |
| 103 | - 'fields' => apply_filters( 'give_forms_donation_form_metabox_fields', array( | |
| 104 | - // Donation Option. | |
| 105 | - array( | |
| 106 | - 'name' => __( 'Donation Option', 'give' ), | |
| 107 | - 'description' => __( 'Do you want this form to have one set donation price or multiple levels (for example, $10, $20, $50)?', 'give' ), | |
| 108 | - 'id' => $prefix . 'price_option', | |
| 109 | - 'type' => 'radio_inline', | |
| 110 | - 'default' => 'multi', | |
| 111 | - 'options' => apply_filters( 'give_forms_price_options', array( | |
| 112 | - 'multi' => __( 'Multi-level Donation', 'give' ), | |
| 113 | - 'set' => __( 'Set Donation', 'give' ), | |
| 114 | - ) ), | |
| 115 | - ), | |
| 116 | - array( | |
| 117 | - 'name' => __( 'Set Donation', 'give' ), | |
| 118 | - 'description' => __( 'This is the set donation amount for this form. If you have a "Custom Amount Minimum" set, make sure it is less than this amount.', 'give' ), | |
| 119 | - 'id' => $prefix . 'set_price', | |
| 120 | - 'type' => 'text_small', | |
| 121 | - 'data_type' => 'price', | |
| 122 | - 'attributes' => array( | |
| 123 | - 'placeholder' => $price_placeholder, | |
| 124 | - 'class' => 'give-money-field', | |
| 125 | - ), | |
| 126 | - ), | |
| 127 | - // Display Style. | |
| 128 | - array( | |
| 129 | - 'name' => __( 'Display Style', 'give' ), | |
| 130 | - 'description' => __( 'Set how the donations levels will display on the form.', 'give' ), | |
| 131 | - 'id' => $prefix . 'display_style', | |
| 132 | - 'type' => 'radio_inline', | |
| 133 | - 'default' => 'buttons', | |
| 134 | - 'options' => array( | |
| 135 | - 'buttons' => __( 'Buttons', 'give' ), | |
| 136 | - 'radios' => __( 'Radios', 'give' ), | |
| 137 | - 'dropdown' => __( 'Dropdown', 'give' ), | |
| 138 | - ), | |
| 139 | - 'wrapper_class' => 'give-hidden', | |
| 140 | - ), | |
| 141 | - // Custom Amount. | |
| 142 | - array( | |
| 143 | - 'name' => __( 'Custom Amount', 'give' ), | |
| 144 | - 'description' => __( 'Do you want the user to be able to input their own donation amount?', 'give' ), | |
| 145 | - 'id' => $prefix . 'custom_amount', | |
| 146 | - 'type' => 'radio_inline', | |
| 147 | - 'default' => 'disabled', | |
| 148 | - 'options' => array( | |
| 149 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 150 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 151 | - ), | |
| 152 | - ), | |
| 153 | - array( | |
| 154 | - 'name' => __( 'Donation Limit', 'give' ), | |
| 155 | - 'description' => __( 'Set the minimum and maximum amount for all gateways.', 'give' ), | |
| 156 | - 'id' => $prefix . 'custom_amount_range', | |
| 157 | - 'type' => 'donation_limit', | |
| 158 | - 'wrapper_class' => 'give-hidden', | |
| 159 | - 'data_type' => 'price', | |
| 160 | - 'attributes' => array( | |
| 161 | - 'placeholder' => $price_placeholder, | |
| 162 | - 'class' => 'give-money-field', | |
| 163 | - ), | |
| 164 | - 'options' => array( | |
| 165 | - 'display_label' => __( 'Donation Limits: ', 'give' ), | |
| 166 | - 'minimum' => give_format_decimal( '1.00', false, false ), | |
| 167 | - 'maximum' => give_format_decimal( '999999.99', false, false ), | |
| 168 | - ), | |
| 169 | - ), | |
| 170 | - array( | |
| 171 | - 'name' => __( 'Custom Amount Text', 'give' ), | |
| 172 | - 'description' => __( 'This text appears as a label below the custom amount field for set donation forms. For multi-level forms the text will appear as it\'s own level (ie button, radio, or select option).', 'give' ), | |
| 173 | - 'id' => $prefix . 'custom_amount_text', | |
| 174 | - 'type' => 'text_medium', | |
| 175 | - 'attributes' => array( | |
| 176 | - 'rows' => 3, | |
| 177 | - 'placeholder' => __( 'Give a Custom Amount', 'give' ), | |
| 178 | - ), | |
| 179 | - 'wrapper_class' => 'give-hidden', | |
| 180 | - ), | |
| 181 | - // Donation Levels. | |
| 182 | - array( | |
| 183 | - 'id' => $prefix . 'donation_levels', | |
| 184 | - 'type' => 'group', | |
| 185 | - 'options' => array( | |
| 186 | - 'add_button' => __( 'Add Level', 'give' ), | |
| 187 | - 'header_title' => __( 'Donation Level', 'give' ), | |
| 188 | - 'remove_button' => '<span class="dashicons dashicons-no"></span>', | |
| 189 | - ), | |
| 190 | - 'wrapper_class' => 'give-hidden', | |
| 191 | - // Fields array works the same, except id's only need to be unique for this group. | |
| 192 | - // Prefix is not needed. | |
| 193 | - 'fields' => apply_filters( 'give_donation_levels_table_row', array( | |
| 194 | - array( | |
| 195 | - 'name' => __( 'ID', 'give' ), | |
| 196 | - 'id' => $prefix . 'id', | |
| 197 | - 'type' => 'levels_id', | |
| 198 | - ), | |
| 199 | - array( | |
| 200 | - 'name' => __( 'Amount', 'give' ), | |
| 201 | - 'id' => $prefix . 'amount', | |
| 202 | - 'type' => 'text_small', | |
| 203 | - 'data_type' => 'price', | |
| 204 | - 'attributes' => array( | |
| 205 | - 'placeholder' => $price_placeholder, | |
| 206 | - 'class' => 'give-money-field', | |
| 207 | - ), | |
| 208 | - ), | |
| 209 | - array( | |
| 210 | - 'name' => __( 'Text', 'give' ), | |
| 211 | - 'id' => $prefix . 'text', | |
| 212 | - 'type' => 'text', | |
| 213 | - 'attributes' => array( | |
| 214 | - 'placeholder' => __( 'Donation Level', 'give' ), | |
| 215 | - 'class' => 'give-multilevel-text-field', | |
| 216 | - ), | |
| 217 | - ), | |
| 218 | - array( | |
| 219 | - 'name' => __( 'Default', 'give' ), | |
| 220 | - 'id' => $prefix . 'default', | |
| 221 | - 'type' => 'give_default_radio_inline', | |
| 222 | - ), | |
| 223 | - ) ), | |
| 224 | - ), | |
| 225 | - array( | |
| 226 | - 'name' => 'donation_options_docs', | |
| 227 | - 'type' => 'docs_link', | |
| 228 | - 'url' => 'http://docs.givewp.com/form-donation-options', | |
| 229 | - 'title' => __( 'Donation Options', 'give' ), | |
| 230 | - ), | |
| 231 | - ), | |
| 232 | - $post_id | |
| 233 | - ), | |
| 234 | - ) ), | |
| 127 | + 'form_field_options' => apply_filters( | |
| 128 | + 'give_forms_field_options', | |
| 129 | + [ | |
| 130 | + 'id' => 'form_field_options', | |
| 131 | + 'title' => __('Donation Options', 'give'), | |
| 132 | + 'icon-html' => '<i class="fas fa-heart"></i>', | |
| 133 | + 'fields' => apply_filters( | |
| 134 | + 'give_forms_donation_form_metabox_fields', | |
| 135 | + [ | |
| 136 | + // Donation Option. | |
| 137 | + [ | |
| 138 | + 'name' => __('Donation Option', 'give'), | |
| 139 | + 'description' => __( | |
| 140 | + 'Do you want this form to have one set donation price or multiple levels (for example, $10, $20, $50)?', | |
| 141 | + 'give' | |
| 142 | + ), | |
| 143 | + 'id' => $prefix . 'price_option', | |
| 144 | + 'type' => 'radio_inline', | |
| 145 | + 'default' => 'multi', | |
| 146 | + 'options' => apply_filters( | |
| 147 | + 'give_forms_price_options', | |
| 148 | + [ | |
| 149 | + 'multi' => __('Multi-level Donation', 'give'), | |
| 150 | + 'set' => __('Set Donation', 'give'), | |
| 151 | + ] | |
| 152 | + ), | |
| 153 | + ], | |
| 154 | + [ | |
| 155 | + 'name' => __('Set Donation', 'give'), | |
| 156 | + 'description' => __( | |
| 157 | + 'This is the set donation amount for this form. If you have a "Custom Amount Minimum" set, make sure it is less than this amount.', | |
| 158 | + 'give' | |
| 159 | + ), | |
| 160 | + 'id' => $prefix . 'set_price', | |
| 161 | + 'default' => give_format_decimal(['amount' => '25.00']), | |
| 162 | + 'type' => 'text_small', | |
| 163 | + 'data_type' => 'price', | |
| 164 | + 'attributes' => [ | |
| 165 | + 'placeholder' => $price_placeholder, | |
| 166 | + 'class' => 'give-money-field', | |
| 167 | + ], | |
| 168 | + 'wrapper_class' => 'give-hidden', | |
| 169 | + ], | |
| 170 | + // Custom Amount. | |
| 171 | + [ | |
| 172 | + 'name' => __('Custom Amount', 'give'), | |
| 173 | + 'description' => __( | |
| 174 | + 'Do you want the user to be able to input their own donation amount?', | |
| 175 | + 'give' | |
| 176 | + ), | |
| 177 | + 'id' => $prefix . 'custom_amount', | |
| 178 | + 'type' => 'radio_inline', | |
| 179 | + 'default' => 'enabled', | |
| 180 | + 'options' => [ | |
| 181 | + 'enabled' => __('Enabled', 'give'), | |
| 182 | + 'disabled' => __('Disabled', 'give'), | |
| 183 | + ], | |
| 184 | + ], | |
| 185 | + [ | |
| 186 | + 'name' => __('Donation Limit', 'give'), | |
| 187 | + 'description' => __('Set the minimum and maximum amount for all gateways.', 'give'), | |
| 188 | + 'id' => $prefix . 'custom_amount_range', | |
| 189 | + 'type' => 'donation_limit', | |
| 190 | + 'wrapper_class' => 'give-hidden', | |
| 191 | + 'data_type' => 'price', | |
| 192 | + 'attributes' => [ | |
| 193 | + 'placeholder' => $price_placeholder, | |
| 194 | + 'class' => 'give-money-field', | |
| 195 | + ], | |
| 196 | + 'options' => [ | |
| 197 | + 'display_label' => __('Donation Limits: ', 'give'), | |
| 198 | + 'minimum' => give_format_decimal(['amount' => '5.00']), | |
| 199 | + 'maximum' => give_format_decimal(['amount' => '999999.99']), | |
| 200 | + ], | |
| 201 | + ], | |
| 202 | + [ | |
| 203 | + 'name' => __('Custom Amount Text', 'give'), | |
| 204 | + 'description' => __( | |
| 205 | + 'This text appears as a label below the custom amount field for set donation forms. For multi-level forms the text will appear as its own level (button, radio, or select option).', | |
| 206 | + 'give' | |
| 207 | + ), | |
| 208 | + 'id' => $prefix . 'custom_amount_text', | |
| 209 | + 'type' => 'text_medium', | |
| 210 | + 'default' => __('Custom Amount', 'give'), | |
| 211 | + 'attributes' => [ | |
| 212 | + 'rows' => 3, | |
| 213 | + ], | |
| 214 | + 'wrapper_class' => 'give-hidden', | |
| 215 | + ], | |
| 216 | + // Donation Levels. | |
| 217 | + [ | |
| 218 | + 'id' => $prefix . 'donation_levels', | |
| 219 | + 'type' => 'group', | |
| 220 | + 'options' => [ | |
| 221 | + 'add_button' => __('Add Level', 'give'), | |
| 222 | + 'header_title' => __('Donation Level', 'give'), | |
| 223 | + 'remove_button' => '<span class="dashicons dashicons-no"></span>', | |
| 224 | + ], | |
| 225 | + 'default' => [ | |
| 226 | + [ | |
| 227 | + '_give_id' => | |
| 228 | + [ | |
| 229 | + 'level_id' => 0, | |
| 230 | + ], | |
| 231 | + '_give_amount' => '10.000000', | |
| 232 | + ], | |
| 233 | + [ | |
| 234 | + '_give_id' => | |
| 235 | + [ | |
| 236 | + 'level_id' => 1, | |
| 237 | + ], | |
| 238 | + '_give_amount' => '25.000000', | |
| 239 | + ], | |
| 240 | + [ | |
| 241 | + '_give_id' => | |
| 242 | + [ | |
| 243 | + 'level_id' => 2, | |
| 244 | + ], | |
| 245 | + '_give_amount' => '50.000000', | |
| 246 | + ], | |
| 247 | + [ | |
| 248 | + '_give_id' => | |
| 249 | + [ | |
| 250 | + 'level_id' => 3, | |
| 251 | + ], | |
| 252 | + '_give_amount' => '100.000000', | |
| 253 | + '_give_default' => 'default', | |
| 254 | + ], | |
| 255 | + [ | |
| 256 | + '_give_id' => | |
| 257 | + [ | |
| 258 | + 'level_id' => 5, | |
| 259 | + ], | |
| 260 | + '_give_amount' => '250.000000', | |
| 261 | + ], | |
| 262 | + ], | |
| 263 | + 'wrapper_class' => 'give-hidden', | |
| 264 | + // Fields array works the same, except id's only need to be unique for this group. | |
| 265 | + // Prefix is not needed. | |
| 266 | + 'fields' => apply_filters( | |
| 267 | + 'give_donation_levels_table_row', | |
| 268 | + [ | |
| 269 | + [ | |
| 270 | + 'name' => __('ID', 'give'), | |
| 271 | + 'id' => $prefix . 'id', | |
| 272 | + 'type' => 'levels_id', | |
| 273 | + ], | |
| 274 | + [ | |
| 275 | + 'name' => __('Amount', 'give'), | |
| 276 | + 'id' => $prefix . 'amount', | |
| 277 | + 'type' => 'text_small', | |
| 278 | + 'data_type' => 'price', | |
| 279 | + 'attributes' => [ | |
| 280 | + 'placeholder' => $price_placeholder, | |
| 281 | + 'class' => 'give-money-field', | |
| 282 | + ], | |
| 283 | + ], | |
| 284 | + [ | |
| 285 | + 'name' => __('Text', 'give'), | |
| 286 | + 'id' => $prefix . 'text', | |
| 287 | + 'type' => 'text', | |
| 288 | + 'attributes' => [ | |
| 289 | + 'placeholder' => __('Donation Level', 'give'), | |
| 290 | + 'class' => 'give-multilevel-text-field', | |
| 291 | + ], | |
| 292 | + ], | |
| 293 | + [ | |
| 294 | + 'name' => __('Default', 'give'), | |
| 295 | + 'id' => $prefix . 'default', | |
| 296 | + 'type' => 'give_default_radio_inline', | |
| 297 | + ], | |
| 298 | + ] | |
| 299 | + ), | |
| 300 | + ], | |
| 301 | + [ | |
| 302 | + 'name' => 'donation_options_docs', | |
| 303 | + 'type' => 'docs_link', | |
| 304 | + 'url' => 'http://docs.givewp.com/form-donation-options', | |
| 305 | + 'title' => __('Donation Options', 'give'), | |
| 306 | + ], | |
| 307 | + ], | |
| 308 | + $post_id | |
| 309 | + ), | |
| 310 | + ] | |
| 311 | + ), | |
| 235 | 312 | |
| 236 | 313 | /** |
| 237 | 314 | * Display Options |
| 238 | 315 | */ |
| 239 | - 'form_display_options' => apply_filters( 'give_form_display_options', array( | |
| 316 | + 'form_display_options' => apply_filters( | |
| 317 | + 'give_form_display_options', | |
| 318 | + [ | |
| 240 | 319 | 'id' => 'form_display_options', |
| 241 | - 'title' => __( 'Form Display', 'give' ), | |
| 242 | - 'icon-html' => '<span class="give-icon give-icon-display"></span>', | |
| 243 | - 'fields' => apply_filters( 'give_forms_display_options_metabox_fields', array( | |
| 244 | - array( | |
| 245 | - 'name' => __( 'Display Options', 'give' ), | |
| 246 | - 'desc' => sprintf( __( 'How would you like to display donation information for this form?', 'give' ), '#' ), | |
| 247 | - 'id' => $prefix . 'payment_display', | |
| 248 | - 'type' => 'radio_inline', | |
| 249 | - 'options' => array( | |
| 250 | - 'onpage' => __( 'All Fields', 'give' ), | |
| 251 | - 'modal' => __( 'Modal', 'give' ), | |
| 252 | - 'reveal' => __( 'Reveal', 'give' ), | |
| 253 | - 'button' => __( 'Button', 'give' ), | |
| 254 | - ), | |
| 255 | - 'default' => 'onpage', | |
| 256 | - ), | |
| 257 | - array( | |
| 258 | - 'id' => $prefix . 'reveal_label', | |
| 259 | - 'name' => __( 'Continue Button', 'give' ), | |
| 260 | - 'desc' => __( 'The button label for displaying the additional payment fields.', 'give' ), | |
| 261 | - 'type' => 'text_small', | |
| 262 | - 'attributes' => array( | |
| 263 | - 'placeholder' => __( 'Donate Now', 'give' ), | |
| 264 | - ), | |
| 265 | - 'wrapper_class' => 'give-hidden', | |
| 266 | - ), | |
| 267 | - array( | |
| 268 | - 'id' => $prefix . 'checkout_label', | |
| 269 | - 'name' => __( 'Submit Button', 'give' ), | |
| 270 | - 'desc' => __( 'The button label for completing a donation.', 'give' ), | |
| 271 | - 'type' => 'text_small', | |
| 272 | - 'attributes' => array( | |
| 273 | - 'placeholder' => __( 'Donate Now', 'give' ), | |
| 274 | - ), | |
| 275 | - ), | |
| 276 | - array( | |
| 277 | - 'name' => __( 'Default Gateway', 'give' ), | |
| 278 | - 'desc' => __( 'By default, the gateway for this form will inherit the global default gateway (set under Give > Settings > Payment Gateways). This option allows you to customize the default gateway for this form only.', 'give' ), | |
| 279 | - 'id' => $prefix . 'default_gateway', | |
| 280 | - 'type' => 'default_gateway', | |
| 281 | - ), | |
| 282 | - array( | |
| 283 | - 'name' => __( 'Name Title Prefix', 'give' ), | |
| 284 | - 'desc' => __( 'Do you want to add a name title prefix dropdown field before the donor\'s first name field? This will display a dropdown with options such as Mrs, Miss, Ms, Sir, and Dr for donor to choose from.', 'give' ), | |
| 285 | - 'id' => $prefix . 'name_title_prefix', | |
| 286 | - 'type' => 'radio_inline', | |
| 287 | - 'options' => array( | |
| 288 | - 'global' => __( 'Global Option', 'give' ), | |
| 289 | - 'required' => __( 'Required', 'give' ), | |
| 290 | - 'optional' => __( 'Optional', 'give' ), | |
| 291 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 292 | - ), | |
| 293 | - 'default' => 'global', | |
| 294 | - ), | |
| 295 | - array( | |
| 296 | - 'name' => __( 'Title Prefixes', 'give' ), | |
| 297 | - 'desc' => __( 'Add or remove salutations from the dropdown using the field above.', 'give' ), | |
| 298 | - 'id' => $prefix . 'title_prefixes', | |
| 299 | - 'type' => 'chosen', | |
| 300 | - 'data_type' => 'multiselect', | |
| 301 | - 'style' => 'width: 100%', | |
| 302 | - 'wrapper_class' => 'give-hidden give-title-prefixes-wrap', | |
| 303 | - 'options' => give_get_default_title_prefixes(), | |
| 304 | - ), | |
| 305 | - array( | |
| 306 | - 'name' => __( 'Company Donations', 'give' ), | |
| 307 | - 'desc' => __( 'Do you want a Company field to appear after First Name and Last Name?', 'give' ), | |
| 308 | - 'id' => $prefix . 'company_field', | |
| 309 | - 'type' => 'radio_inline', | |
| 310 | - 'default' => 'global', | |
| 311 | - 'options' => array( | |
| 312 | - 'global' => __( 'Global Option', 'give' ), | |
| 313 | - 'required' => __( 'Required', 'give' ), | |
| 314 | - 'optional' => __( 'Optional', 'give' ), | |
| 315 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 320 | + 'title' => __( 'Form Fields', 'give' ), | |
| 321 | + 'icon-html' => '<i class="fas fa-stream"></i>', | |
| 322 | + 'fields' => apply_filters( | |
| 323 | + 'give_forms_display_options_metabox_fields', | |
| 324 | + [ | |
| 325 | + [ | |
| 326 | + 'name' => __( 'Default Gateway', 'give' ), | |
| 327 | + 'desc' => __( 'By default, the gateway for this form will inherit the global default gateway (set under GiveWP > Settings > Payment Gateways). This option allows you to customize the default gateway for this form only.', 'give' ), | |
| 328 | + 'id' => $prefix . 'default_gateway', | |
| 329 | + 'type' => 'default_gateway', | |
| 330 | + ], | |
| 331 | + [ | |
| 332 | + 'name' => __( 'Name Title Prefix', 'give' ), | |
| 333 | + 'desc' => __( 'Do you want to add a name title prefix dropdown field before the donor\'s first name field? This will display a dropdown with options such as Mrs, Miss, Ms, Sir, and Dr for the donor to choose from.', 'give' ), | |
| 334 | + 'id' => $prefix . 'name_title_prefix', | |
| 335 | + 'type' => 'radio_inline', | |
| 336 | + 'options' => [ | |
| 337 | + 'global' => __( 'Global Option', 'give' ), | |
| 338 | + 'required' => __( 'Required', 'give' ), | |
| 339 | + 'optional' => __( 'Optional', 'give' ), | |
| 340 | + 'disabled' => __( 'Disabled', 'give' ), | |
| 341 | + ], | |
| 342 | + 'default' => 'global', | |
| 343 | + ], | |
| 344 | + [ | |
| 345 | + 'name' => __( 'Title Prefixes', 'give' ), | |
| 346 | + 'desc' => __( 'Add or remove salutations from the dropdown using the field above.', 'give' ), | |
| 347 | + 'id' => $prefix . 'title_prefixes', | |
| 348 | + 'type' => 'chosen', | |
| 349 | + 'data_type' => 'multiselect', | |
| 350 | + 'allow-custom-values' => true, | |
| 351 | + 'style' => 'width: 100%', | |
| 352 | + 'wrapper_class' => 'give-hidden give-title-prefixes-wrap', | |
| 353 | + 'options' => give_get_default_title_prefixes(), | |
| 354 | + ], | |
| 355 | + [ | |
| 356 | + 'name' => __( 'Company Donations', 'give' ), | |
| 357 | + 'desc' => __( 'Do you want a Company field to appear after First Name and Last Name?', 'give' ), | |
| 358 | + 'id' => $prefix . 'company_field', | |
| 359 | + 'type' => 'radio_inline', | |
| 360 | + 'default' => 'global', | |
| 361 | + 'options' => [ | |
| 362 | + 'global' => __( 'Global Option', 'give' ), | |
| 363 | + 'required' => __( 'Required', 'give' ), | |
| 364 | + 'optional' => __( 'Optional', 'give' ), | |
| 365 | + 'disabled' => __( 'Disabled', 'give' ), | |
| 316 | 366 | |
| 317 | - ), | |
| 318 | - ), | |
| 319 | - array( | |
| 320 | - 'name' => __( 'Anonymous Donations', 'give' ), | |
| 321 | - 'desc' => __( 'Do you want to provide donors the ability mark themselves anonymous while giving. This will prevent their information from appearing publicly on your website but you will still receive their information for your records in the admin panel.', 'give' ), | |
| 322 | - 'id' => "{$prefix}anonymous_donation", | |
| 323 | - 'type' => 'radio_inline', | |
| 324 | - 'default' => 'global', | |
| 325 | - 'options' => array( | |
| 326 | - 'global' => __( 'Global Option', 'give' ), | |
| 327 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 328 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 329 | - ), | |
| 330 | - ), | |
| 331 | - array( | |
| 332 | - 'name' => __( 'Donor Comments', 'give' ), | |
| 333 | - 'desc' => __( 'Do you want to provide donors the ability to add a comment to their donation? The comment will display publicly on the donor wall if they do not select to give anonymously.', 'give' ), | |
| 334 | - 'id' => "{$prefix}donor_comment", | |
| 335 | - 'type' => 'radio_inline', | |
| 336 | - 'default' => 'global', | |
| 337 | - 'options' => array( | |
| 338 | - 'global' => __( 'Global Option', 'give' ), | |
| 339 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 340 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 341 | - ), | |
| 342 | - ), | |
| 343 | - array( | |
| 344 | - 'name' => __( 'Guest Donations', 'give' ), | |
| 345 | - 'desc' => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ), | |
| 346 | - 'id' => $prefix . 'logged_in_only', | |
| 347 | - 'type' => 'radio_inline', | |
| 348 | - 'default' => 'enabled', | |
| 349 | - 'options' => array( | |
| 350 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 351 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 352 | - ), | |
| 353 | - ), | |
| 354 | - array( | |
| 355 | - 'name' => __( 'Registration', 'give' ), | |
| 356 | - 'desc' => __( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ), | |
| 357 | - 'id' => $prefix . 'show_register_form', | |
| 358 | - 'type' => 'radio', | |
| 359 | - 'options' => array( | |
| 360 | - 'none' => __( 'None', 'give' ), | |
| 361 | - 'registration' => __( 'Registration', 'give' ), | |
| 362 | - 'login' => __( 'Login', 'give' ), | |
| 363 | - 'both' => __( 'Registration + Login', 'give' ), | |
| 364 | - ), | |
| 365 | - 'default' => 'none', | |
| 366 | - ), | |
| 367 | - array( | |
| 368 | - 'name' => __( 'Floating Labels', 'give' ), | |
| 369 | - /* translators: %s: forms http://docs.givewp.com/form-floating-labels */ | |
| 370 | - 'desc' => sprintf( __( 'Select the <a href="%s" target="_blank">floating labels</a> setting for this Give form. Be aware that if you have the "Disable CSS" option enabled, you will need to style the floating labels yourself.', 'give' ), esc_url( 'http://docs.givewp.com/form-floating-labels' ) ), | |
| 371 | - 'id' => $prefix . 'form_floating_labels', | |
| 372 | - 'type' => 'radio_inline', | |
| 373 | - 'options' => array( | |
| 374 | - 'global' => __( 'Global Option', 'give' ), | |
| 375 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 376 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 377 | - ), | |
| 378 | - 'default' => 'global', | |
| 379 | - ), | |
| 380 | - array( | |
| 381 | - 'name' => 'form_display_docs', | |
| 382 | - 'type' => 'docs_link', | |
| 383 | - 'url' => 'http://docs.givewp.com/form-display-options', | |
| 384 | - 'title' => __( 'Form Display', 'give' ), | |
| 385 | - ), | |
| 386 | - ), | |
| 367 | + ], | |
| 368 | + ], | |
| 369 | + [ | |
| 370 | + 'name' => __( 'Last Name Field Required', 'give' ), | |
| 371 | + 'desc' => __( 'Do you want to force the Last Name field to be required?', 'give' ), | |
| 372 | + 'id' => $prefix . 'last_name_field_required', | |
| 373 | + 'type' => 'radio_inline', | |
| 374 | + 'default' => 'global', | |
| 375 | + 'options' => [ | |
| 376 | + 'global' => __( 'Global Option', 'give' ), | |
| 377 | + 'required' => __( 'Required', 'give' ), | |
| 378 | + 'optional' => __( 'Optional', 'give' ), | |
| 379 | + ], | |
| 380 | + ], | |
| 381 | + [ | |
| 382 | + 'name' => __( 'Anonymous Donations', 'give' ), | |
| 383 | + 'desc' => __( 'Do you want to provide donors the ability mark themselves anonymous while giving? This will prevent their information from appearing publicly on your website but you will still receive their information for your records in the admin panel.', 'give' ), | |
| 384 | + 'id' => "{$prefix}anonymous_donation", | |
| 385 | + 'type' => 'radio_inline', | |
| 386 | + 'default' => 'global', | |
| 387 | + 'options' => [ | |
| 388 | + 'global' => __( 'Global Option', 'give' ), | |
| 389 | + 'enabled' => __( 'Enabled', 'give' ), | |
| 390 | + 'disabled' => __( 'Disabled', 'give' ), | |
| 391 | + ], | |
| 392 | + ], | |
| 393 | + [ | |
| 394 | + 'name' => __( 'Donor Comments', 'give' ), | |
| 395 | + 'desc' => __( 'Do you want to provide donors the ability to add a comment to their donation? The comment will display publicly on the donor wall if they do not select to give anonymously.', 'give' ), | |
| 396 | + 'id' => "{$prefix}donor_comment", | |
| 397 | + 'type' => 'radio_inline', | |
| 398 | + 'default' => 'global', | |
| 399 | + 'options' => [ | |
| 400 | + 'global' => __( 'Global Option', 'give' ), | |
| 401 | + 'enabled' => __( 'Enabled', 'give' ), | |
| 402 | + 'disabled' => __( 'Disabled', 'give' ), | |
| 403 | + ], | |
| 404 | + ], | |
| 405 | + [ | |
| 406 | + 'name' => __( 'Guest Donations', 'give' ), | |
| 407 | + 'desc' => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ), | |
| 408 | + 'id' => $prefix . 'logged_in_only', | |
| 409 | + 'type' => 'radio_inline', | |
| 410 | + 'default' => 'enabled', | |
| 411 | + 'options' => [ | |
| 412 | + 'enabled' => __( 'Enabled', 'give' ), | |
| 413 | + 'disabled' => __( 'Disabled', 'give' ), | |
| 414 | + ], | |
| 415 | + ], | |
| 416 | + [ | |
| 417 | + 'name' => __( 'Registration', 'give' ), | |
| 418 | + 'desc' => __( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ), | |
| 419 | + 'id' => $prefix . 'show_register_form', | |
| 420 | + 'type' => 'radio', | |
| 421 | + 'options' => [ | |
| 422 | + 'none' => __( 'None', 'give' ), | |
| 423 | + 'registration' => __( 'Registration', 'give' ), | |
| 424 | + 'login' => __( 'Login', 'give' ), | |
| 425 | + 'both' => __( 'Registration + Login', 'give' ), | |
| 426 | + ], | |
| 427 | + 'default' => 'none', | |
| 428 | + ], | |
| 429 | + [ | |
| 430 | + 'name' => 'form_display_docs', | |
| 431 | + 'type' => 'docs_link', | |
| 432 | + 'url' => 'http://docs.givewp.com/form-display-options', | |
| 433 | + 'title' => __( 'Form Display', 'give' ), | |
| 434 | + ], | |
| 435 | + ], | |
| 387 | 436 | $post_id |
| 388 | 437 | ), |
| 389 | - ) | |
| 438 | + ] | |
| 390 | 439 | ), |
| 391 | 440 | |
| 392 | 441 | /** |
| 393 | 442 | * Donation Goals |
| 394 | 443 | */ |
| 395 | - 'donation_goal_options' => apply_filters( 'give_donation_goal_options', array( | |
| 396 | - 'id' => 'donation_goal_options', | |
| 397 | - 'title' => __( 'Donation Goal', 'give' ), | |
| 398 | - 'icon-html' => '<span class="give-icon give-icon-target"></span>', | |
| 399 | - 'fields' => apply_filters( 'give_forms_donation_goal_metabox_fields', array( | |
| 400 | - // Goals | |
| 401 | - array( | |
| 402 | - 'name' => __( 'Donation Goal', 'give' ), | |
| 403 | - 'description' => __( 'Do you want to set a donation goal for this form?', 'give' ), | |
| 404 | - 'id' => $prefix . 'goal_option', | |
| 405 | - 'type' => 'radio_inline', | |
| 406 | - 'default' => 'disabled', | |
| 407 | - 'options' => array( | |
| 408 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 409 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 410 | - ), | |
| 411 | - ), | |
| 444 | + 'donation_goal_options' => apply_filters( | |
| 445 | + 'give_donation_goal_options', | |
| 446 | + [ | |
| 447 | + 'id' => 'donation_goal_options', | |
| 448 | + 'title' => __( 'Donation Goal', 'give' ), | |
| 449 | + 'icon-html' => '<i class="fas fa-bullseye"></i>', | |
| 450 | + 'fields' => apply_filters( | |
| 451 | + 'give_forms_donation_goal_metabox_fields', | |
| 452 | + [ | |
| 453 | + // Goals | |
| 454 | + [ | |
| 455 | + 'name' => __( 'Donation Goal', 'give' ), | |
| 456 | + 'description' => __( 'Do you want to set a donation goal for this form?', 'give' ), | |
| 457 | + 'id' => $prefix . 'goal_option', | |
| 458 | + 'type' => 'radio_inline', | |
| 459 | + 'default' => 'disabled', | |
| 460 | + 'options' => [ | |
| 461 | + 'enabled' => __( 'Enabled', 'give' ), | |
| 462 | + 'disabled' => __( 'Disabled', 'give' ), | |
| 463 | + ], | |
| 464 | + ], | |
| 412 | 465 | |
| 413 | - array( | |
| 414 | - 'name' => __( 'Goal Format', 'give' ), | |
| 415 | - 'description' => __( 'Do you want to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded" or "1 of 5 donations". You can also display a donor-based goal, such as "100 of 1,000 donors have given".', 'give' ), | |
| 416 | - 'id' => $prefix . 'goal_format', | |
| 417 | - 'type' => 'donation_form_goal', | |
| 418 | - 'default' => 'amount', | |
| 419 | - 'options' => array( | |
| 420 | - 'amount' => __( 'Amount Raised', 'give' ), | |
| 421 | - 'percentage' => __( 'Percentage Raised', 'give' ), | |
| 422 | - 'donation' => __( 'Number of Donations', 'give' ), | |
| 423 | - 'donors' => __( 'Number of Donors', 'give' ), | |
| 424 | - ), | |
| 425 | - ), | |
| 466 | + [ | |
| 467 | + 'name' => __( 'Goal Format', 'give' ), | |
| 468 | + 'description' => __( 'Do you want to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded" or "1 of 5 donations". You can also display a donor-based goal, such as "100 of 1,000 donors have given".', 'give' ), | |
| 469 | + 'id' => $prefix . 'goal_format', | |
| 470 | + 'type' => 'donation_form_goal', | |
| 471 | + 'default' => 'amount', | |
| 472 | + 'options' => [ | |
| 473 | + 'amount' => __( 'Amount Raised', 'give' ), | |
| 474 | + 'percentage' => __( 'Percentage Raised', 'give' ), | |
| 475 | + 'donation' => __( 'Number of Donations', 'give' ), | |
| 476 | + 'donors' => __( 'Number of Donors', 'give' ), | |
| 477 | + ], | |
| 478 | + ], | |
| 426 | 479 | |
| 427 | - array( | |
| 428 | - 'name' => __( 'Goal Amount', 'give' ), | |
| 429 | - 'description' => __( 'This is the monetary goal amount you want to reach for this form.', 'give' ), | |
| 430 | - 'id' => $prefix . 'set_goal', | |
| 431 | - 'type' => 'text_small', | |
| 432 | - 'data_type' => 'price', | |
| 433 | - 'attributes' => array( | |
| 434 | - 'placeholder' => $price_placeholder, | |
| 435 | - 'class' => 'give-money-field', | |
| 436 | - ), | |
| 437 | - 'wrapper_class' => 'give-hidden', | |
| 438 | - ), | |
| 439 | - array( | |
| 440 | - 'id' => $prefix . 'number_of_donation_goal', | |
| 441 | - 'name' => __( 'Donation Goal', 'give' ), | |
| 442 | - 'desc' => __( 'Set the total number of donations as a goal.', 'give' ), | |
| 443 | - 'type' => 'number', | |
| 444 | - 'default' => 1, | |
| 445 | - 'attributes' => array( | |
| 446 | - 'placeholder' => 1, | |
| 447 | - ), | |
| 448 | - ), | |
| 449 | - array( | |
| 450 | - 'id' => $prefix . 'number_of_donor_goal', | |
| 451 | - 'name' => __( 'Donor Goal', 'give' ), | |
| 452 | - 'desc' => __( 'Set the total number of donors as a goal.', 'give' ), | |
| 453 | - 'type' => 'number', | |
| 454 | - 'default' => 1, | |
| 455 | - 'attributes' => array( | |
| 456 | - 'placeholder' => 1, | |
| 457 | - ), | |
| 458 | - ), | |
| 459 | - array( | |
| 460 | - 'name' => __( 'Progress Bar Color', 'give' ), | |
| 461 | - 'desc' => __( 'Customize the color of the goal progress bar.', 'give' ), | |
| 462 | - 'id' => $prefix . 'goal_color', | |
| 463 | - 'type' => 'colorpicker', | |
| 464 | - 'default' => '#2bc253', | |
| 465 | - 'wrapper_class' => 'give-hidden', | |
| 466 | - ), | |
| 480 | + [ | |
| 481 | + 'name' => __( 'Goal Amount', 'give' ), | |
| 482 | + 'description' => __( 'This is the monetary goal amount you want to reach for this form.', 'give' ), | |
| 483 | + 'id' => $prefix . 'set_goal', | |
| 484 | + 'type' => 'text_small', | |
| 485 | + 'data_type' => 'price', | |
| 486 | + 'default' => give_format_decimal( [ 'amount' => '10000.00' ] ), | |
| 487 | + 'attributes' => [ | |
| 488 | + 'placeholder' => give_format_decimal( [ 'amount' => '10000.00' ] ), | |
| 489 | + 'class' => 'give-money-field', | |
| 490 | + ], | |
| 491 | + 'wrapper_class' => 'give-hidden', | |
| 492 | + ], | |
| 493 | + [ | |
| 494 | + 'id' => $prefix . 'number_of_donation_goal', | |
| 495 | + 'name' => __( 'Donation Goal', 'give' ), | |
| 496 | + 'desc' => __( 'Set the total number of donations as a goal.', 'give' ), | |
| 497 | + 'type' => 'number', | |
| 498 | + 'default' => 1, | |
| 499 | + 'attributes' => [ | |
| 500 | + 'placeholder' => 1, | |
| 501 | + ], | |
| 502 | + ], | |
| 503 | + [ | |
| 504 | + 'id' => $prefix . 'number_of_donor_goal', | |
| 505 | + 'name' => __( 'Donor Goal', 'give' ), | |
| 506 | + 'desc' => __( 'Set the total number of donors as a goal.', 'give' ), | |
| 507 | + 'type' => 'number', | |
| 508 | + 'default' => 1, | |
| 509 | + 'attributes' => [ | |
| 510 | + 'placeholder' => 1, | |
| 511 | + ], | |
| 512 | + ], | |
| 513 | + [ | |
| 514 | + 'name' => __( 'Progress Bar Color', 'give' ), | |
| 515 | + 'desc' => __( 'Customize the color of the goal progress bar.', 'give' ), | |
| 516 | + 'id' => $prefix . 'goal_color', | |
| 517 | + 'type' => 'colorpicker', | |
| 518 | + 'default' => '#2bc253', | |
| 519 | + 'wrapper_class' => 'give-hidden', | |
| 520 | + ], | |
| 467 | 521 | |
| 468 | - array( | |
| 469 | - 'name' => __( 'Close Form', 'give' ), | |
| 470 | - 'desc' => __( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ), | |
| 471 | - 'id' => $prefix . 'close_form_when_goal_achieved', | |
| 472 | - 'type' => 'radio_inline', | |
| 473 | - 'default' => 'disabled', | |
| 474 | - 'options' => array( | |
| 475 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 476 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 477 | - ), | |
| 478 | - 'wrapper_class' => 'give-hidden', | |
| 522 | + [ | |
| 523 | + 'name' => __( 'Close Form', 'give' ), | |
| 524 | + 'desc' => __( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ), | |
| 525 | + 'id' => $prefix . 'close_form_when_goal_achieved', | |
| 526 | + 'type' => 'radio_inline', | |
| 527 | + 'default' => 'disabled', | |
| 528 | + 'options' => [ | |
| 529 | + 'enabled' => __( 'Enabled', 'give' ), | |
| 530 | + 'disabled' => __( 'Disabled', 'give' ), | |
| 531 | + ], | |
| 532 | + 'wrapper_class' => 'give-hidden', | |
| 533 | + ], | |
| 534 | + [ | |
| 535 | + 'name' => __( 'Goal Achieved Message', 'give' ), | |
| 536 | + 'desc' => __( 'Do you want to display a custom message when the goal is closed?', 'give' ), | |
| 537 | + 'id' => $prefix . 'form_goal_achieved_message', | |
| 538 | + 'type' => 'wysiwyg', | |
| 539 | + 'default' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ), | |
| 540 | + 'wrapper_class' => 'give-hidden', | |
| 541 | + ], | |
| 542 | + [ | |
| 543 | + 'name' => 'donation_goal_docs', | |
| 544 | + 'type' => 'docs_link', | |
| 545 | + 'url' => 'http://docs.givewp.com/form-donation-goal', | |
| 546 | + 'title' => __( 'Donation Goal', 'give' ), | |
| 547 | + ], | |
| 548 | + ], | |
| 549 | + $post_id | |
| 479 | 550 | ), |
| 480 | - array( | |
| 481 | - 'name' => __( 'Goal Achieved Message', 'give' ), | |
| 482 | - 'desc' => __( 'Do you want to display a custom message when the goal is closed?', 'give' ), | |
| 483 | - 'id' => $prefix . 'form_goal_achieved_message', | |
| 484 | - 'type' => 'wysiwyg', | |
| 485 | - 'default' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ), | |
| 486 | - 'wrapper_class' => 'give-hidden', | |
| 487 | - ), | |
| 488 | - array( | |
| 489 | - 'name' => 'donation_goal_docs', | |
| 490 | - 'type' => 'docs_link', | |
| 491 | - 'url' => 'http://docs.givewp.com/form-donation-goal', | |
| 492 | - 'title' => __( 'Donation Goal', 'give' ), | |
| 493 | - ), | |
| 494 | - ), | |
| 495 | - $post_id | |
| 496 | - ), | |
| 497 | - ) ), | |
| 551 | + ] | |
| 552 | + ), | |
| 498 | 553 | |
| 499 | 554 | /** |
| 500 | - * Content Field | |
| 555 | + * Terms & Conditions | |
| 501 | 556 | */ |
| 502 | - 'form_content_options' => apply_filters( 'give_forms_content_options', array( | |
| 503 | - 'id' => 'form_content_options', | |
| 504 | - 'title' => __( 'Form Content', 'give' ), | |
| 505 | - 'icon-html' => '<span class="give-icon give-icon-edit"></span>', | |
| 506 | - 'fields' => apply_filters( 'give_forms_content_options_metabox_fields', array( | |
| 507 | - | |
| 508 | - // Donation content. | |
| 509 | - array( | |
| 510 | - 'name' => __( 'Display Content', 'give' ), | |
| 511 | - 'description' => __( 'Do you want to add custom content to this form?', 'give' ), | |
| 512 | - 'id' => $prefix . 'display_content', | |
| 513 | - 'type' => 'radio_inline', | |
| 514 | - 'options' => array( | |
| 515 | - 'enabled' => __( 'Enabled', 'give' ), | |
| 516 | - 'disabled' => __( 'Disabled', 'give' ), | |
| 517 | - ), | |
| 518 | - 'default' => 'disabled', | |
| 557 | + 'form_terms_options' => apply_filters( | |
| 558 | + 'give_forms_terms_options', | |
| 559 | + [ | |
| 560 | + 'id' => 'form_terms_options', | |
| 561 | + 'title' => __( 'Terms & Conditions', 'give' ), | |
| 562 | + 'icon-html' => '<i class="far fa-check-square"></i>', | |
| 563 | + 'fields' => apply_filters( | |
| 564 | + 'give_forms_terms_options_metabox_fields', | |
| 565 | + [ | |
| 566 | + // Donation Option | |
| 567 | + [ | |
| 568 | + 'name' => __( 'Terms and Conditions', 'give' ), | |
| 569 | + 'description' => __( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ), | |
| 570 | + 'id' => $prefix . 'terms_option', | |
| 571 | + 'type' => 'radio_inline', | |
| 572 | + 'options' => apply_filters( | |
| 573 | + 'give_forms_content_options_select', | |
| 574 | + [ | |
| 575 | + 'global' => __( 'Global Option', 'give' ), | |
| 576 | + 'enabled' => __( 'Customize', 'give' ), | |
| 577 | + 'disabled' => __( 'Disable', 'give' ), | |
| 578 | + ] | |
| 579 | + ), | |
| 580 | + 'default' => 'global', | |
| 581 | + ], | |
| 582 | + [ | |
| 583 | + 'id' => $prefix . 'agree_label', | |
| 584 | + 'name' => __( 'Agreement Label', 'give' ), | |
| 585 | + 'desc' => __( 'The label shown next to the agree to terms check box. Add your own to customize or leave blank to use the default text placeholder.', 'give' ), | |
| 586 | + 'type' => 'textarea', | |
| 587 | + 'attributes' => [ | |
| 588 | + 'placeholder' => __( 'Agree to Terms?', 'give' ), | |
| 589 | + 'rows' => 1, | |
| 590 | + ], | |
| 591 | + 'wrapper_class' => 'give-hidden', | |
| 592 | + ], | |
| 593 | + [ | |
| 594 | + 'id' => $prefix . 'agree_text', | |
| 595 | + 'name' => __( 'Agreement Text', 'give' ), | |
| 596 | + 'desc' => __( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ), | |
| 597 | + 'default' => give_get_option( 'agreement_text' ), | |
| 598 | + 'type' => 'wysiwyg', | |
| 599 | + 'wrapper_class' => 'give-hidden', | |
| 600 | + ], | |
| 601 | + [ | |
| 602 | + 'name' => 'terms_docs', | |
| 603 | + 'type' => 'docs_link', | |
| 604 | + 'url' => 'http://docs.givewp.com/form-terms', | |
| 605 | + 'title' => __( 'Terms and Conditions', 'give' ), | |
| 606 | + ], | |
| 607 | + ], | |
| 608 | + $post_id | |
| 519 | 609 | ), |
| 610 | + ] | |
| 611 | + ), | |
| 520 | 612 | |
| 521 | - // Content placement. | |
| 522 | - array( | |
| 523 | - 'name' => __( 'Content Placement', 'give' ), | |
| 524 | - 'description' => __( 'This option controls where the content appears within the donation form.', 'give' ), | |
| 525 | - 'id' => $prefix . 'content_placement', | |
| 526 | - 'type' => 'radio_inline', | |
| 527 | - 'options' => apply_filters( 'give_forms_content_options_select', array( | |
| 528 | - 'give_pre_form' => __( 'Above fields', 'give' ), | |
| 529 | - 'give_post_form' => __( 'Below fields', 'give' ), | |
| 530 | - ) | |
| 531 | - ), | |
| 532 | - 'default' => 'give_pre_form', | |
| 533 | - 'wrapper_class' => 'give-hidden', | |
| 534 | - ), | |
| 535 | - array( | |
| 536 | - 'name' => __( 'Content', 'give' ), | |
| 537 | - 'description' => __( 'This content will display on the single give form page.', 'give' ), | |
| 538 | - 'id' => $prefix . 'form_content', | |
| 539 | - 'type' => 'wysiwyg', | |
| 540 | - 'wrapper_class' => 'give-hidden', | |
| 541 | - ), | |
| 542 | - array( | |
| 543 | - 'name' => 'form_content_docs', | |
| 544 | - 'type' => 'docs_link', | |
| 545 | - 'url' => 'http://docs.givewp.com/form-content', | |
| 546 | - 'title' => __( 'Form Content', 'give' ), | |
| 547 | - ), | |
| 548 | - ), | |
| 549 | - $post_id | |
| 550 | - ), | |
| 551 | - ) ), | |
| 613 | + /** | |
| 614 | + * Form Grid | |
| 615 | + * | |
| 616 | + * @since 2.20.0 | |
| 617 | + */ | |
| 618 | + 'form_grid_options' => apply_filters( | |
| 619 | + 'give_forms_grid_options', | |
| 620 | + [ | |
| 621 | + 'id' => 'form_grid_options', | |
| 622 | + 'title' => __( 'Form Grid', 'give' ), | |
| 623 | + 'icon-html' => '<i class="fas fa-th-large"></i>', | |
| 624 | + 'fields' => [ | |
| 625 | + [ | |
| 626 | + 'name' => __( 'Form Grid', 'give' ), | |
| 627 | + 'description' => __( 'These settings are used to customize how this form looks or functions when displayed as a part of a Form Grid. The default option is for donors to be redirected to the individual form page (linked above), and to have "Donate" as the default text. To change that behavior, select to customize the options.', 'give' ), | |
| 628 | + 'id' => $prefix . 'form_grid_option', | |
| 629 | + 'type' => 'radio_inline', | |
| 630 | + 'default' => 'default', | |
| 631 | + 'options' => [ | |
| 632 | + 'default' => __( 'Default options', 'give' ), | |
| 633 | + 'custom' => __( 'Customize', 'give' ), | |
| 634 | + ], | |
| 635 | + 'attributes' => [ | |
| 636 | + 'class' => 'give-visibility-handler', | |
| 637 | + ] | |
| 638 | + ], | |
| 639 | + [ | |
| 640 | + 'name' => __( 'Redirect URL', 'give' ), | |
| 641 | + 'description' => __( 'The full URL of the page you want this form to redirect to when clicked on from the Form Grid. This only applies when the Form Grid uses the “Redirect” method. ', 'give' ), | |
| 642 | + 'id' => $prefix . 'form_grid_redirect_url', | |
| 643 | + 'type' => 'text-medium', | |
| 644 | + 'attributes' => [ | |
| 645 | + 'placeholder' => 'https://example.com/donation-form', | |
| 646 | + 'data-field-visibility' => htmlspecialchars(json_encode([ $prefix . 'form_grid_option' => 'custom' ])), | |
| 647 | + ], | |
| 648 | + 'wrapper_class' => 'give-hidden', | |
| 649 | + ], | |
| 650 | + [ | |
| 651 | + 'name' => __( 'Donate Button Text', 'give' ), | |
| 652 | + 'description' => __( 'The text on the Donate Button for this form when displayed on the Form Grid. This setting only applies if the Donate Button display option is enabled in your Form Grid.', 'give' ), | |
| 653 | + 'id' => $prefix . 'form_grid_donate_button_text', | |
| 654 | + 'type' => 'text-medium', | |
| 655 | + 'attributes' => [ | |
| 656 | + 'placeholder' => 'Donate Here', | |
| 657 | + 'data-field-visibility' => htmlspecialchars(json_encode([ $prefix . 'form_grid_option' => 'custom' ])), | |
| 658 | + ], | |
| 659 | + 'wrapper_class' => 'give-hidden', | |
| 660 | + ], | |
| 661 | + ], | |
| 662 | + ] | |
| 663 | + ), | |
| 664 | + ]; | |
| 552 | 665 | |
| 553 | - /** | |
| 554 | - * Terms & Conditions | |
| 555 | - */ | |
| 556 | - 'form_terms_options' => apply_filters( 'give_forms_terms_options', array( | |
| 557 | - 'id' => 'form_terms_options', | |
| 558 | - 'title' => __( 'Terms & Conditions', 'give' ), | |
| 559 | - 'icon-html' => '<span class="give-icon give-icon-checklist"></span>', | |
| 560 | - 'fields' => apply_filters( 'give_forms_terms_options_metabox_fields', array( | |
| 561 | - // Donation Option | |
| 562 | - array( | |
| 563 | - 'name' => __( 'Terms and Conditions', 'give' ), | |
| 564 | - 'description' => __( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ), | |
| 565 | - 'id' => $prefix . 'terms_option', | |
| 566 | - 'type' => 'radio_inline', | |
| 567 | - 'options' => apply_filters( 'give_forms_content_options_select', array( | |
| 568 | - 'global' => __( 'Global Option', 'give' ), | |
| 569 | - 'enabled' => __( 'Customize', 'give' ), | |
| 570 | - 'disabled' => __( 'Disable', 'give' ), | |
| 571 | - ) | |
| 572 | - ), | |
| 573 | - 'default' => 'global', | |
| 574 | - ), | |
| 575 | - array( | |
| 576 | - 'id' => $prefix . 'agree_label', | |
| 577 | - 'name' => __( 'Agreement Label', 'give' ), | |
| 578 | - 'desc' => __( 'The label shown next to the agree to terms check box. Add your own to customize or leave blank to use the default text placeholder.', 'give' ), | |
| 579 | - 'type' => 'textarea', | |
| 580 | - 'attributes' => array( | |
| 581 | - 'placeholder' => __( 'Agree to Terms?', 'give' ), | |
| 582 | - 'rows' => 1 | |
| 583 | - ), | |
| 584 | - 'wrapper_class' => 'give-hidden', | |
| 585 | - ), | |
| 586 | - array( | |
| 587 | - 'id' => $prefix . 'agree_text', | |
| 588 | - 'name' => __( 'Agreement Text', 'give' ), | |
| 589 | - 'desc' => __( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ), | |
| 590 | - 'default' => give_get_option( 'agreement_text' ), | |
| 591 | - 'type' => 'wysiwyg', | |
| 592 | - 'wrapper_class' => 'give-hidden', | |
| 593 | - ), | |
| 594 | - array( | |
| 595 | - 'name' => 'terms_docs', | |
| 596 | - 'type' => 'docs_link', | |
| 597 | - 'url' => 'http://docs.givewp.com/form-terms', | |
| 598 | - 'title' => __( 'Terms and Conditions', 'give' ), | |
| 599 | - ), | |
| 600 | - ), | |
| 601 | - $post_id | |
| 602 | - ), | |
| 603 | - ) ), | |
| 604 | - ); | |
| 605 | - | |
| 606 | 666 | /** |
| 607 | 667 | * Filter the metabox tabbed panel settings. |
| 608 | 668 | */ |
| 609 | 669 | $settings = apply_filters( 'give_metabox_form_data_settings', $settings, $post_id ); |
| @@ -622,10 +682,10 @@ | ||
| 622 | 682 | public function add_meta_box() { |
| 623 | 683 | add_meta_box( |
| 624 | 684 | $this->get_metabox_ID(), |
| 625 | 685 | $this->get_metabox_label(), |
| 626 | - array( $this, 'output' ), | |
| 627 | - array( 'give_forms' ), | |
| 686 | + [ $this, 'output' ], | |
| 687 | + [ 'give_forms' ], | |
| 628 | 688 | 'normal', |
| 629 | 689 | 'high' |
| 630 | 690 | ); |
| 631 | 691 | |
| @@ -633,10 +693,10 @@ | ||
| 633 | 693 | if ( give_is_setting_enabled( give_get_meta( give_get_admin_post_id(), '_give_goal_option', true ) ) ) { |
| 634 | 694 | add_meta_box( |
| 635 | 695 | 'give-form-goal-stats', |
| 636 | 696 | __( 'Goal Statistics', 'give' ), |
| 637 | - array( $this, 'output_goal' ), | |
| 638 | - array( 'give_forms' ), | |
| 697 | + [ $this, 'output_goal' ], | |
| 698 | + [ 'give_forms' ], | |
| 639 | 699 | 'side', |
| 640 | 700 | 'low' |
| 641 | 701 | ); |
| 642 | 702 | } |
| @@ -689,9 +749,9 @@ | ||
| 689 | 749 | * |
| 690 | 750 | * @return array |
| 691 | 751 | */ |
| 692 | 752 | public function get_tabs() { |
| 693 | - $tabs = array(); | |
| 753 | + $tabs = []; | |
| 694 | 754 | |
| 695 | 755 | if ( ! empty( $this->settings ) ) { |
| 696 | 756 | foreach ( $this->settings as $setting ) { |
| 697 | 757 | if ( ! isset( $setting['id'] ) || ! isset( $setting['title'] ) ) { |
| @@ -696,24 +756,24 @@ | ||
| 696 | 756 | foreach ( $this->settings as $setting ) { |
| 697 | 757 | if ( ! isset( $setting['id'] ) || ! isset( $setting['title'] ) ) { |
| 698 | 758 | continue; |
| 699 | 759 | } |
| 700 | - $tab = array( | |
| 760 | + $tab = [ | |
| 701 | 761 | 'id' => $setting['id'], |
| 702 | 762 | 'label' => $setting['title'], |
| 703 | 763 | 'icon-html' => ( ! empty( $setting['icon-html'] ) ? $setting['icon-html'] : '' ), |
| 704 | - ); | |
| 764 | + ]; | |
| 705 | 765 | |
| 706 | 766 | if ( $this->has_sub_tab( $setting ) ) { |
| 707 | 767 | if ( empty( $setting['sub-fields'] ) ) { |
| 708 | - $tab = array(); | |
| 768 | + $tab = []; | |
| 709 | 769 | } else { |
| 710 | 770 | foreach ( $setting['sub-fields'] as $sub_fields ) { |
| 711 | - $tab['sub-fields'][] = array( | |
| 771 | + $tab['sub-fields'][] = [ | |
| 712 | 772 | 'id' => $sub_fields['id'], |
| 713 | 773 | 'label' => $sub_fields['title'], |
| 714 | 774 | 'icon-html' => ( ! empty( $sub_fields['icon-html'] ) ? $sub_fields['icon-html'] : '' ), |
| 715 | - ); | |
| 775 | + ]; | |
| 716 | 776 | } |
| 717 | 777 | } |
| 718 | 778 | } |
| 719 | 779 | |
| @@ -735,10 +795,14 @@ | ||
| 735 | 795 | */ |
| 736 | 796 | public function output() { |
| 737 | 797 | // Bailout. |
| 738 | 798 | if ( $form_data_tabs = $this->get_tabs() ) : |
| 739 | - $active_tab = ! empty( $_GET['give_tab'] ) ? give_clean( $_GET['give_tab'] ) : 'form_field_options'; | |
| 799 | + Template\LegacyFormSettingCompatibility::migrateExistingFormSettings(); | |
| 800 | + | |
| 801 | + $active_tab = ! empty( $_GET['give_tab'] ) ? give_clean( $_GET['give_tab'] ) : 'form_template_options'; | |
| 740 | 802 | wp_nonce_field( 'give_save_form_meta', 'give_form_meta_nonce' ); |
| 803 | + | |
| 804 | + $added_upsells_notice = false; | |
| 741 | 805 | ?> |
| 742 | 806 | <input id="give_form_active_tab" type="hidden" name="give_form_active_tab"> |
| 743 | 807 | <div class="give-metabox-panel-wrap"> |
| 744 | 808 | <ul class="give-form-data-tabs give-metabox-tabs"> |
| @@ -752,9 +816,9 @@ | ||
| 752 | 816 | data-tab-id="<?php echo $form_data_tab['id']; ?>"> |
| 753 | 817 | <?php if ( ! empty( $form_data_tab['icon-html'] ) ) : ?> |
| 754 | 818 | <?php echo $form_data_tab['icon-html']; ?> |
| 755 | 819 | <?php else : ?> |
| 756 | - <span class="give-icon give-icon-default"></span> | |
| 820 | + <i class="fas fa-angle-right"></i> | |
| 757 | 821 | <?php endif; ?> |
| 758 | 822 | <span class="give-label"><?php echo $form_data_tab['label']; ?></span> |
| 759 | 823 | </a> |
| 760 | 824 | <?php if ( $this->has_sub_tab( $form_data_tab ) ) : ?> |
| @@ -765,9 +829,9 @@ | ||
| 765 | 829 | data-tab-id="<?php echo $sub_tab['id']; ?>"> |
| 766 | 830 | <?php if ( ! empty( $sub_tab['icon-html'] ) ) : ?> |
| 767 | 831 | <?php echo $sub_tab['icon-html']; ?> |
| 768 | 832 | <?php else : ?> |
| 769 | - <span class="give-icon give-icon-default"></span> | |
| 833 | + <i class="fas fa-angle-right"></i> | |
| 770 | 834 | <?php endif; ?> |
| 771 | 835 | <span class="give-label"><?php echo $sub_tab['label']; ?></span> |
| 772 | 836 | </a> |
| 773 | 837 | </li> |
| @@ -781,17 +845,24 @@ | ||
| 781 | 845 | <?php foreach ( $this->settings as $setting ) : ?> |
| 782 | 846 | <?php do_action( "give_before_{$setting['id']}_settings" ); ?> |
| 783 | 847 | <?php |
| 784 | 848 | // Determine if current panel is active. |
| 785 | - $is_active = $active_tab === $setting['id'] ? true : false; | |
| 849 | + $is_active = $active_tab === $setting['id']; | |
| 786 | 850 | ?> |
| 787 | 851 | <div id="<?php echo $setting['id']; ?>" |
| 788 | 852 | class="panel give_options_panel<?php echo( $is_active ? ' active' : '' ); ?>"> |
| 853 | + <?php | |
| 854 | + if ( ! $added_upsells_notice ) { | |
| 855 | + echo UpsellNotice::recurringAddon(); | |
| 856 | + $added_upsells_notice = true; | |
| 857 | + } | |
| 858 | + ?> | |
| 789 | 859 | <?php if ( ! empty( $setting['fields'] ) ) : ?> |
| 790 | 860 | <?php foreach ( $setting['fields'] as $field ) : ?> |
| 791 | 861 | <?php give_render_field( $field ); ?> |
| 792 | 862 | <?php endforeach; ?> |
| 793 | 863 | <?php endif; ?> |
| 864 | + <?php do_action( "give_post_{$setting['id']}_settings" ); ?> | |
| 794 | 865 | </div> |
| 795 | 866 | <?php do_action( "give_after_{$setting['id']}_settings" ); ?> |
| 796 | 867 | |
| 797 | 868 | |
| @@ -809,9 +880,9 @@ | ||
| 809 | 880 | <?php endif; ?> |
| 810 | 881 | <?php endif; ?> |
| 811 | 882 | <?php endforeach; ?> |
| 812 | 883 | </div> |
| 813 | - <?php | |
| 884 | + <?php | |
| 814 | 885 | endif; // End if(). |
| 815 | 886 | } |
| 816 | 887 | |
| 817 | 888 | /** |
| @@ -855,9 +926,9 @@ | ||
| 855 | 926 | * |
| 856 | 927 | * @return array |
| 857 | 928 | */ |
| 858 | 929 | function cmb2_metabox_settings() { |
| 859 | - $all_cmb2_settings = apply_filters( 'cmb2_meta_boxes', array() ); | |
| 930 | + $all_cmb2_settings = apply_filters( 'cmb2_meta_boxes', [] ); | |
| 860 | 931 | $give_forms_settings = $all_cmb2_settings; |
| 861 | 932 | |
| 862 | 933 | // Filter settings: Use only give forms related settings. |
| 863 | 934 | foreach ( $all_cmb2_settings as $index => $setting ) { |
| @@ -922,9 +993,9 @@ | ||
| 922 | 993 | |
| 923 | 994 | // Set default value for checkbox fields. |
| 924 | 995 | if ( |
| 925 | 996 | ! isset( $_POST[ $form_meta_key ] ) && |
| 926 | - in_array( $this->get_field_type( $form_meta_key ), array( 'checkbox', 'chosen' ) ) | |
| 997 | + in_array( $this->get_field_type( $form_meta_key ), [ 'checkbox', 'chosen', 'multicheck' ] ) | |
| 927 | 998 | ) { |
| 928 | 999 | $_POST[ $form_meta_key ] = ''; |
| 929 | 1000 | } |
| 930 | 1001 | |
| @@ -936,14 +1007,14 @@ | ||
| 936 | 1007 | case 'wysiwyg': |
| 937 | 1008 | $form_meta_value = wp_kses_post( $_POST[ $form_meta_key ] ); |
| 938 | 1009 | break; |
| 939 | 1010 | |
| 940 | - case 'donation_limit' : | |
| 1011 | + case 'donation_limit': | |
| 941 | 1012 | $form_meta_value = $_POST[ $form_meta_key ]; |
| 942 | 1013 | break; |
| 943 | 1014 | |
| 944 | 1015 | case 'group': |
| 945 | - $form_meta_value = array(); | |
| 1016 | + $form_meta_value = []; | |
| 946 | 1017 | |
| 947 | 1018 | foreach ( $_POST[ $form_meta_key ] as $index => $group ) { |
| 948 | 1019 | |
| 949 | 1020 | // Do not save template input field values. |
| @@ -950,9 +1021,9 @@ | ||
| 950 | 1021 | if ( '{{row-count-placeholder}}' === $index ) { |
| 951 | 1022 | continue; |
| 952 | 1023 | } |
| 953 | 1024 | |
| 954 | - $group_meta_value = array(); | |
| 1025 | + $group_meta_value = []; | |
| 955 | 1026 | foreach ( $group as $field_id => $field_value ) { |
| 956 | 1027 | switch ( $this->get_field_type( $field_id, $form_meta_key ) ) { |
| 957 | 1028 | case 'wysiwyg': |
| 958 | 1029 | $group_meta_value[ $field_id ] = wp_kses_post( $field_value ); |
| @@ -1012,8 +1083,11 @@ | ||
| 1012 | 1083 | }// End if(). |
| 1013 | 1084 | }// End foreach(). |
| 1014 | 1085 | }// End if(). |
| 1015 | 1086 | |
| 1087 | + // Update the goal progress for donation form. | |
| 1088 | + give_update_goal_progress( $post_id ); | |
| 1089 | + | |
| 1016 | 1090 | // Fire action after saving form meta. |
| 1017 | 1091 | do_action( 'give_post_process_give_forms_meta', $post_id, $post ); |
| 1018 | 1092 | } |
| 1019 | 1093 | |
| @@ -1018,8 +1092,110 @@ | ||
| 1018 | 1092 | } |
| 1019 | 1093 | |
| 1020 | 1094 | |
| 1021 | 1095 | /** |
| 1096 | + * Save form template setting handler | |
| 1097 | + * | |
| 1098 | + * @since 4.16.2 Normalize file field values as URLs when saving form template settings. | |
| 1099 | + * | |
| 1100 | + * @param string $meta_key | |
| 1101 | + * @param string $new_template | |
| 1102 | + * @param int $formID | |
| 1103 | + */ | |
| 1104 | + public function save_form_template_settings( $meta_key, $new_template, $formID ) { | |
| 1105 | + // Save setting for new template only if it is not empty. | |
| 1106 | + if ( ! $new_template ) { | |
| 1107 | + return; | |
| 1108 | + } | |
| 1109 | + | |
| 1110 | + $options = $_POST[ $new_template ]; | |
| 1111 | + | |
| 1112 | + // Exit | |
| 1113 | + if ( empty( $options ) ) { | |
| 1114 | + return; | |
| 1115 | + } | |
| 1116 | + | |
| 1117 | + /* @var Template $template */ | |
| 1118 | + $template = Give()->templates->getTemplate( $new_template ); | |
| 1119 | + | |
| 1120 | + // If selected theme is not registered then do not save it's options. | |
| 1121 | + if ( null === $template ) { | |
| 1122 | + return; | |
| 1123 | + } | |
| 1124 | + | |
| 1125 | + /* @var Template\Options $templateOptions */ | |
| 1126 | + $templateOptions = $template->getOptions(); | |
| 1127 | + $saveOptions = FormTemplateUtils::getOptions( $formID ); | |
| 1128 | + | |
| 1129 | + /* @var Section $group */ | |
| 1130 | + foreach ( $templateOptions->sections as $group ) { | |
| 1131 | + /* @var Fields $field */ | |
| 1132 | + foreach ( $group->fields as $field ) { | |
| 1133 | + if ( ! isset( $options[ $group->id ][ $field->id ] ) ) { | |
| 1134 | + continue; | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + // Initialize $value for every field to prevent value type conflict. | |
| 1138 | + $value = null; | |
| 1139 | + | |
| 1140 | + switch ( $field->type ) { | |
| 1141 | + case 'textarea': | |
| 1142 | + case 'wysiwyg': | |
| 1143 | + $value = wp_kses_post( $options[ $group->id ][ $field->id ] ); | |
| 1144 | + break; | |
| 1145 | + | |
| 1146 | + case 'donation_limit': | |
| 1147 | + $value = $options[ $group->id ][ $field->id ]; | |
| 1148 | + break; | |
| 1149 | + | |
| 1150 | + case 'file': | |
| 1151 | + $value = esc_url_raw( $options[ $group->id ][ $field->id ] ); | |
| 1152 | + break; | |
| 1153 | + | |
| 1154 | + case 'group': | |
| 1155 | + /* @var \Give\FormAPI\Form\Group $field */ | |
| 1156 | + foreach ( $options[ $group->id ][ $field->id ] as $index => $subFields ) { | |
| 1157 | + | |
| 1158 | + // Do not save template input field values. | |
| 1159 | + if ( '{{row-count-placeholder}}' === $index ) { | |
| 1160 | + continue; | |
| 1161 | + } | |
| 1162 | + | |
| 1163 | + $group_of_values = []; | |
| 1164 | + | |
| 1165 | + foreach ( $subFields as $field_id => $field_value ) { | |
| 1166 | + switch ( $field->getFieldArguments( $field_id )['type'] ) { | |
| 1167 | + case 'wysiwyg': | |
| 1168 | + $group_of_values[ $field_id ] = wp_kses_post( $field_value ); | |
| 1169 | + break; | |
| 1170 | + | |
| 1171 | + default: | |
| 1172 | + $group_of_values[ $field_id ] = give_clean( $field_value ); | |
| 1173 | + } | |
| 1174 | + } | |
| 1175 | + | |
| 1176 | + if ( ! empty( $group_of_values ) ) { | |
| 1177 | + $value[ $index ] = $group_of_values; | |
| 1178 | + } | |
| 1179 | + } | |
| 1180 | + | |
| 1181 | + // Arrange repeater field keys in order. | |
| 1182 | + $value = $value ? array_values( $value ) : []; | |
| 1183 | + break; | |
| 1184 | + | |
| 1185 | + default: | |
| 1186 | + $value = give_clean( $options[ $group->id ][ $field->id ] ); | |
| 1187 | + }// End switch(). | |
| 1188 | + | |
| 1189 | + $saveOptions[ $group->id ][ $field->id ] = $value; | |
| 1190 | + } | |
| 1191 | + } | |
| 1192 | + | |
| 1193 | + FormTemplateUtils::saveOptions( $formID, $saveOptions ); | |
| 1194 | + } | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + /** | |
| 1022 | 1198 | * Get field ID. |
| 1023 | 1199 | * |
| 1024 | 1200 | * @param array $field Array of Fields. |
| 1025 | 1201 | * |
| @@ -1047,9 +1223,9 @@ | ||
| 1047 | 1223 | * |
| 1048 | 1224 | * @return array |
| 1049 | 1225 | */ |
| 1050 | 1226 | private function get_fields_id( $setting ) { |
| 1051 | - $meta_keys = array(); | |
| 1227 | + $meta_keys = []; | |
| 1052 | 1228 | |
| 1053 | 1229 | if ( |
| 1054 | 1230 | ! empty( $setting ) |
| 1055 | 1231 | && array_key_exists( 'fields', $setting ) |
| @@ -1074,9 +1250,9 @@ | ||
| 1074 | 1250 | * |
| 1075 | 1251 | * @return array |
| 1076 | 1252 | */ |
| 1077 | 1253 | private function get_sub_fields_id( $setting ) { |
| 1078 | - $meta_keys = array(); | |
| 1254 | + $meta_keys = []; | |
| 1079 | 1255 | |
| 1080 | 1256 | if ( $this->has_sub_tab( $setting ) && ! empty( $setting['sub-fields'] ) ) { |
| 1081 | 1257 | foreach ( $setting['sub-fields'] as $fields ) { |
| 1082 | 1258 | if ( ! empty( $fields['fields'] ) ) { |
| @@ -1100,9 +1276,9 @@ | ||
| 1100 | 1276 | * |
| 1101 | 1277 | * @return array |
| 1102 | 1278 | */ |
| 1103 | 1279 | private function get_meta_keys_from_settings() { |
| 1104 | - $meta_keys = array(); | |
| 1280 | + $meta_keys = []; | |
| 1105 | 1281 | |
| 1106 | 1282 | foreach ( $this->settings as $setting ) { |
| 1107 | 1283 | $meta_key = $this->get_fields_id( $setting ); |
| 1108 | 1284 | |
| @@ -1148,9 +1324,9 @@ | ||
| 1148 | 1324 | * |
| 1149 | 1325 | * @return array |
| 1150 | 1326 | */ |
| 1151 | 1327 | private function get_field( $setting, $field_id ) { |
| 1152 | - $setting_field = array(); | |
| 1328 | + $setting_field = []; | |
| 1153 | 1329 | |
| 1154 | 1330 | if ( ! empty( $setting['fields'] ) ) { |
| 1155 | 1331 | foreach ( $setting['fields'] as $field ) { |
| 1156 | 1332 | if ( array_key_exists( 'id', $field ) && $field['id'] === $field_id ) { |
| @@ -1173,9 +1349,9 @@ | ||
| 1173 | 1349 | * |
| 1174 | 1350 | * @return array |
| 1175 | 1351 | */ |
| 1176 | 1352 | private function get_sub_field( $setting, $field_id ) { |
| 1177 | - $setting_field = array(); | |
| 1353 | + $setting_field = []; | |
| 1178 | 1354 | |
| 1179 | 1355 | if ( ! empty( $setting['sub-fields'] ) ) { |
| 1180 | 1356 | foreach ( $setting['sub-fields'] as $fields ) { |
| 1181 | 1357 | if ( $field = $this->get_field( $fields, $field_id ) ) { |
| @@ -1198,9 +1374,9 @@ | ||
| 1198 | 1374 | * |
| 1199 | 1375 | * @return array |
| 1200 | 1376 | */ |
| 1201 | 1377 | function get_setting_field( $field_id, $group_id = '' ) { |
| 1202 | - $setting_field = array(); | |
| 1378 | + $setting_field = []; | |
| 1203 | 1379 | |
| 1204 | 1380 | $_field_id = $field_id; |
| 1205 | 1381 | $field_id = empty( $group_id ) ? $field_id : $group_id; |
| 1206 | 1382 | |
| @@ -1238,14 +1414,17 @@ | ||
| 1238 | 1414 | * @return mixed |
| 1239 | 1415 | */ |
| 1240 | 1416 | function add_offline_donations_setting_tab( $settings ) { |
| 1241 | 1417 | if ( give_is_gateway_active( 'offline' ) ) { |
| 1242 | - $settings['offline_donations_options'] = apply_filters( 'give_forms_offline_donations_options', array( | |
| 1243 | - 'id' => 'offline_donations_options', | |
| 1244 | - 'title' => __( 'Offline Donations', 'give' ), | |
| 1245 | - 'icon-html' => '<span class="give-icon give-icon-purse"></span>', | |
| 1246 | - 'fields' => apply_filters( 'give_forms_offline_donations_metabox_fields', array() ), | |
| 1247 | - ) ); | |
| 1418 | + $settings['offline_donations_options'] = apply_filters( | |
| 1419 | + 'give_forms_offline_donations_options', | |
| 1420 | + [ | |
| 1421 | + 'id' => 'offline_donations_options', | |
| 1422 | + 'title' => __( 'Offline Donations', 'give' ), | |
| 1423 | + 'icon-html' => '<i class="fas fa-wallet"></i>', | |
| 1424 | + 'fields' => apply_filters( 'give_forms_offline_donations_metabox_fields', [] ), | |
| 1425 | + ] | |
| 1426 | + ); | |
| 1248 | 1427 | } |
| 1249 | 1428 | |
| 1250 | 1429 | return $settings; |
| 1251 | 1430 | } |
| @@ -1289,13 +1468,16 @@ | ||
| 1289 | 1468 | default: |
| 1290 | 1469 | if ( ! empty( $setting_field['data_type'] ) && 'price' === $setting_field['data_type'] ) { |
| 1291 | 1470 | $meta_value = $meta_value ? |
| 1292 | 1471 | give_sanitize_amount_for_db( $meta_value ) : |
| 1293 | - ( in_array( $setting_field['id'], array( | |
| 1294 | - '_give_set_price', | |
| 1295 | - '_give_custom_amount_minimum', | |
| 1296 | - '_give_set_goal' | |
| 1297 | - ) ) ? | |
| 1472 | + ( in_array( | |
| 1473 | + $setting_field['id'], | |
| 1474 | + [ | |
| 1475 | + '_give_set_price', | |
| 1476 | + '_give_custom_amount_minimum', | |
| 1477 | + '_give_set_goal', | |
| 1478 | + ] | |
| 1479 | + ) ? | |
| 1298 | 1480 | give_sanitize_amount_for_db( '1.00' ) : |
| 1299 | 1481 | 0 ); |
| 1300 | 1482 | } |
| 1301 | 1483 | } |
| @@ -1318,13 +1500,16 @@ | ||
| 1318 | 1500 | if ( |
| 1319 | 1501 | 'give_forms' === get_post_type( $post_id ) && |
| 1320 | 1502 | ! empty( $_POST['give_form_active_tab'] ) |
| 1321 | 1503 | ) { |
| 1322 | - $location = add_query_arg( 'give_tab', give_clean( $_POST['give_form_active_tab'] ), $location ); | |
| 1323 | - } | |
| 1504 | + $location = esc_url_raw( add_query_arg( 'give_tab', give_clean( $_POST['give_form_active_tab'] ), $location ) ); } | |
| 1324 | 1505 | |
| 1325 | 1506 | return $location; |
| 1326 | 1507 | } |
| 1327 | 1508 | } |
| 1328 | 1509 | |
| 1329 | -new Give_MetaBox_Form_Data(); | |
| 1330 | - | |
| 1510 | +/** | |
| 1511 | + * @since 4.3.0 use init action | |
| 1512 | + */ | |
| 1513 | +add_action( 'init', static function () { | |
| 1514 | + new Give_MetaBox_Form_Data(); | |
| 1515 | +}); | |