| @@ -1,39 +1,71 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +// Exit if accessed directly. | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 2 | 8 | /** |
| 3 | 9 | * Display select field. |
| 4 | 10 | * |
| 5 | 11 | * @author David Bisset |
| 6 | 12 | * @package Charitable/Admin View/Settings |
| 7 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 13 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 14 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 15 | * @since 1.0.0 |
| 10 | - * @version 1.6.25 | |
| 16 | + * @version 1.8.8.6 | |
| 11 | 17 | */ |
| 12 | 18 | |
| 13 | -$value = charitable_get_option( $view_args['key'] ); | |
| 19 | +// Determine if this is a tools field or settings field. | |
| 20 | +$charitable_is_tools_field = charitable_is_tools_view(); | |
| 14 | 21 | |
| 15 | -if ( false === $value ) { | |
| 16 | - $value = isset( $view_args['default'] ) ? $view_args['default'] : ''; | |
| 22 | +if ( $charitable_is_tools_field ) { | |
| 23 | + $charitable_tools_options = get_option( 'charitable_tools', array() ); | |
| 24 | + $charitable_value = ''; | |
| 25 | + if ( isset( $view_args['key'] ) && is_array( $view_args['key'] ) ) { | |
| 26 | + $charitable_value_path = $charitable_tools_options; | |
| 27 | + foreach ( $view_args['key'] as $charitable_key_part ) { | |
| 28 | + if ( isset( $charitable_value_path[ $charitable_key_part ] ) ) { | |
| 29 | + $charitable_value_path = $charitable_value_path[ $charitable_key_part ]; | |
| 30 | + } else { | |
| 31 | + $charitable_value_path = false; | |
| 32 | + break; | |
| 33 | + } | |
| 34 | + } | |
| 35 | + $charitable_value = $charitable_value_path; | |
| 36 | + } | |
| 37 | + if ( false === $charitable_value ) { | |
| 38 | + $charitable_value = isset( $view_args['default'] ) ? $view_args['default'] : ''; | |
| 39 | + } | |
| 40 | + $charitable_field_id = sprintf( 'charitable_tools_%s', implode( '_', $view_args['key'] ) ); | |
| 41 | + $charitable_field_name = sprintf( 'charitable_tools[%s]', $view_args['name'] ); | |
| 42 | +} else { | |
| 43 | + $charitable_value = charitable_get_option( $view_args['key'] ); | |
| 44 | + if ( false === $charitable_value ) { | |
| 45 | + $charitable_value = isset( $view_args['default'] ) ? $view_args['default'] : ''; | |
| 46 | + } | |
| 47 | + $charitable_field_id = sprintf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); | |
| 48 | + $charitable_field_name = sprintf( 'charitable_settings[%s]', $view_args['name'] ); | |
| 17 | 49 | } |
| 18 | 50 | ?> |
| 19 | -<select id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); ?>" | |
| 20 | - name="<?php printf( 'charitable_settings[%s]', $view_args['name'] ); ?>" | |
| 51 | +<select id="<?php echo esc_attr( $charitable_field_id ); ?>" | |
| 52 | + name="<?php echo esc_attr( $charitable_field_name ); ?>" | |
| 21 | 53 | class="<?php echo esc_attr( $view_args['classes'] ); ?>" |
| 22 | - <?php echo charitable_get_arbitrary_attributes( $view_args ); ?> | |
| 54 | + <?php echo charitable_get_arbitrary_attributes( $view_args ); // phpcs:ignore ?> | |
| 23 | 55 | > |
| 24 | 56 | <?php |
| 25 | - foreach ( $view_args['options'] as $key => $option ) : | |
| 26 | - if ( is_array( $option ) ) : | |
| 27 | - $label = isset( $option['label'] ) ? $option['label'] : ''; | |
| 57 | + foreach ( $view_args['options'] as $charitable_key => $charitable_option ) : | |
| 58 | + if ( is_array( $charitable_option ) ) : | |
| 59 | + $charitable_label = isset( $charitable_option['label'] ) ? $charitable_option['label'] : ''; | |
| 28 | 60 | ?> |
| 29 | - <optgroup label="<?php echo $label; ?>"> | |
| 30 | - <?php foreach ( $option['options'] as $k => $opt ) : ?> | |
| 31 | - <option value="<?php echo $k; ?>" <?php selected( $k, $value ); ?>><?php echo $opt; ?></option> | |
| 61 | + <optgroup label="<?php echo wp_kses_post( $charitable_label ); ?>"> | |
| 62 | + <?php foreach ( $charitable_option['options'] as $charitable_k => $charitable_opt ) : ?> | |
| 63 | + <option value="<?php echo esc_attr( $charitable_k ); ?>" <?php selected( $charitable_k, $charitable_value ); ?>><?php echo esc_html( $charitable_opt ); ?></option> | |
| 32 | 64 | <?php endforeach ?> |
| 33 | 65 | </optgroup> |
| 34 | 66 | <?php else : ?> |
| 35 | - <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $value ); ?>><?php echo $option; ?></option> | |
| 67 | + <option value="<?php echo esc_attr( $charitable_key ); ?>" <?php selected( $charitable_key, $charitable_value ); ?>><?php echo $charitable_option; // phpcs:ignore ?></option> | |
| 36 | 68 | <?php |
| 37 | 69 | endif; |
| 38 | 70 | endforeach |
| 39 | 71 | ?> |
| @@ -38,7 +70,7 @@ | ||
| 38 | 70 | endforeach |
| 39 | 71 | ?> |
| 40 | 72 | </select> |
| 41 | 73 | <?php if ( isset( $view_args['help'] ) ) : ?> |
| 42 | - <div class="charitable-help"><?php echo $view_args['help']; ?></div> | |
| 74 | + <div class="charitable-help"><?php echo $view_args['help']; // phpcs:ignore ?></div> | |
| 43 | 75 | <?php |
| 44 | 76 | endif; |