Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Give_MetaBox_Form_Data often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Give_MetaBox_Form_Data, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Give_MetaBox_Form_Data { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Meta box settings. |
||
| 21 | * |
||
| 22 | * @since 1.8 |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | private $settings = array(); |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Metabox ID. |
||
| 29 | * |
||
| 30 | * @since 1.8 |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private $metabox_id; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Metabox Label. |
||
| 37 | * |
||
| 38 | * @since 1.8 |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $metabox_label; |
||
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * Give_MetaBox_Form_Data constructor. |
||
| 46 | */ |
||
| 47 | function __construct() { |
||
|
|
|||
| 48 | $this->metabox_id = 'give-metabox-form-data'; |
||
| 49 | $this->metabox_label = __( 'Donation Form Options', 'give' ); |
||
| 50 | |||
| 51 | // Setup. |
||
| 52 | add_action( 'admin_init', array( $this, 'setup' ) ); |
||
| 53 | |||
| 54 | // Add metabox. |
||
| 55 | add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10 ); |
||
| 56 | |||
| 57 | // Save form meta. |
||
| 58 | add_action( 'save_post_give_forms', array( $this, 'save' ), 10, 2 ); |
||
| 59 | |||
| 60 | // cmb2 old setting loaders. |
||
| 61 | // add_filter( 'give_metabox_form_data_settings', array( $this, 'cmb2_metabox_settings' ) ); |
||
| 62 | // Add offline donations options. |
||
| 63 | add_filter( 'give_metabox_form_data_settings', array( $this, 'add_offline_donations_setting_tab' ), 0, 1 ); |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * Setup metabox related data. |
||
| 69 | * |
||
| 70 | * @since 1.8 |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | function setup() { |
||
| 74 | $this->settings = $this->get_settings(); |
||
| 75 | } |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * Get metabox settings |
||
| 80 | * |
||
| 81 | * @since 1.8 |
||
| 82 | * @return array |
||
| 83 | */ |
||
| 84 | function get_settings() { |
||
| 85 | $post_id = give_get_admin_post_id(); |
||
| 86 | $price = give_get_form_price( $post_id ); |
||
| 87 | $custom_amount_minimum = give_get_form_minimum_price( $post_id ); |
||
| 88 | $goal = give_format_amount( give_get_form_goal( $post_id ), array( 'sanitize' => false ) ); |
||
| 89 | $price_placeholder = give_format_decimal( '1.00', false, false ); |
||
| 90 | |||
| 91 | // No empty prices - min. 1.00 for new forms |
||
| 92 | if ( empty( $price ) && is_null( $post_id ) ) { |
||
| 93 | $price = '1.00'; |
||
| 94 | } |
||
| 95 | |||
| 96 | // Min. $1.00 for new forms |
||
| 97 | if ( empty( $custom_amount_minimum ) ) { |
||
| 98 | $custom_amount_minimum = '1.00'; |
||
| 99 | } |
||
| 100 | |||
| 101 | // Format amounts. |
||
| 102 | $price = give_format_amount( $price, array( 'sanitize' => false ) ); |
||
| 103 | $custom_amount_minimum = give_format_amount( $custom_amount_minimum, array( 'sanitize' => false ) ); |
||
| 104 | |||
| 105 | // Start with an underscore to hide fields from custom fields list |
||
| 106 | $prefix = '_give_'; |
||
| 107 | |||
| 108 | $settings = array( |
||
| 109 | /** |
||
| 110 | * Repeatable Field Groups |
||
| 111 | */ |
||
| 112 | 'form_field_options' => apply_filters( 'give_forms_field_options', array( |
||
| 113 | 'id' => 'form_field_options', |
||
| 114 | 'title' => __( 'Donation Options', 'give' ), |
||
| 115 | 'icon-html' => '<span class="give-icon give-icon-heart"></span>', |
||
| 116 | 'fields' => apply_filters( 'give_forms_donation_form_metabox_fields', array( |
||
| 117 | // Donation Option |
||
| 118 | array( |
||
| 119 | 'name' => __( 'Donation Option', 'give' ), |
||
| 120 | 'description' => __( 'Do you want this form to have one set donation price or multiple levels (for example, $10, $20, $50)?', 'give' ), |
||
| 121 | 'id' => $prefix . 'price_option', |
||
| 122 | 'type' => 'radio_inline', |
||
| 123 | 'default' => 'set', |
||
| 124 | 'options' => apply_filters( 'give_forms_price_options', array( |
||
| 125 | 'set' => __( 'Set Donation', 'give' ), |
||
| 126 | 'multi' => __( 'Multi-level Donation', 'give' ), |
||
| 127 | ) ), |
||
| 128 | ), |
||
| 129 | array( |
||
| 130 | 'name' => __( 'Set Donation', 'give' ), |
||
| 131 | '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' ), |
||
| 132 | 'id' => $prefix . 'set_price', |
||
| 133 | 'type' => 'text_small', |
||
| 134 | 'data_type' => 'price', |
||
| 135 | 'attributes' => array( |
||
| 136 | 'placeholder' => $price_placeholder, |
||
| 137 | 'value' => $price, |
||
| 138 | 'class' => 'give-money-field', |
||
| 139 | ), |
||
| 140 | ), |
||
| 141 | // Display Style |
||
| 142 | array( |
||
| 143 | 'name' => __( 'Display Style', 'give' ), |
||
| 144 | 'description' => __( 'Set how the donations levels will display on the form.', 'give' ), |
||
| 145 | 'id' => $prefix . 'display_style', |
||
| 146 | 'type' => 'radio_inline', |
||
| 147 | 'default' => 'buttons', |
||
| 148 | 'options' => array( |
||
| 149 | 'buttons' => __( 'Buttons', 'give' ), |
||
| 150 | 'radios' => __( 'Radios', 'give' ), |
||
| 151 | 'dropdown' => __( 'Dropdown', 'give' ), |
||
| 152 | ), |
||
| 153 | ), |
||
| 154 | // Custom Amount |
||
| 155 | array( |
||
| 156 | 'name' => __( 'Custom Amount', 'give' ), |
||
| 157 | 'description' => __( 'Do you want the user to be able to input their own donation amount?', 'give' ), |
||
| 158 | 'id' => $prefix . 'custom_amount', |
||
| 159 | 'type' => 'radio_inline', |
||
| 160 | 'default' => 'disabled', |
||
| 161 | 'options' => array( |
||
| 162 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 163 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 164 | ), |
||
| 165 | ), |
||
| 166 | array( |
||
| 167 | 'name' => __( 'Minimum Amount', 'give' ), |
||
| 168 | 'description' => __( 'Enter the minimum custom donation amount.', 'give' ), |
||
| 169 | 'id' => $prefix . 'custom_amount_minimum', |
||
| 170 | 'type' => 'text_small', |
||
| 171 | 'data_type' => 'price', |
||
| 172 | 'attributes' => array( |
||
| 173 | 'placeholder' => $price_placeholder, |
||
| 174 | 'value' => $custom_amount_minimum, |
||
| 175 | 'class' => 'give-money-field', |
||
| 176 | ), |
||
| 177 | ), |
||
| 178 | array( |
||
| 179 | 'name' => __( 'Custom Amount Text', 'give' ), |
||
| 180 | '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' ), |
||
| 181 | 'id' => $prefix . 'custom_amount_text', |
||
| 182 | 'type' => 'text_medium', |
||
| 183 | 'attributes' => array( |
||
| 184 | 'rows' => 3, |
||
| 185 | 'placeholder' => esc_attr__( 'Give a Custom Amount', 'give' ), |
||
| 186 | ), |
||
| 187 | ), |
||
| 188 | // Donation Levels: Repeatable CMB2 Group |
||
| 189 | array( |
||
| 190 | 'id' => $prefix . 'donation_levels', |
||
| 191 | 'type' => 'group', |
||
| 192 | 'options' => array( |
||
| 193 | 'add_button' => __( 'Add Level', 'give' ), |
||
| 194 | 'header_title' => __( 'Donation Level', 'give' ), |
||
| 195 | 'remove_button' => '<span class="dashicons dashicons-no"></span>', |
||
| 196 | ), |
||
| 197 | // Fields array works the same, except id's only need to be unique for this group. |
||
| 198 | // Prefix is not needed. |
||
| 199 | 'fields' => apply_filters( 'give_donation_levels_table_row', array( |
||
| 200 | array( |
||
| 201 | 'name' => __( 'ID', 'give' ), |
||
| 202 | 'id' => $prefix . 'id', |
||
| 203 | 'type' => 'levels_id', |
||
| 204 | ), |
||
| 205 | array( |
||
| 206 | 'name' => __( 'Amount', 'give' ), |
||
| 207 | 'id' => $prefix . 'amount', |
||
| 208 | 'type' => 'text_small', |
||
| 209 | 'data_type' => 'price', |
||
| 210 | 'attributes' => array( |
||
| 211 | 'placeholder' => $price_placeholder, |
||
| 212 | 'class' => 'give-money-field', |
||
| 213 | ), |
||
| 214 | ), |
||
| 215 | array( |
||
| 216 | 'name' => __( 'Text', 'give' ), |
||
| 217 | 'id' => $prefix . 'text', |
||
| 218 | 'type' => 'text', |
||
| 219 | 'attributes' => array( |
||
| 220 | 'placeholder' => __( 'Donation Level', 'give' ), |
||
| 221 | 'class' => 'give-multilevel-text-field', |
||
| 222 | ), |
||
| 223 | ), |
||
| 224 | array( |
||
| 225 | 'name' => __( 'Default', 'give' ), |
||
| 226 | 'id' => $prefix . 'default', |
||
| 227 | 'type' => 'give_default_radio_inline', |
||
| 228 | ), |
||
| 229 | ) ), |
||
| 230 | ), |
||
| 231 | array( |
||
| 232 | 'name' => 'donation_options_docs', |
||
| 233 | 'type' => 'docs_link', |
||
| 234 | 'url' => 'http://docs.givewp.com/form-donation-options', |
||
| 235 | 'title' => __( 'Donation Options', 'give' ), |
||
| 236 | ), |
||
| 237 | ), |
||
| 238 | $post_id |
||
| 239 | ), |
||
| 240 | ) ), |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Display Options |
||
| 244 | */ |
||
| 245 | 'form_display_options' => apply_filters( 'give_form_display_options', array( |
||
| 246 | 'id' => 'form_display_options', |
||
| 247 | 'title' => __( 'Form Display', 'give' ), |
||
| 248 | 'icon-html' => '<span class="give-icon give-icon-display"></span>', |
||
| 249 | 'fields' => apply_filters( 'give_forms_display_options_metabox_fields', array( |
||
| 250 | array( |
||
| 251 | 'name' => __( 'Display Options', 'give' ), |
||
| 252 | 'desc' => sprintf( __( 'How would you like to display donation information for this form?', 'give' ), '#' ), |
||
| 253 | 'id' => $prefix . 'payment_display', |
||
| 254 | 'type' => 'radio_inline', |
||
| 255 | 'options' => array( |
||
| 256 | 'onpage' => __( 'All Fields', 'give' ), |
||
| 257 | 'modal' => __( 'Modal', 'give' ), |
||
| 258 | 'reveal' => __( 'Reveal', 'give' ), |
||
| 259 | 'button' => __( 'Button', 'give' ), |
||
| 260 | ), |
||
| 261 | 'default' => 'onpage', |
||
| 262 | ), |
||
| 263 | array( |
||
| 264 | 'id' => $prefix . 'reveal_label', |
||
| 265 | 'name' => __( 'Continue Button', 'give' ), |
||
| 266 | 'desc' => __( 'The button label for displaying the additional payment fields.', 'give' ), |
||
| 267 | 'type' => 'text_small', |
||
| 268 | 'attributes' => array( |
||
| 269 | 'placeholder' => esc_attr__( 'Donate Now', 'give' ), |
||
| 270 | ), |
||
| 271 | ), |
||
| 272 | array( |
||
| 273 | 'id' => $prefix . 'checkout_label', |
||
| 274 | 'name' => __( 'Submit Button', 'give' ), |
||
| 275 | 'desc' => __( 'The button label for completing a donation.', 'give' ), |
||
| 276 | 'type' => 'text_small', |
||
| 277 | 'attributes' => array( |
||
| 278 | 'placeholder' => __( 'Donate Now', 'give' ), |
||
| 279 | ), |
||
| 280 | ), |
||
| 281 | array( |
||
| 282 | 'name' => __( 'Default Gateway', 'give' ), |
||
| 283 | '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' ), |
||
| 284 | 'id' => $prefix . 'default_gateway', |
||
| 285 | 'type' => 'default_gateway', |
||
| 286 | ), |
||
| 287 | array( |
||
| 288 | 'name' => __( 'Guest Donations', 'give' ), |
||
| 289 | 'desc' => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ), |
||
| 290 | 'id' => $prefix . 'logged_in_only', |
||
| 291 | 'type' => 'radio_inline', |
||
| 292 | 'default' => 'enabled', |
||
| 293 | 'options' => array( |
||
| 294 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 295 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 296 | ), |
||
| 297 | ), |
||
| 298 | array( |
||
| 299 | 'name' => __( 'Registration', 'give' ), |
||
| 300 | 'desc' => __( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ), |
||
| 301 | 'id' => $prefix . 'show_register_form', |
||
| 302 | 'type' => 'radio', |
||
| 303 | 'options' => array( |
||
| 304 | 'none' => __( 'None', 'give' ), |
||
| 305 | 'registration' => __( 'Registration', 'give' ), |
||
| 306 | 'login' => __( 'Login', 'give' ), |
||
| 307 | 'both' => __( 'Registration + Login', 'give' ), |
||
| 308 | ), |
||
| 309 | 'default' => 'none', |
||
| 310 | ), |
||
| 311 | array( |
||
| 312 | 'name' => __( 'Floating Labels', 'give' ), |
||
| 313 | /* translators: %s: forms http://docs.givewp.com/form-floating-labels */ |
||
| 314 | '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' ) ), |
||
| 315 | 'id' => $prefix . 'form_floating_labels', |
||
| 316 | 'type' => 'radio_inline', |
||
| 317 | 'options' => array( |
||
| 318 | 'global' => __( 'Global Option', 'give' ), |
||
| 319 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 320 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 321 | ), |
||
| 322 | 'default' => 'global', |
||
| 323 | ), |
||
| 324 | array( |
||
| 325 | 'name' => 'form_display_docs', |
||
| 326 | 'type' => 'docs_link', |
||
| 327 | 'url' => 'http://docs.givewp.com/form-display-options', |
||
| 328 | 'title' => __( 'Form Display', 'give' ), |
||
| 329 | ), |
||
| 330 | ), |
||
| 331 | $post_id |
||
| 332 | ), |
||
| 333 | ) |
||
| 334 | ), |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Donation Goals |
||
| 338 | */ |
||
| 339 | 'donation_goal_options' => apply_filters( 'give_donation_goal_options', array( |
||
| 340 | 'id' => 'donation_goal_options', |
||
| 341 | 'title' => __( 'Donation Goal', 'give' ), |
||
| 342 | 'icon-html' => '<span class="give-icon give-icon-target"></span>', |
||
| 343 | 'fields' => apply_filters( 'give_forms_donation_goal_metabox_fields', array( |
||
| 344 | // Goals |
||
| 345 | array( |
||
| 346 | 'name' => __( 'Donation Goal', 'give' ), |
||
| 347 | 'description' => __( 'Do you want to set a donation goal for this form?', 'give' ), |
||
| 348 | 'id' => $prefix . 'goal_option', |
||
| 349 | 'type' => 'radio_inline', |
||
| 350 | 'default' => 'disabled', |
||
| 351 | 'options' => array( |
||
| 352 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 353 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 354 | ), |
||
| 355 | ), |
||
| 356 | array( |
||
| 357 | 'name' => __( 'Goal Amount', 'give' ), |
||
| 358 | 'description' => __( 'This is the monetary goal amount you want to reach for this form.', 'give' ), |
||
| 359 | 'id' => $prefix . 'set_goal', |
||
| 360 | 'type' => 'text_small', |
||
| 361 | 'data_type' => 'price', |
||
| 362 | 'attributes' => array( |
||
| 363 | 'placeholder' => give_format_decimal( '0.00', false, false ), |
||
| 364 | 'value' => $goal, |
||
| 365 | 'class' => 'give-money-field', |
||
| 366 | ), |
||
| 367 | ), |
||
| 368 | |||
| 369 | array( |
||
| 370 | 'name' => __( 'Goal Format', 'give' ), |
||
| 371 | '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".', 'give' ), |
||
| 372 | 'id' => $prefix . 'goal_format', |
||
| 373 | 'type' => 'radio_inline', |
||
| 374 | 'default' => 'amount', |
||
| 375 | 'options' => array( |
||
| 376 | 'amount' => __( 'Amount', 'give' ), |
||
| 377 | 'percentage' => __( 'Percentage', 'give' ), |
||
| 378 | ), |
||
| 379 | ), |
||
| 380 | array( |
||
| 381 | 'name' => __( 'Progress Bar Color', 'give' ), |
||
| 382 | 'desc' => __( 'Customize the color of the goal progress bar.', 'give' ), |
||
| 383 | 'id' => $prefix . 'goal_color', |
||
| 384 | 'type' => 'colorpicker', |
||
| 385 | 'default' => '#2bc253', |
||
| 386 | ), |
||
| 387 | |||
| 388 | array( |
||
| 389 | 'name' => __( 'Close Form', 'give' ), |
||
| 390 | 'desc' => __( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ), |
||
| 391 | 'id' => $prefix . 'close_form_when_goal_achieved', |
||
| 392 | 'type' => 'radio_inline', |
||
| 393 | 'default' => 'disabled', |
||
| 394 | 'options' => array( |
||
| 395 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 396 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 397 | ), |
||
| 398 | ), |
||
| 399 | array( |
||
| 400 | 'name' => __( 'Goal Achieved Message', 'give' ), |
||
| 401 | 'desc' => __( 'Do you want to display a custom message when the goal is closed?', 'give' ), |
||
| 402 | 'id' => $prefix . 'form_goal_achieved_message', |
||
| 403 | 'type' => 'wysiwyg', |
||
| 404 | 'default' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ), |
||
| 405 | ), |
||
| 406 | array( |
||
| 407 | 'name' => 'donation_goal_docs', |
||
| 408 | 'type' => 'docs_link', |
||
| 409 | 'url' => 'http://docs.givewp.com/form-donation-goal', |
||
| 410 | 'title' => __( 'Donation Goal', 'give' ), |
||
| 411 | ), |
||
| 412 | ), |
||
| 413 | $post_id |
||
| 414 | ), |
||
| 415 | ) ), |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Content Field |
||
| 419 | */ |
||
| 420 | 'form_content_options' => apply_filters( 'give_forms_content_options', array( |
||
| 421 | 'id' => 'form_content_options', |
||
| 422 | 'title' => __( 'Form Content', 'give' ), |
||
| 423 | 'icon-html' => '<span class="give-icon give-icon-edit"></span>', |
||
| 424 | 'fields' => apply_filters( 'give_forms_content_options_metabox_fields', array( |
||
| 425 | |||
| 426 | // Donation content. |
||
| 427 | array( |
||
| 428 | 'name' => __( 'Display Content', 'give' ), |
||
| 429 | 'description' => __( 'Do you want to add custom content to this form?', 'give' ), |
||
| 430 | 'id' => $prefix . 'display_content', |
||
| 431 | 'type' => 'radio_inline', |
||
| 432 | 'options' => array( |
||
| 433 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 434 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 435 | ), |
||
| 436 | 'default' => 'disabled', |
||
| 437 | ), |
||
| 438 | |||
| 439 | // Content placement. |
||
| 440 | array( |
||
| 441 | 'name' => __( 'Content Placement', 'give' ), |
||
| 442 | 'description' => __( 'This option controls where the content appears within the donation form.', 'give' ), |
||
| 443 | 'id' => $prefix . 'content_placement', |
||
| 444 | 'type' => 'radio_inline', |
||
| 445 | 'options' => apply_filters( 'give_forms_content_options_select', array( |
||
| 446 | 'give_pre_form' => __( 'Above fields', 'give' ), |
||
| 447 | 'give_post_form' => __( 'Below fields', 'give' ), |
||
| 448 | ) |
||
| 449 | ), |
||
| 450 | 'default' => 'give_pre_form', |
||
| 451 | ), |
||
| 452 | array( |
||
| 453 | 'name' => __( 'Content', 'give' ), |
||
| 454 | 'description' => __( 'This content will display on the single give form page.', 'give' ), |
||
| 455 | 'id' => $prefix . 'form_content', |
||
| 456 | 'type' => 'wysiwyg', |
||
| 457 | ), |
||
| 458 | array( |
||
| 459 | 'name' => 'form_content_docs', |
||
| 460 | 'type' => 'docs_link', |
||
| 461 | 'url' => 'http://docs.givewp.com/form-content', |
||
| 462 | 'title' => __( 'Form Content', 'give' ), |
||
| 463 | ), |
||
| 464 | ), |
||
| 465 | $post_id |
||
| 466 | ), |
||
| 467 | ) ), |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Terms & Conditions |
||
| 471 | */ |
||
| 472 | 'form_terms_options' => apply_filters( 'give_forms_terms_options', array( |
||
| 473 | 'id' => 'form_terms_options', |
||
| 474 | 'title' => __( 'Terms & Conditions', 'give' ), |
||
| 475 | 'icon-html' => '<span class="give-icon give-icon-checklist"></span>', |
||
| 476 | 'fields' => apply_filters( 'give_forms_terms_options_metabox_fields', array( |
||
| 477 | // Donation Option |
||
| 478 | array( |
||
| 479 | 'name' => __( 'Terms and Conditions', 'give' ), |
||
| 480 | 'description' => __( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ), |
||
| 481 | 'id' => $prefix . 'terms_option', |
||
| 482 | 'type' => 'radio_inline', |
||
| 483 | 'options' => apply_filters( 'give_forms_content_options_select', array( |
||
| 484 | 'global' => __( 'Global Option', 'give' ), |
||
| 485 | 'enabled' => __( 'Customize', 'give' ), |
||
| 486 | 'disabled' => __( 'Disable', 'give' ), |
||
| 487 | ) |
||
| 488 | ), |
||
| 489 | 'default' => 'global', |
||
| 490 | ), |
||
| 491 | array( |
||
| 492 | 'id' => $prefix . 'agree_label', |
||
| 493 | 'name' => __( 'Agreement Label', 'give' ), |
||
| 494 | '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' ), |
||
| 495 | 'type' => 'text', |
||
| 496 | 'size' => 'regular', |
||
| 497 | 'attributes' => array( |
||
| 498 | 'placeholder' => esc_attr__( 'Agree to Terms?', 'give' ), |
||
| 499 | ), |
||
| 500 | ), |
||
| 501 | array( |
||
| 502 | 'id' => $prefix . 'agree_text', |
||
| 503 | 'name' => __( 'Agreement Text', 'give' ), |
||
| 504 | 'desc' => __( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ), |
||
| 505 | 'default' => give_get_option('agreement_text'), |
||
| 506 | 'type' => 'wysiwyg', |
||
| 507 | ), |
||
| 508 | array( |
||
| 509 | 'name' => 'terms_docs', |
||
| 510 | 'type' => 'docs_link', |
||
| 511 | 'url' => 'http://docs.givewp.com/form-terms', |
||
| 512 | 'title' => __( 'Terms and Conditions', 'give' ), |
||
| 513 | ), |
||
| 514 | ), |
||
| 515 | $post_id |
||
| 516 | ), |
||
| 517 | ) ), |
||
| 518 | ); |
||
| 519 | |||
| 520 | |||
| 521 | /** |
||
| 522 | * Filter the metabox tabbed panel settings. |
||
| 523 | */ |
||
| 524 | $settings = apply_filters( 'give_metabox_form_data_settings', $settings, $post_id ); |
||
| 525 | |||
| 526 | // Output. |
||
| 527 | return $settings; |
||
| 528 | } |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Add metabox. |
||
| 532 | * |
||
| 533 | * @since 1.8 |
||
| 534 | * @return void |
||
| 535 | */ |
||
| 536 | public function add_meta_box() { |
||
| 537 | add_meta_box( |
||
| 538 | $this->get_metabox_ID(), |
||
| 539 | $this->get_metabox_label(), |
||
| 540 | array( $this, 'output' ), |
||
| 541 | array( 'give_forms' ), |
||
| 542 | 'normal', |
||
| 543 | 'high' |
||
| 544 | ); |
||
| 545 | } |
||
| 546 | |||
| 547 | |||
| 548 | /** |
||
| 549 | * Enqueue scripts. |
||
| 550 | * |
||
| 551 | * @since 1.8 |
||
| 552 | * @return void |
||
| 553 | */ |
||
| 554 | function enqueue_script() { |
||
| 555 | global $post; |
||
| 556 | |||
| 557 | if ( is_object( $post ) && 'give_forms' === $post->post_type ) { |
||
| 558 | |||
| 559 | } |
||
| 560 | } |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Get metabox id. |
||
| 564 | * |
||
| 565 | * @since 1.8 |
||
| 566 | * @return string |
||
| 567 | */ |
||
| 568 | function get_metabox_ID() { |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Get metabox label. |
||
| 574 | * |
||
| 575 | * @since 1.8 |
||
| 576 | * @return string |
||
| 577 | */ |
||
| 578 | function get_metabox_label() { |
||
| 581 | |||
| 582 | |||
| 583 | /** |
||
| 584 | * Get metabox tabs. |
||
| 585 | * |
||
| 586 | * @since 1.8 |
||
| 587 | * @return array |
||
| 588 | */ |
||
| 589 | public function get_tabs() { |
||
| 625 | |||
| 626 | /** |
||
| 627 | * Output metabox settings. |
||
| 628 | * |
||
| 629 | * @since 1.8 |
||
| 630 | * @return void |
||
| 631 | */ |
||
| 632 | public function output() { |
||
| 706 | |||
| 707 | |||
| 708 | /** |
||
| 709 | * Check if setting field has sub tabs/fields |
||
| 710 | * |
||
| 711 | * @since 1.8 |
||
| 712 | * |
||
| 713 | * @param $field_setting |
||
| 714 | * |
||
| 715 | * @return bool |
||
| 716 | */ |
||
| 717 | private function has_sub_tab( $field_setting ) { |
||
| 725 | |||
| 726 | /** |
||
| 727 | * CMB2 settings loader. |
||
| 728 | * |
||
| 729 | * @since 1.8 |
||
| 730 | * @return array |
||
| 731 | */ |
||
| 732 | function cmb2_metabox_settings() { |
||
| 746 | |||
| 747 | /** |
||
| 748 | * Check if we're saving, the trigger an action based on the post type. |
||
| 749 | * |
||
| 750 | * @since 1.8 |
||
| 751 | * |
||
| 752 | * @param int $post_id |
||
| 753 | * @param object $post |
||
| 754 | * |
||
| 755 | * @return void |
||
| 756 | */ |
||
| 757 | public function save( $post_id, $post ) { |
||
| 877 | |||
| 878 | |||
| 879 | /** |
||
| 880 | * Get field ID. |
||
| 881 | * |
||
| 882 | * @since 1.8 |
||
| 883 | * |
||
| 884 | * @param array $field |
||
| 885 | * |
||
| 886 | * @return string |
||
| 887 | */ |
||
| 888 | private function get_field_id( $field ) { |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Get fields ID. |
||
| 901 | * |
||
| 902 | * @since 1.8 |
||
| 903 | * |
||
| 904 | * @param $setting |
||
| 905 | * |
||
| 906 | * @return array |
||
| 907 | */ |
||
| 908 | View Code Duplication | private function get_fields_id( $setting ) { |
|
| 921 | |||
| 922 | /** |
||
| 923 | * Get sub fields ID. |
||
| 924 | * |
||
| 925 | * @since 1.8 |
||
| 926 | * |
||
| 927 | * @param $setting |
||
| 928 | * |
||
| 929 | * @return array |
||
| 930 | */ |
||
| 931 | private function get_sub_fields_id( $setting ) { |
||
| 948 | |||
| 949 | |||
| 950 | /** |
||
| 951 | * Get all setting field ids. |
||
| 952 | * |
||
| 953 | * @since 1.8 |
||
| 954 | * @return array |
||
| 955 | */ |
||
| 956 | private function get_meta_keys_from_settings() { |
||
| 971 | |||
| 972 | |||
| 973 | /** |
||
| 974 | * Get field type. |
||
| 975 | * |
||
| 976 | * @since 1.8 |
||
| 977 | * |
||
| 978 | * @param string $field_id |
||
| 979 | * @param string $group_id |
||
| 980 | * |
||
| 981 | * @return string |
||
| 982 | */ |
||
| 983 | function get_field_type( $field_id, $group_id = '' ) { |
||
| 992 | |||
| 993 | |||
| 994 | /** |
||
| 995 | * Get Field |
||
| 996 | * |
||
| 997 | * @since 1.8 |
||
| 998 | * |
||
| 999 | * @param array $setting |
||
| 1000 | * @param string $field_id |
||
| 1001 | * |
||
| 1002 | * @return array |
||
| 1003 | */ |
||
| 1004 | private function get_field( $setting, $field_id ) { |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Get Sub Field |
||
| 1021 | * |
||
| 1022 | * @since 1.8 |
||
| 1023 | * |
||
| 1024 | * @param array $setting |
||
| 1025 | * @param string $field_id |
||
| 1026 | * |
||
| 1027 | * @return array |
||
| 1028 | */ |
||
| 1029 | View Code Duplication | private function get_sub_field( $setting, $field_id ) { |
|
| 1043 | |||
| 1044 | /** |
||
| 1045 | * Get setting field. |
||
| 1046 | * |
||
| 1047 | * @since 1.8 |
||
| 1048 | * |
||
| 1049 | * @param string $field_id |
||
| 1050 | * @param string $group_id Get sub field from group. |
||
| 1051 | * |
||
| 1052 | * @return array |
||
| 1053 | */ |
||
| 1054 | function get_setting_field( $field_id, $group_id = '' ) { |
||
| 1083 | |||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Add offline donations setting tab to donation form options metabox. |
||
| 1087 | * |
||
| 1088 | * @since 1.8 |
||
| 1089 | * |
||
| 1090 | * @param array $settings List of form settings. |
||
| 1091 | * |
||
| 1092 | * @return mixed |
||
| 1093 | */ |
||
| 1094 | function add_offline_donations_setting_tab( $settings ) { |
||
| 1106 | |||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Sanitize form meta values before saving. |
||
| 1110 | * |
||
| 1111 | * @since 1.8.9 |
||
| 1112 | * @access public |
||
| 1113 | * |
||
| 1114 | * @param mixed $meta_value |
||
| 1115 | * @param array $setting_field |
||
| 1116 | * |
||
| 1117 | * @return mixed |
||
| 1118 | */ |
||
| 1119 | function sanitize_form_meta( $meta_value, $setting_field ) { |
||
| 1149 | } |
||
| 1150 | |||
| 1153 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.