PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | includes/admin/class-admin-settings.php +745 -532 2.3.24.16.9 View file →
@@ -27,15 +27,15 @@
27 27 *
28 28 * @since 1.8
29 29 * @var array List of settings.
30 30 */
31 - private static $settings = array();
31 + private static $settings = [];
32 32
33 33 /**
34 34 * Setting filter and action prefix.
35 35 *
36 36 * @since 1.8
37 - * @var string setting fileter and action anme prefix.
37 + * @var string setting filter and action name prefix.
38 38 */
39 39 private static $setting_filter_prefix = '';
40 40
41 41 /**
@@ -43,9 +43,9 @@
43 43 *
44 44 * @since 1.8
45 45 * @var array List of errors.
46 46 */
47 - private static $errors = array();
47 + private static $errors = [];
48 48
49 49 /**
50 50 * Update messages.
51 51 *
@@ -51,9 +51,9 @@
51 51 *
52 52 * @since 1.8
53 53 * @var array List of messages.
54 54 */
55 - private static $messages = array();
55 + private static $messages = [];
56 56
57 57 /**
58 58 * Include the settings page classes.
59 59 *
@@ -67,13 +67,14 @@
67 67 * Note: filter dynamically fire on basis of setting page slug.
68 68 * For example: if you register a setting page with give-settings menu slug
69 69 * then filter will be give-settings_get_settings_pages
70 70 *
71 + * @since 3.17.1 cast to array
71 72 * @since 1.8
72 73 *
73 74 * @param array $settings Array of settings class object.
74 75 */
75 - self::$settings = apply_filters( self::$setting_filter_prefix . '_get_settings_pages', array() );
76 + self::$settings = (array)apply_filters( self::$setting_filter_prefix . '_get_settings_pages', [] );
76 77
77 78 return self::$settings;
78 79 }
79 80
@@ -175,9 +176,9 @@
175 176
176 177 if ( 0 < count( self::$errors ) ) {
177 178 foreach ( self::$errors as $code => $message ) {
178 179 $notice_html .= sprintf(
179 - '<div id="setting-error-%1$s" class="%2$s error" style="display: none"><p><strong>%3$s</strong></p></div>',
180 + '<div id="setting-error-%1$s" class="%2$s error" style="display: none"><p>%3$s</p></div>',
180 181 $code,
181 182 $classes,
182 183 $message
183 184 );
@@ -225,19 +226,20 @@
225 226 * @since 1.8
226 227 */
227 228 do_action( self::$setting_filter_prefix . '_start' );
228 229
229 - $current_tab = give_get_current_setting_tab();
230 + $current_tab = give_get_current_setting_tab();
231 + $current_section = give_get_current_setting_section();
230 232
231 233 // Include settings pages.
232 234 $all_setting = self::get_settings_pages();
233 235
234 236 /* @var object $current_setting_obj */
235 - $current_setting_obj = new StdClass;
237 + $current_setting_obj = new StdClass();
236 238
237 239 foreach ( $all_setting as $setting ) {
238 240 if (
239 - method_exists( $setting, 'get_id' ) &&
241 + is_object($setting) && method_exists( $setting, 'get_id' ) &&
240 242 $current_tab === $setting->get_id()
241 243 ) {
242 244 $current_setting_obj = $setting;
243 245 break;
@@ -257,9 +259,9 @@
257 259 * then action will be give-settings_tabs_array
258 260 *
259 261 * @since 1.8
260 262 */
261 - $tabs = apply_filters( self::$setting_filter_prefix . '_tabs_array', array() );
263 + $tabs = apply_filters( self::$setting_filter_prefix . '_tabs_array', [] );
262 264
263 265 include 'views/html-admin-settings.php';
264 266
265 267 return true;
@@ -313,283 +315,541 @@
313 315 /**
314 316 * Output admin fields.
315 317 *
316 318 * Loops though the give options array and outputs each field.
317 - *
318 - * @todo : Refactor this function
319 + *
320 + * @since 4.1.0 Display tabs only when there is more than one group available
319 321 * @since 1.8
322 + * @access public
323 + *
324 + * @param array $sections Opens array to output.
325 + * @param string $option_name Opens array to output.
320 326 *
321 - * @param array $options Opens array to output.
322 - * @param string $option_name Opens array to output.
323 - *
324 327 * @return void
328 + * @todo Refactor this function
329 + *
325 330 */
326 - public static function output_fields( $options, $option_name = '' ) {
327 - $current_tab = give_get_current_setting_tab();
331 + public static function output_fields( $sections, $option_name = '' ) {
328 332
329 - // Field Default values.
330 - $defaults = array(
331 - 'id' => '',
332 - 'class' => '',
333 - 'css' => '',
334 - 'default' => '',
335 - 'desc' => '',
336 - 'table_html' => true,
337 - 'repeat' => false,
338 - 'repeat_btn_title' => __( 'Add Field', 'give' ),
339 - );
333 + $current_page = give_get_current_setting_page();
334 + $current_tab = give_get_current_setting_tab();
335 + $current_section = give_get_current_setting_section();
336 + $groups = give_get_settings_groups();
340 337
341 - foreach ( $options as $value ) {
342 - if ( ! isset( $value['type'] ) ) {
343 - continue;
338 + if ( $groups ) {
339 + $defaultGroup = current( array_keys( $groups ) );
340 + ?>
341 + <div class="give-settings-section-content">
342 + <?php
343 + if (count($groups) > 1) : ?>
344 + <div class="give-settings-section-group-menu">
345 + <ul>
346 + <?php
347 + foreach ($groups as $slug => $group) {
348 + $current_group = ! empty($_GET['group']) ? give_clean($_GET['group']) : $defaultGroup;
349 + $active_class = ($slug === $current_group) ? 'active' : '';
350 +
351 + echo sprintf(
352 + '<li><a class="%1$s" href="%2$s" data-group="%3$s">%4$s</a></li>',
353 + esc_html($active_class),
354 + esc_url(admin_url("edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$slug}")),
355 + esc_html($slug),
356 + esc_html($group)
357 + );
358 + }
359 + ?>
360 + </ul>
361 + </div>
362 + <?php
363 + endif; ?>
364 + <div class="give-settings-section-group-content">
365 + <?php
366 + foreach ( $sections as $group => $fields ) {
367 + $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $defaultGroup;
368 + $hide_class = $group !== $current_group ? 'give-hidden' : '';
369 +
370 + printf(
371 + '<div id="give-settings-section-group-%1$s" class="give-settings-section-group %2$s">',
372 + esc_attr( $group ),
373 + esc_html( $hide_class )
374 + );
375 +
376 + /**
377 + * Filter sub group settings.
378 + *
379 + * @since 2.8.0
380 + */
381 + $subGroups = apply_filters( "give_get_groups_{$current_section}_{$group}", [] );
382 +
383 + if ( $subGroups ) {
384 + $subGroupIds = array_keys( $subGroups );
385 + $defaultSubGroup = current( $subGroupIds );
386 + $lastSubGroupId = end( $subGroupIds );
387 +
388 + echo '<ul class="give-subsubsub">';
389 + foreach ( $subGroups as $id => $label ) {
390 + $separator = $lastSubGroupId === $id ? '' : '&nbsp;|&nbsp;';
391 + $currentSubGroup = ! empty( $_GET['sub-group'] ) ? give_clean( $_GET['sub-group'] ) : $defaultSubGroup;
392 + $class = $id === $currentSubGroup ? 'current' : '';
393 + printf(
394 + '<li><a data-subgroup="%1$s" href="%2$s" class="%5$s">%3$s</a>%4$s</li>',
395 + $id,
396 + esc_url( admin_url( "edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$group}&sub-group={$id}" ) ),
397 + $label,
398 + $separator,
399 + $class
400 + );
401 + }
402 + echo '</ul>';
403 +
404 + foreach ( $fields as $id => $subgroup ) {
405 + $current_group = ! empty( $_GET['sub-group'] ) ? give_clean( $_GET['sub-group'] ) : $defaultSubGroup;
406 + $hide_class = $id !== $current_group ? 'give-hidden' : '';
407 +
408 + printf(
409 + '<div id="give-settings-section-subgroup-%1$s" class="give-settings-section-subgroup %2$s">',
410 + esc_attr( $id ),
411 + esc_html( $hide_class )
412 + );
413 +
414 + foreach ( $subgroup as $setting ) {
415 + if ( ! isset( $setting['type'] ) ) {
416 + continue;
417 + }
418 + self::prepare_settings_field( $setting, $option_name );
419 + }
420 +
421 + echo '</div>';
422 + }
423 + } else {
424 + foreach ( $fields as $value ) {
425 + if ( ! isset( $value['type'] ) ) {
426 + continue;
427 + }
428 + self::prepare_settings_field( $value, $option_name );
429 + }
430 + }
431 +
432 + echo '</div>';
433 + }
434 + ?>
435 + </div>
436 + </div>
437 + <?php
438 + } else {
439 +
440 + // Loop through each section.
441 + foreach ( $sections as $value ) {
442 + if ( ! isset( $value['type'] ) ) {
443 + continue;
444 + }
445 + self::prepare_settings_field( $value, $option_name );
344 446 }
447 + }
345 448
346 - // Set title.
347 - $defaults['title'] = isset( $value['name'] ) ? $value['name'] : '';
449 + }
348 450
349 - // Set default setting.
350 - $value = wp_parse_args( $value, $defaults );
451 + /**
452 + * This function will help you prepare the admin settings field.
453 + *
454 + * @since 4.1.0 Added support for code editor field.
455 + * @since 2.5.5
456 + *
457 + * @param array $value Settings Field Array.
458 + * @param string $option_name Option Name.
459 + *
460 + * @return mixed
461 + */
462 + public static function prepare_settings_field( $value, $option_name ) {
351 463
352 - // Colorpicker field.
353 - $value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] );
354 - $value['type'] = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] );
464 + $current_tab = give_get_current_setting_tab();
355 465
466 + // Field Default values.
467 + $defaults = [
468 + 'id' => '',
469 + 'class' => '',
470 + 'css' => '',
471 + 'default' => '',
472 + 'desc' => '',
473 + 'table_html' => true,
474 + 'repeat' => false,
475 + 'repeat_btn_title' => __( 'Add Field', 'give' ),
476 + ];
356 477
357 - // Custom attribute handling.
358 - $custom_attributes = array();
478 + // Set title.
479 + $defaults['title'] = isset( $value['name'] ) ? $value['name'] : '';
359 480
360 - if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) {
361 - foreach ( $value['attributes'] as $attribute => $attribute_value ) {
362 - $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
363 - }
481 + // Set default setting.
482 + $value = wp_parse_args( $value, $defaults );
483 +
484 + // Colorpicker field.
485 + $value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] );
486 + $value['type'] = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] );
487 +
488 + // Custom attribute handling.
489 + $custom_attributes = [];
490 +
491 + if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) {
492 + foreach ( $value['attributes'] as $attribute => $attribute_value ) {
493 + $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
364 494 }
495 + }
365 496
366 - // Description handling.
367 - $description = self::get_field_description( $value );
497 + // Description handling.
498 + $description = self::get_field_description( $value );
368 499
369 - // Switch based on type.
370 - switch ( $value['type'] ) {
500 + // Switch based on type.
501 + switch ( $value['type'] ) {
371 502
372 - // Section Titles.
373 - case 'title':
374 - if ( ! empty( $value['title'] ) || ! empty( $value['desc'] ) ) {
375 - ?>
376 - <div class="give-setting-tab-header give-setting-tab-header-<?php echo $current_tab; ?>">
377 - <?php if ( ! empty( $value['title'] ) ) : ?>
378 - <h2><?php echo self::get_field_title( $value ); ?></h2>
379 - <hr>
380 - <?php endif; ?>
503 + // Section Titles.
504 + case 'title':
505 + if ( ! empty( $value['title'] ) || ! empty( $value['desc'] ) ) {
506 + ?>
507 + <div class="give-setting-tab-header give-setting-tab-header-<?php echo $current_tab; ?>">
508 + <?php if ( ! empty( $value['title'] ) ) : ?>
509 + <h2><?php echo self::get_field_title( $value ); ?></h2>
510 + <hr>
511 + <?php endif; ?>
381 512
382 - <?php if ( ! empty( $value['desc'] ) ) : ?>
383 - <?php echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); ?>
384 - <?php endif; ?>
385 - </div>
386 - <?php
387 - }
513 + <?php if ( ! empty( $value['desc'] ) ) : ?>
514 + <?php echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); ?>
515 + <?php endif; ?>
516 + </div>
517 + <?php
518 + }
388 519
389 - if ( $value['table_html'] ) {
390 - echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
391 - }
520 + if ( $value['table_html'] ) {
521 + echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
522 + }
392 523
393 - if ( ! empty( $value['id'] ) ) {
524 + if ( ! empty( $value['id'] ) ) {
394 525
395 - /**
396 - * Trigger Action.
397 - *
398 - * Note: action dynamically fire on basis of field id.
399 - *
400 - * @since 1.8
401 - */
402 - do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
403 - }
526 + /**
527 + * Trigger Action.
528 + *
529 + * Note: action dynamically fire on basis of field id.
530 + *
531 + * @since 1.8
532 + */
533 + do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
534 + }
404 535
405 - break;
536 + break;
406 537
407 - // Section Ends.
408 - case 'sectionend':
409 - if ( ! empty( $value['id'] ) ) {
538 + // Section Ends.
539 + case 'sectionend':
540 + if ( ! empty( $value['id'] ) ) {
410 541
411 - /**
412 - * Trigger Action.
413 - *
414 - * Note: action dynamically fire on basis of field id.
415 - *
416 - * @since 1.8
417 - */
418 - do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
419 - }
542 + /**
543 + * Trigger Action.
544 + *
545 + * Note: action dynamically fire on basis of field id.
546 + *
547 + * @since 1.8
548 + */
549 + do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
550 + }
420 551
421 - if ( $value['table_html'] ) {
422 - echo '</table>';
423 - }
552 + if ( $value['table_html'] ) {
553 + echo '</table>';
554 + }
424 555
425 - if ( ! empty( $value['id'] ) ) {
556 + if ( ! empty( $value['id'] ) ) {
426 557
427 - /**
428 - * Trigger Action.
429 - *
430 - * Note: action dynamically fire on basis of field id.
431 - *
432 - * @since 1.8
433 - */
434 - do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
435 - }
558 + /**
559 + * Trigger Action.
560 + *
561 + * Note: action dynamically fire on basis of field id.
562 + *
563 + * @since 1.8
564 + */
565 + do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
566 + }
436 567
437 - break;
568 + break;
438 569
439 - // Standard text inputs and subtypes like 'number'.
440 - case 'colorpicker':
441 - case 'hidden' :
442 - $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
443 - case 'text':
444 - case 'email':
445 - case 'number':
446 - case 'password' :
447 - $type = $value['type'];
448 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
570 + // Standard text inputs and subtypes like 'number'.
571 + case 'colorpicker':
572 + case 'hidden':
573 + $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
574 + case 'text':
575 + case 'email':
576 + case 'number':
577 + case 'password':
578 + $type = $value['type'];
579 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
449 580
450 - // Set default value for repeater field if not any value set yet.
451 - if ( $value['repeat'] && is_string( $option_value ) ) {
452 - $option_value = array( $value['default'] );
453 - }
454 - ?>
455 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
581 + // Set default value for repeater field if not any value set yet.
582 + if ( $value['repeat'] && is_string( $option_value ) ) {
583 + $option_value = [ $value['default'] ];
584 + }
585 + ?>
586 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
587 + <th scope="row" class="titledesc">
588 + <label
589 + for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
590 + </th>
591 + <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
592 + <?php if ( $value['repeat'] ) : ?>
593 + <?php foreach ( $option_value ?: [''] as $index => $field_value ) : ?>
594 + <p>
595 + <input
596 + name="<?php echo esc_attr( $value['id'] ); ?>[]"
597 + type="<?php echo esc_attr( $type ); ?>"
598 + style="<?php echo esc_attr( $value['css'] ); ?>"
599 + value="<?php echo esc_attr( $field_value ); ?>"
600 + class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?> <?php echo esc_attr( $value['id'] ); ?>"
601 + <?php echo implode( ' ', $custom_attributes ); ?>
602 + />
603 + <span class="give-remove-setting-field"
604 + title="<?php esc_html_e( 'Remove setting field', 'give' ); ?>">-</span>
605 + </p>
606 + <?php endforeach; ?>
607 + <a href="#" data-id="<?php echo $value['id']; ?>"
608 + class="give-repeat-setting-field button-secondary"><?php echo $value['repeat_btn_title']; ?></a>
609 + <?php else : ?>
610 + <input
611 + name="<?php echo esc_attr( $value['id'] ); ?>"
612 + id="<?php echo esc_attr( $value['id'] ); ?>"
613 + type="<?php echo esc_attr( $type ); ?>"
614 + style="<?php echo esc_attr( $value['css'] ); ?>"
615 + value="<?php echo esc_attr( $option_value ); ?>"
616 + class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
617 + <?php echo implode( ' ', $custom_attributes ); ?>
618 + />
619 + <?php endif; ?>
620 + <?php echo $description; ?>
621 + </td>
622 + </tr>
623 + <?php
624 + break;
625 +
626 + // Textarea.
627 + case 'textarea':
628 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
629 + $default_attributes = [
630 + 'rows' => 10,
631 + 'cols' => 60,
632 + ];
633 + $textarea_attributes = isset( $value['attributes'] ) ? $value['attributes'] : [];
634 + ?>
635 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
456 636 <th scope="row" class="titledesc">
457 637 <label
458 638 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
459 639 </th>
460 - <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
461 - <?php if ( $value['repeat'] ) : ?>
462 - <?php foreach ( $option_value as $index => $field_value ) : ?>
463 - <p>
464 - <input
465 - name="<?php echo esc_attr( $value['id'] ); ?>[]"
466 - type="<?php echo esc_attr( $type ); ?>"
467 - style="<?php echo esc_attr( $value['css'] ); ?>"
468 - value="<?php echo esc_attr( $field_value ); ?>"
469 - class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?> <?php echo esc_attr( $value['id'] ); ?>"
470 - <?php echo implode( ' ', $custom_attributes ); ?>
471 - />
472 - <span class="give-remove-setting-field"
473 - title="<?php esc_html_e( 'Remove setting field', 'give' ); ?>">-</span>
474 - </p>
475 - <?php endforeach; ?>
476 - <a href="#" data-id="<?php echo $value['id']; ?>"
477 - class="give-repeat-setting-field button-secondary"><?php echo $value['repeat_btn_title']; ?></a>
478 - <?php else : ?>
479 - <input
640 + <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
641 + <textarea
480 642 name="<?php echo esc_attr( $value['id'] ); ?>"
481 643 id="<?php echo esc_attr( $value['id'] ); ?>"
482 - type="<?php echo esc_attr( $type ); ?>"
483 644 style="<?php echo esc_attr( $value['css'] ); ?>"
484 - value="<?php echo esc_attr( $option_value ); ?>"
485 - class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
486 - <?php echo implode( ' ', $custom_attributes ); ?>
487 - />
488 - <?php endif; ?>
645 + class="<?php echo esc_attr( $value['class'] ); ?>"
646 + <?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?>
647 + ><?php echo esc_textarea( $option_value ); ?></textarea>
489 648 <?php echo $description; ?>
490 649 </td>
491 - </tr><?php
492 - break;
650 + </tr>
651 + <?php
652 + break;
493 653
494 - // Textarea.
495 - case 'textarea':
654 + // Code Editor.
655 + case 'code_editor':
656 + $option_value = self::get_option($option_name, $value['id'], $value['default']);
657 + $editor_attributes = isset($value['editor_attributes']) ? $value['editor_attributes'] : [];
496 658
497 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
498 - $default_attributes = array(
499 - 'rows' => 10,
500 - 'cols' => 60
501 - );
502 - $textarea_attributes = isset( $value['attributes'] ) ? $value['attributes'] : array();
503 - ?>
504 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
505 - <th scope="row" class="titledesc">
506 - <label
507 - for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
508 - </th>
509 - <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
510 - <textarea
511 - name="<?php echo esc_attr( $value['id'] ); ?>"
512 - id="<?php echo esc_attr( $value['id'] ); ?>"
513 - style="<?php echo esc_attr( $value['css'] ); ?>"
514 - class="<?php echo esc_attr( $value['class'] ); ?>"
515 - <?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?>
516 - ><?php echo esc_textarea( $option_value ); ?></textarea>
517 - <?php echo $description; ?>
518 - </td>
519 - </tr>
520 - <?php
521 - break;
659 + wp_enqueue_code_editor([
660 + 'type' => $editor_attributes['mode'] ?? 'text/html',
661 + ]);
662 + ?>
663 + <tr valign="top" <?php
664 + echo ! empty($value['wrapper_class']) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
665 + <th scope="row" class="titledesc">
666 + <label
667 + for="<?php
668 + echo esc_attr($value['id']); ?>"><?php
669 + echo self::get_field_title($value); ?></label>
670 + </th>
671 + <td class="give-forminp give-forminp-<?php
672 + echo sanitize_title($value['type']); ?>">
673 + <textarea
674 + name="<?php
675 + echo esc_attr($value['id']); ?>"
676 + id="<?php
677 + echo esc_attr($value['id']); ?>"
678 + style="<?php
679 + echo esc_attr($value['css']); ?>"
680 + class="<?php
681 + echo esc_attr($value['class']); ?>"
682 + ><?php
683 + echo esc_textarea($option_value); ?></textarea>
684 + <?php
685 + echo $description; ?>
522 686
523 - // Select boxes.
524 - case 'select' :
525 - case 'multiselect' :
526 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
687 + <script>
688 + window.addEventListener('DOMContentLoaded', function() {
689 + if (typeof wp.codeEditor === 'undefined') {
690 + return;
691 + }
527 692
528 - /**
529 - * Insert page in option if missing.
530 - *
531 - * Check success_page setting in general settings.
532 - */
533 - if (
534 - isset( $value['attributes'] ) &&
535 - false !== strpos( $value['class'], 'give-select-chosen' ) &&
536 - in_array( 'data-search-type', array_keys( $value['attributes' ] ) ) &&
537 - 'pages' === $value['attributes' ]['data-search-type'] &&
538 - ! in_array( $option_value, array_keys( $value['options'] ) )
539 - ) {
540 - $value['options'][ $option_value ] = get_the_title( $option_value );
541 - }
542 - ?>
543 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
544 - <th scope="row" class="titledesc">
545 - <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
546 - </th>
547 - <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
548 - <select
549 - name="<?php echo esc_attr( $value['id'] ); ?><?php if ( 'multiselect' === $value['type'] ) echo '[]'; ?>"
550 - id="<?php echo esc_attr( $value['id'] ); ?>"
551 - style="<?php echo esc_attr( $value['css'] ); ?>"
552 - class="<?php echo esc_attr( $value['class'] ); ?>"
553 - <?php echo implode( ' ', $custom_attributes ); ?>
554 - <?php echo ( 'multiselect' === $value['type'] ) ? 'multiple="multiple"' : ''; ?>
555 - >
693 + wp.codeEditor.initialize(<?php echo esc_attr($value['id']); ?>, {
694 + codeEditor: {
695 + mode: '<?php echo esc_attr($editor_attributes['mode'] ?? 'text/html'); ?>',
696 + lineNumbers: <?php echo esc_attr(
697 + $editor_attributes['lineNumbers'] ?? true
698 + ); ?>,
699 + lineWrapping: <?php echo esc_attr(
700 + $editor_attributes['lineWrapping'] ?? true
701 + ); ?>,
702 + autoCloseBrackets: <?php echo esc_attr(
703 + $editor_attributes['autoCloseBrackets'] ?? true
704 + ); ?>,
705 + matchBrackets: <?php echo esc_attr(
706 + $editor_attributes['matchBrackets'] ?? true
707 + ); ?>,
708 + indentUnit: <?php echo esc_attr($editor_attributes['indentUnit'] ?? 4); ?>,
709 + tabSize: <?php echo esc_attr($editor_attributes['tabSize'] ?? 4); ?>,
710 + },
711 + });
712 + });
713 + </script>
714 + </td>
715 + </tr>
716 + <?php
717 + break;
556 718
557 - <?php
558 - if ( ! empty( $value['options'] ) ) {
559 - foreach ( $value['options'] as $key => $val ) {
560 - ?>
561 - <option value="<?php echo esc_attr( $key ); ?>" <?php
719 + // Select boxes.
720 + case 'select':
721 + case 'multiselect':
722 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
723 + $setting_name = esc_attr( $value['id'] ) . ( 'multiselect' === $value['type'] ? '[]' : '' );
562 724
563 - if ( is_array( $option_value ) ) {
564 - selected( in_array( $key, $option_value ), true );
565 - } else {
566 - selected( $option_value, $key );
567 - }
725 + /**
726 + * Insert page in option if missing.
727 + *
728 + * Check success_page setting in general settings.
729 + */
730 + if (
731 + isset( $value['attributes'] ) &&
732 + false !== strpos( $value['class'], 'give-select-chosen' ) &&
733 + in_array( 'data-search-type', array_keys( $value['attributes'] ) ) &&
734 + 'pages' === $value['attributes']['data-search-type'] &&
735 + ! in_array( $option_value, array_keys( $value['options'] ) )
736 + ) {
737 + $value['options'][ $option_value ] = get_the_title( $option_value );
738 + }
739 + ?>
740 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
741 + <th scope="row" class="titledesc">
742 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
743 + </th>
744 + <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
745 + <select name="<?php echo $setting_name; ?>"
746 + id="<?php echo esc_attr( $value['id'] ); ?>"
747 + style="<?php echo esc_attr( $value['css'] ); ?>"
748 + class="<?php echo esc_attr( $value['class'] ); ?>"
749 + <?php echo implode( ' ', $custom_attributes ); ?>
750 + <?php echo ( 'multiselect' === $value['type'] ) ? 'multiple="multiple"' : ''; ?>
751 + >
568 752
569 - ?>><?php echo $val ?></option>
570 - <?php
571 - }
753 + <?php
754 + if ( ! empty( $value['options'] ) ) {
755 + foreach ( $value['options'] as $key => $val ) {
756 + ?>
757 + <option value="<?php echo esc_attr( $key ); ?>"
758 + <?php
759 +
760 + if ( is_array( $option_value ) ) {
761 + selected( in_array( $key, $option_value ), true );
762 + } else {
763 + selected( $option_value, $key );
764 + }
765 +
766 + ?>
767 + ><?php echo $val; ?></option>
768 + <?php
572 769 }
770 + }
771 + ?>
772 +
773 + </select> <?php echo $description; ?>
774 + </td>
775 + </tr>
776 + <?php
777 + break;
778 +
779 + // Radio inputs.
780 + case 'radio_inline':
781 + $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
782 + case 'radio':
783 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
784 + ?>
785 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
786 + <th scope="row" class="titledesc">
787 + <label
788 + for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
789 + </th>
790 + <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
791 + <fieldset>
792 + <ul>
793 + <?php
794 + foreach ( $value['options'] as $key => $val ) {
795 + ?>
796 + <li>
797 + <label><input
798 + name="<?php echo esc_attr( $value['id'] ); ?>"
799 + value="<?php echo $key; ?>"
800 + type="radio"
801 + style="<?php echo esc_attr( $value['css'] ); ?>"
802 + <?php echo implode( ' ', $custom_attributes ); ?>
803 + <?php checked( $key, $option_value ); ?>
804 + /> <?php echo $val; ?></label>
805 + </li>
806 + <?php
807 + }
573 808 ?>
809 + <?php echo $description; ?>
810 + </fieldset>
811 + </td>
812 + </tr>
813 + <?php
814 + break;
574 815
575 - </select> <?php echo $description; ?>
816 + // Checkbox input.
817 + case 'checkbox':
818 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
819 + ?>
820 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
821 + <th scope="row" class="titledesc">
822 + <label
823 + for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
824 + </th>
825 + <td class="give-forminp">
826 + <input
827 + name="<?php echo esc_attr( $value['id'] ); ?>"
828 + id="<?php echo esc_attr( $value['id'] ); ?>"
829 + type="checkbox"
830 + class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
831 + value="1"
832 + <?php checked( $option_value, 'on' ); ?>
833 + <?php echo implode( ' ', $custom_attributes ); ?>
834 + />
835 + <?php echo $description; ?>
576 836 </td>
577 - </tr><?php
578 - break;
837 + </tr>
838 + <?php
839 + break;
579 840
580 - // Radio inputs.
581 - case 'radio_inline' :
582 - $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
583 - case 'radio' :
584 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
585 - ?>
586 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
841 + // Multi Checkbox input.
842 + case 'multicheck':
843 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
844 + $option_value = is_array( $option_value ) ? $option_value : [];
845 + ?>
846 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
587 847 <th scope="row" class="titledesc">
588 848 <label
589 849 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
590 850 </th>
591 - <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
851 + <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
592 852 <fieldset>
593 853 <ul>
594 854 <?php
595 855 foreach ( $value['options'] as $key => $val ) {
@@ -594,16 +854,22 @@
594 854 <?php
595 855 foreach ( $value['options'] as $key => $val ) {
596 856 ?>
597 857 <li>
598 - <label><input
599 - name="<?php echo esc_attr( $value['id'] ); ?>"
858 + <label>
859 + <input
860 + name="<?php echo esc_attr( $value['id'] ); ?>[]"
600 861 value="<?php echo $key; ?>"
601 - type="radio"
862 + type="checkbox"
602 863 style="<?php echo esc_attr( $value['css'] ); ?>"
603 864 <?php echo implode( ' ', $custom_attributes ); ?>
604 - <?php checked( $key, $option_value ); ?>
605 - /> <?php echo $val ?></label>
865 + <?php
866 + if ( in_array( $key, $option_value ) ) {
867 + echo 'checked="checked"';
868 + }
869 + ?>
870 + /> <?php echo $val; ?>
871 + </label>
606 872 </li>
607 873 <?php
608 874 }
609 875 ?>
@@ -609,313 +875,221 @@
609 875 ?>
610 876 <?php echo $description; ?>
611 877 </fieldset>
612 878 </td>
613 - </tr><?php
614 - break;
879 + </tr>
880 + <?php
881 + break;
615 882
616 - // Checkbox input.
617 - case 'checkbox' :
618 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
619 - ?>
620 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
621 - <th scope="row" class="titledesc">
622 - <label
623 - for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
624 - </th>
625 - <td class="give-forminp">
626 - <input
627 - name="<?php echo esc_attr( $value['id'] ); ?>"
628 - id="<?php echo esc_attr( $value['id'] ); ?>"
629 - type="checkbox"
630 - class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
631 - value="1"
632 - <?php checked( $option_value, 'on' ); ?>
633 - <?php echo implode( ' ', $custom_attributes ); ?>
634 - />
635 - <?php echo $description; ?>
636 - </td>
637 - </tr>
638 - <?php
639 - break;
883 + // File input field.
884 + case 'file':
885 + case 'media':
886 + $option_value = esc_url( self::get_option( $option_name, $value['id'], $value['default'] ) );
887 + $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
888 + $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
640 889
641 - // Multi Checkbox input.
642 - case 'multicheck' :
643 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
644 - $option_value = is_array( $option_value ) ? $option_value : array();
645 - ?>
646 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
647 - <th scope="row" class="titledesc">
648 - <label
649 - for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
650 - </th>
651 - <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
652 - <fieldset>
653 - <ul>
654 - <?php
655 - foreach ( $value['options'] as $key => $val ) {
656 - ?>
657 - <li>
658 - <label>
659 - <input
660 - name="<?php echo esc_attr( $value['id'] ); ?>[]"
661 - value="<?php echo $key; ?>"
662 - type="checkbox"
663 - style="<?php echo esc_attr( $value['css'] ); ?>"
664 - <?php echo implode( ' ', $custom_attributes ); ?>
665 - <?php if ( in_array( $key, $option_value ) ) {
666 - echo 'checked="checked"';
667 - } ?>
668 - /> <?php echo $val ?>
669 - </label>
670 - </li>
671 - <?php
672 - }
673 - ?>
674 - <?php echo $description; ?>
675 - </fieldset>
676 - </td>
677 - </tr>
678 - <?php
679 - break;
680 -
681 - // File input field.
682 - case 'file' :
683 - case 'media' :
684 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
685 - $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
686 - $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
687 -
688 - $allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' );
689 - $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
690 - $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
691 - $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
692 - ?>
693 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
694 - <th scope="row" class="titledesc">
695 - <label
696 - for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
697 - </th>
698 - <td class="give-forminp">
699 - <div class="give-field-wrap">
700 - <label for="<?php echo $value['id'] ?>">
701 - <input
702 - name="<?php echo esc_attr( $value['id'] ); ?>"
703 - id="<?php echo esc_attr( $value['id'] ); ?>"
704 - type="text"
705 - class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
706 - value="<?php echo $option_value; ?>"
707 - style="<?php echo esc_attr( $value['css'] ); ?>"
708 - <?php echo implode( ' ', $custom_attributes ); ?>
709 - />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
710 - data-fvalue="<?php echo $fvalue; ?>"
711 - data-field-type="<?php echo $value['type']; ?>"
712 - value="<?php echo $button_label; ?>">
713 - <?php echo $description ?>
714 - <div
715 - class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
716 - <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
717 - <img src="<?php echo $preview_image_src; ?>" alt="">
718 - </div>
719 - </label>
720 - </div>
721 - </td>
722 - </tr>
723 - <?php
724 - break;
725 -
726 - // WordPress Editor.
727 - case 'wysiwyg' :
728 - // Get option value.
729 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
730 -
731 - // Get editor settings.
732 - $editor_settings = ! empty( $value['options'] ) ? $value['options'] : array();
733 - ?>
734 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
890 + $allow_media_preview_tags = [ 'jpg', 'jpeg', 'png', 'gif', 'ico' ];
891 + $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
892 + $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
893 + $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
894 + ?>
895 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
735 896 <th scope="row" class="titledesc">
736 897 <label
737 898 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
738 899 </th>
739 900 <td class="give-forminp">
740 - <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
741 - <?php echo $description; ?>
901 + <div class="give-field-wrap">
902 + <label for="<?php echo $value['id']; ?>">
903 + <input
904 + name="<?php echo esc_attr( $value['id'] ); ?>"
905 + id="<?php echo esc_attr( $value['id'] ); ?>"
906 + type="text"
907 + class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
908 + value="<?php echo $option_value; ?>"
909 + style="<?php echo esc_attr( $value['css'] ); ?>"
910 + <?php echo implode( ' ', $custom_attributes ); ?>
911 + />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
912 + data-fvalue="<?php echo $fvalue; ?>"
913 + data-field-type="<?php echo $value['type']; ?>"
914 + value="<?php echo $button_label; ?>">
915 + <?php echo $description; ?>
916 + <div
917 + class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
918 + <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
919 + <img src="<?php echo $preview_image_src; ?>" alt="">
920 + </div>
921 + </label>
922 + </div>
742 923 </td>
743 - </tr><?php
744 - break;
924 + </tr>
925 + <?php
926 + break;
745 927
746 - // Custom: Default gateways setting field.
747 - case 'default_gateway' :
748 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
749 - ?>
750 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
751 - <th scope="row" class="titledesc">
752 - <label
753 - for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
754 - </th>
755 - <td class="give-forminp">
756 - <?php give_default_gateway_callback( $value, $option_value ); ?>
757 - <?php echo $description; ?>
758 - </td>
759 - </tr><?php
760 - break;
928 + // WordPress Editor.
929 + case 'wysiwyg':
930 + // Get option value.
931 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
761 932
762 - // Custom: Email preview buttons field.
763 - case 'email_preview_buttons' :
764 - ?>
765 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
766 - <th scope="row" class="titledesc">
767 - <label
768 - for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
769 - </th>
770 - <td class="give-forminp">
771 - <?php give_email_preview_buttons_callback( $value ); ?>
772 - <?php echo $description; ?>
773 - </td>
774 - </tr><?php
775 - break;
933 + // Get editor settings.
934 + $editor_settings = ! empty( $value['options'] ) ? $value['options'] : [];
935 + ?>
936 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
937 + <th scope="row" class="titledesc">
938 + <label
939 + for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
940 + </th>
941 + <td class="give-forminp">
942 + <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
943 + <?php echo $description; ?>
944 + </td>
945 + </tr>
946 + <?php
947 + break;
776 948
777 - // Custom: API field.
778 - case 'api' :
779 - give_api_callback();
780 - echo $description;
781 - break;
949 + // Custom: Email preview buttons field.
950 + case 'email_preview_buttons':
951 + ?>
952 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
953 + <th scope="row" class="titledesc">
954 + <label
955 + for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
956 + </th>
957 + <td class="give-forminp">
958 + <?php give_email_preview_buttons_callback( $value ); ?>
959 + <?php echo $description; ?>
960 + </td>
961 + </tr>
962 + <?php
963 + break;
782 964
783 - // Custom: Gateway API key.
784 - case 'api_key' :
785 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
786 - $type = ! empty( $option_value ) ? 'password' : 'text';
787 - ?>
788 - <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
965 + // Custom: API field.
966 + case 'api':
967 + give_api_callback();
968 + echo $description;
969 + break;
970 +
971 + // Custom: Gateway API key.
972 + case 'api_key':
973 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
974 + $type = ! empty( $option_value ) ? 'password' : 'text';
975 + ?>
976 + <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
977 + <th scope="row" class="titledesc">
978 + <label
979 + for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
980 + </th>
981 + <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
982 + <input
983 + name="<?php echo esc_attr( $value['id'] ); ?>"
984 + id="<?php echo esc_attr( $value['id'] ); ?>"
985 + type="<?php echo esc_attr( $type ); ?>"
986 + style="<?php echo esc_attr( $value['css'] ); ?>"
987 + value="<?php echo esc_attr( trim( $option_value ) ); ?>"
988 + class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
989 + <?php echo implode( ' ', $custom_attributes ); ?>
990 + /> <?php echo $description; ?>
991 + </td>
992 + </tr>
993 + <?php
994 + break;
995 +
996 + // Note: only for internal use.
997 + case 'chosen':
998 + // Get option value.
999 + $option_value = array_filter( (array) self::get_option( $option_name, $value['id'], $value['default'] ) );
1000 + $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
1001 + $type = '';
1002 + $allow_new_values = ! empty( $value['allow-custom-values'] ) && (bool) $value['allow-custom-values'] ? 'data-allows-new-values="true"' : '';
1003 + $name = give_get_field_name( $value );
1004 + $choices = $value['options'];
1005 + $value['style'] = isset( $value['style'] ) ? $value['style'] : '';
1006 +
1007 + // Set attributes based on multiselect datatype.
1008 + if ( ! empty( $value['data_type'] ) && 'multiselect' === $value['data_type'] ) {
1009 + $type = 'multiple';
1010 + $name .= '[]';
1011 + $option_value = empty( $option_value ) ? [] : $option_value;
1012 + }
1013 +
1014 + // Add dynamically added values to options
1015 + // we can add option dynamically to chosen select field. For example: "Title Prefixes"
1016 + if ( $allow_new_values && $option_value ) {
1017 + $choices = array_merge( array_combine( $option_value, $option_value ), $value['options'] );
1018 + }
1019 + ?>
1020 + <tr valign="top" <?php echo $wrapper_class; ?>>
789 1021 <th scope="row" class="titledesc">
790 - <label
791 - for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
1022 + <label for="<?php
1023 + echo esc_attr($value['id']); ?>"><?php
1024 + echo wp_kses_post(self::get_field_title($value)); ?></label>
792 1025 </th>
793 - <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
794 - <input
795 - name="<?php echo esc_attr( $value['id'] ); ?>"
1026 + <td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
1027 + <select
1028 + class="give-select-chosen give-chosen-settings"
1029 + style="<?php echo esc_attr( $value['style'] ); ?>"
1030 + name="<?php echo esc_attr( $name ); ?>"
796 1031 id="<?php echo esc_attr( $value['id'] ); ?>"
797 - type="<?php echo esc_attr( $type ); ?>"
798 - style="<?php echo esc_attr( $value['css'] ); ?>"
799 - value="<?php echo esc_attr( trim( $option_value ) ); ?>"
800 - class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
801 - <?php echo implode( ' ', $custom_attributes ); ?>
802 - /> <?php echo $description; ?>
1032 + data-placeholder="<?php echo esc_attr__( 'Select Some Options', 'give'); ?>"
1033 + <?php
1034 + echo "{$type} {$allow_new_values}";
1035 + echo implode( ' ', $custom_attributes );
1036 + ?>
1037 + >
1038 + <?php
1039 + foreach ( $choices as $key => $name ) {
1040 + echo sprintf(
1041 + '<option %1$s value="%2$s">%3$s</option>',
1042 + in_array( $key, $option_value ) ? 'selected="selected"' : '',
1043 + esc_attr( $key ),
1044 + $name
1045 + );
1046 + }
1047 + ?>
1048 + </select>
1049 + <?php echo wp_kses_post( $description ); ?>
803 1050 </td>
804 - </tr><?php
805 - break;
1051 + </tr>
1052 + <?php
1053 + break;
806 1054
807 - // Note: only for internal use.
808 - case 'chosen' :
1055 + // Custom: Data field.
1056 + case 'data':
1057 + include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
809 1058
810 - // Get option value.
811 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
812 - $option_value = is_array( $option_value ) ? array_fill_keys( $option_value, 'selected' ) : $option_value;
813 - $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
814 - $type = '';
815 - $allow_new_values = '';
816 - $name = give_get_field_name( $value );
1059 + echo $description;
1060 + break;
817 1061
818 - // Set attributes based on multiselect datatype.
819 - if ( 'multiselect' === $value['data_type'] ) {
820 - $type = 'multiple';
821 - $allow_new_values = 'data-allows-new-values="true"';
822 - $name = $name . '[]';
823 - $option_value = empty( $option_value ) ? array() : $option_value;
824 - }
1062 + // Custom: Give Docs Link field type.
1063 + case 'give_docs_link':
1064 + $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
1065 + ?>
1066 + <tr valign="top" <?php echo esc_html( $wrapper_class ); ?>>
1067 + <td class="give-docs-link" colspan="2">
1068 + <p class="give-docs-link">
1069 + <a href="<?php echo esc_url( $value['url'] ); ?>" target="_blank">
1070 + <?php
1071 + echo sprintf(
1072 + /* translators: %s Title */
1073 + esc_html__( 'Need Help? See docs on "%s"', 'give' ),
1074 + esc_html( $value['title'] )
1075 + );
1076 + ?>
1077 + <span class="dashicons dashicons-editor-help"></span>
1078 + </a>
1079 + </p>
1080 + </td>
1081 + </tr>
1082 + <?php
1083 + break;
825 1084
826 - $title_prefixes_value = ( is_array( $option_value ) && count( $option_value ) > 0 ) ?
827 - array_merge( $value['options'], $option_value ) :
828 - $value['options'];
829 -
830 - ?>
831 - <tr valign="top" <?php echo $wrapper_class; ?>>
832 - <th scope="row" class="titledesc">
833 - <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_attr( self::get_field_title( $value ) ); ?></label>
834 - </th>
835 - <td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
836 - <select
837 - class="give-select-chosen give-chosen-settings"
838 - style="<?php echo esc_attr( $value['style'] ); ?>"
839 - name="<?php echo esc_attr( $name ); ?>"
840 - id="<?php echo esc_attr( $value['id'] ); ?>"
841 - <?php
842 - echo "{$type} {$allow_new_values}";
843 - echo implode( ' ', $custom_attributes );
844 - ?>
845 - >
846 - <?php
847 - if ( is_array( $title_prefixes_value ) && count( $title_prefixes_value ) > 0 ) {
848 - foreach ( $title_prefixes_value as $key => $item_value ) {
849 - echo sprintf(
850 - '<option %1$s value="%2$s">%2$s</option>',
851 - ( 'selected' === $item_value ) ? 'selected="selected"' : '',
852 - esc_attr( $key )
853 - );
854 - }
855 - }
856 - ?>
857 - </select>
858 - <?php echo wp_kses_post( $description ); ?>
859 - </td>
860 - </tr>
861 - <?php
862 - break;
863 -
864 - // Custom: Log field.
865 - case 'logs' :
866 -
867 - // Get current section.
868 - $current_section = $_GET['section'] = give_get_current_setting_section();
869 -
870 - /**
871 - * Fires for each tab of logs view.
872 - *
873 - * @since 1.0
874 - */
875 - do_action( "give_logs_view_{$current_section}" );
876 -
877 - echo $description;
878 - break;
879 -
880 - // Custom: Data field.
881 - case 'data' :
882 -
883 - include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
884 -
885 - echo $description;
886 - break;
887 -
888 - // Custom: Give Docs Link field type.
889 - case 'give_docs_link' :
890 - $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
891 - ?>
892 - <tr valign="top" <?php echo esc_html( $wrapper_class ); ?>>
893 - <td class="give-docs-link" colspan="2">
894 - <p class="give-docs-link">
895 - <a href="<?php echo esc_url( $value['url'] ); ?>" target="_blank">
896 - <?php
897 - echo sprintf(
898 - /* translators: %s Title */
899 - esc_html__( 'Need Help? See docs on "%s"', 'give' ),
900 - esc_html( $value['title'] )
901 - );
902 - ?>
903 - <span class="dashicons dashicons-editor-help"></span>
904 - </a>
905 - </p>
906 - </td>
907 - </tr><?php
908 - break;
909 -
910 - // Default: run an action
911 - // You can add or handle your custom field action.
912 - default:
913 - // Get option value.
914 - $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
915 - do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
916 - break;
917 - }
1085 + // Default: run an action
1086 + // You can add or handle your custom field action.
1087 + default:
1088 + // Get option value.
1089 + $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
1090 + do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
1091 + break;
918 1092 }
919 1093 }
920 1094
921 1095 /**
@@ -968,8 +1142,9 @@
968 1142 * Save admin fields.
969 1143 *
970 1144 * Loops though the give options array and outputs each field.
971 1145 *
1146 + * @since 4.1.0 Added validation for code editor field.
972 1147 * @since 1.8
973 1148 *
974 1149 * @param array $options Options array to output
975 1150 * @param string $option_name Option name to save output. If empty then option will be store in there own option name i.e option id.
@@ -976,14 +1151,42 @@
976 1151 *
977 1152 * @return bool
978 1153 */
979 1154 public static function save_fields( $options, $option_name = '' ) {
980 - if ( empty( $_POST ) ) {
1155 +
1156 + // Fetch form posted super global data.
1157 + $post_data = give_clean( $_POST );
1158 +
1159 + // Bailout, if posted data doesn't exists.
1160 + if ( empty( $post_data ) ) {
981 1161 return false;
982 1162 }
983 1163
1164 + $new_options = [];
1165 + $options_keys = array_keys( $options );
1166 + $is_vertical_tabs = is_array( $options_keys ) && count( $options_keys ) && ! is_numeric( $options_keys[0] );
1167 +
1168 + if ( $is_vertical_tabs ) {
1169 +
1170 + // Loop through each vertical tabs related field options to destructure into single array.
1171 + foreach ( $options as $option ) {
1172 + // Get option from a sub group (if any).
1173 + if ( ! is_numeric( array_keys( $option )[0] ) ) {
1174 + foreach ( $option as $subGroup ) {
1175 + $new_options = array_merge( $new_options, $subGroup );
1176 + }
1177 + continue;
1178 + }
1179 +
1180 + $new_options = array_merge( $new_options, $option );
1181 + }
1182 +
1183 + // Assign new field options.
1184 + $options = $new_options;
1185 + }
1186 +
984 1187 // Options to update will be stored here and saved later.
985 - $update_options = array();
1188 + $update_options = [];
986 1189
987 1190 // Loop options and get values to save.
988 1191 foreach ( $options as $option ) {
989 1192 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
@@ -1003,20 +1206,21 @@
1003 1206 }
1004 1207
1005 1208 // Format the value based on option type.
1006 1209 switch ( $option['type'] ) {
1007 - case 'checkbox' :
1210 + case 'checkbox':
1008 1211 $value = is_null( $raw_value ) ? '' : 'on';
1009 1212 break;
1010 - case 'wysiwyg' :
1011 - case 'textarea' :
1213 + case 'wysiwyg':
1214 + case 'textarea':
1215 + case 'code_editor':
1012 1216 $value = wp_kses_post( trim( $raw_value ) );
1013 1217 break;
1014 - case 'multiselect' :
1015 - case 'chosen' :
1218 + case 'multiselect':
1219 + case 'chosen':
1016 1220 $value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
1017 1221 break;
1018 - default :
1222 + default:
1019 1223 $value = give_clean( $raw_value );
1020 1224 break;
1021 1225 }
1022 1226
@@ -1040,12 +1244,12 @@
1040 1244
1041 1245 // Check if option is an array and handle that differently to single values.
1042 1246 if ( $field_option_name && $setting_name ) {
1043 1247 if ( ! isset( $update_options[ $field_option_name ] ) ) {
1044 - $update_options[ $field_option_name ] = get_option( $field_option_name, array() );
1248 + $update_options[ $field_option_name ] = get_option( $field_option_name, [] );
1045 1249 }
1046 1250 if ( ! is_array( $update_options[ $field_option_name ] ) ) {
1047 - $update_options[ $field_option_name ] = array();
1251 + $update_options[ $field_option_name ] = [];
1048 1252 }
1049 1253 $update_options[ $field_option_name ][ $setting_name ] = $value;
1050 1254 } else {
1051 1255 $update_options[ $field_option_name ] = $value;
@@ -1066,9 +1270,9 @@
1066 1270 */
1067 1271 do_action( "give_save_option_{$name}", $value, $name );
1068 1272 }
1069 1273 } else {
1070 - $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : array();
1274 + $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : [];
1071 1275 $update_options = array_merge( $old_options, $update_options );
1072 1276
1073 1277 update_option( $option_name, $update_options, false );
1074 1278
@@ -1110,9 +1314,18 @@
1110 1314 */
1111 1315 public static function is_setting_page( $tab = '', $section = '' ) {
1112 1316 $is_setting_page = false;
1113 1317
1114 - if( ! is_admin() ) {
1318 + // Are we accessing admin?
1319 + if ( ! is_admin() ) {
1320 + return $is_setting_page;
1321 + }
1322 +
1323 + // Are we accessing any give page?
1324 + if (
1325 + ! isset( $_GET['post_type'], $_GET['page'] )
1326 + || 'give_forms' !== give_clean( $_GET['post_type'] )
1327 + ) {
1115 1328 return $is_setting_page;
1116 1329 }
1117 1330
1118 1331 // Check fo setting tab.