| @@ -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', [] ); | |
| 76 | + self::$settings = (array)apply_filters( self::$setting_filter_prefix . '_get_settings_pages', [] ); | |
| 76 | 77 | |
| 77 | 78 | return self::$settings; |
| 78 | 79 | } |
| 79 | 80 | |
| @@ -314,18 +315,19 @@ | ||
| 314 | 315 | /** |
| 315 | 316 | * Output admin fields. |
| 316 | 317 | * |
| 317 | 318 | * Loops though the give options array and outputs each field. |
| 318 | - * | |
| 319 | - * @todo Refactor this function | |
| 320 | - * | |
| 319 | + * | |
| 320 | + * @since 4.1.0 Display tabs only when there is more than one group available | |
| 321 | 321 | * @since 1.8 |
| 322 | 322 | * @access public |
| 323 | + * | |
| 324 | + * @param array $sections Opens array to output. | |
| 325 | + * @param string $option_name Opens array to output. | |
| 323 | 326 | * |
| 324 | - * @param array $sections Opens array to output. | |
| 325 | - * @param string $option_name Opens array to output. | |
| 326 | - * | |
| 327 | 327 | * @return void |
| 328 | + * @todo Refactor this function | |
| 329 | + * | |
| 328 | 330 | */ |
| 329 | 331 | public static function output_fields( $sections, $option_name = '' ) { |
| 330 | 332 | |
| 331 | 333 | $current_page = give_get_current_setting_page(); |
| @@ -336,27 +338,31 @@ | ||
| 336 | 338 | if ( $groups ) { |
| 337 | 339 | $defaultGroup = current( array_keys( $groups ) ); |
| 338 | 340 | ?> |
| 339 | 341 | <div class="give-settings-section-content"> |
| 340 | - <div class="give-settings-section-group-menu"> | |
| 341 | - <ul> | |
| 342 | - <?php | |
| 343 | - foreach ( $groups as $slug => $group ) { | |
| 344 | - $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $defaultGroup; | |
| 345 | - $active_class = ( $slug === $current_group ) ? 'active' : ''; | |
| 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' : ''; | |
| 346 | 350 | |
| 347 | - echo sprintf( | |
| 348 | - '<li><a class="%1$s" href="%2$s" data-group="%3$s">%4$s</a></li>', | |
| 349 | - esc_html( $active_class ), | |
| 350 | - esc_url( admin_url( "edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}§ion={$current_section}&group={$slug}" ) ), | |
| 351 | - esc_html( $slug ), | |
| 352 | - esc_html( $group ) | |
| 353 | - ); | |
| 354 | - } | |
| 355 | - ?> | |
| 356 | - </ul> | |
| 357 | - </div> | |
| 358 | - <div class="give-settings-section-group-content"> | |
| 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}§ion={$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"> | |
| 359 | 365 | <?php |
| 360 | 366 | foreach ( $sections as $group => $fields ) { |
| 361 | 367 | $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $defaultGroup; |
| 362 | 368 | $hide_class = $group !== $current_group ? 'give-hidden' : ''; |
| @@ -444,10 +450,10 @@ | ||
| 444 | 450 | |
| 445 | 451 | /** |
| 446 | 452 | * This function will help you prepare the admin settings field. |
| 447 | 453 | * |
| 454 | + * @since 4.1.0 Added support for code editor field. | |
| 448 | 455 | * @since 2.5.5 |
| 449 | - * @access public | |
| 450 | 456 | * |
| 451 | 457 | * @param array $value Settings Field Array. |
| 452 | 458 | * @param string $option_name Option Name. |
| 453 | 459 | * |
| @@ -644,8 +650,73 @@ | ||
| 644 | 650 | </tr> |
| 645 | 651 | <?php |
| 646 | 652 | break; |
| 647 | 653 | |
| 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'] : []; | |
| 658 | + | |
| 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; ?> | |
| 686 | + | |
| 687 | + <script> | |
| 688 | + window.addEventListener('DOMContentLoaded', function() { | |
| 689 | + if (typeof wp.codeEditor === 'undefined') { | |
| 690 | + return; | |
| 691 | + } | |
| 692 | + | |
| 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; | |
| 718 | + | |
| 648 | 719 | // Select boxes. |
| 649 | 720 | case 'select': |
| 650 | 721 | case 'multiselect': |
| 651 | 722 | $option_value = self::get_option( $option_name, $value['id'], $value['default'] ); |
| @@ -947,9 +1018,11 @@ | ||
| 947 | 1018 | } |
| 948 | 1019 | ?> |
| 949 | 1020 | <tr valign="top" <?php echo $wrapper_class; ?>> |
| 950 | 1021 | <th scope="row" class="titledesc"> |
| 951 | - <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_attr( 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> | |
| 952 | 1025 | </th> |
| 953 | 1026 | <td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>"> |
| 954 | 1027 | <select |
| 955 | 1028 | class="give-select-chosen give-chosen-settings" |
| @@ -955,8 +1028,9 @@ | ||
| 955 | 1028 | class="give-select-chosen give-chosen-settings" |
| 956 | 1029 | style="<?php echo esc_attr( $value['style'] ); ?>" |
| 957 | 1030 | name="<?php echo esc_attr( $name ); ?>" |
| 958 | 1031 | id="<?php echo esc_attr( $value['id'] ); ?>" |
| 1032 | + data-placeholder="<?php echo esc_attr__( 'Select Some Options', 'give'); ?>" | |
| 959 | 1033 | <?php |
| 960 | 1034 | echo "{$type} {$allow_new_values}"; |
| 961 | 1035 | echo implode( ' ', $custom_attributes ); |
| 962 | 1036 | ?> |
| @@ -1068,8 +1142,9 @@ | ||
| 1068 | 1142 | * Save admin fields. |
| 1069 | 1143 | * |
| 1070 | 1144 | * Loops though the give options array and outputs each field. |
| 1071 | 1145 | * |
| 1146 | + * @since 4.1.0 Added validation for code editor field. | |
| 1072 | 1147 | * @since 1.8 |
| 1073 | 1148 | * |
| 1074 | 1149 | * @param array $options Options array to output |
| 1075 | 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. |
| @@ -1136,8 +1211,9 @@ | ||
| 1136 | 1211 | $value = is_null( $raw_value ) ? '' : 'on'; |
| 1137 | 1212 | break; |
| 1138 | 1213 | case 'wysiwyg': |
| 1139 | 1214 | case 'textarea': |
| 1215 | + case 'code_editor': | |
| 1140 | 1216 | $value = wp_kses_post( trim( $raw_value ) ); |
| 1141 | 1217 | break; |
| 1142 | 1218 | case 'multiselect': |
| 1143 | 1219 | case 'chosen': |