| @@ -1,56 +1,74 @@ | ||
| 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 | +$charitable_value = charitable_get_option( $view_args['key'] ); | |
| 14 | 20 | |
| 15 | -if ( false === $value ) { | |
| 16 | - $value = isset( $view_args['default'] ) ? $view_args['default'] : ''; | |
| 21 | +if ( false === $charitable_value ) { | |
| 22 | + $charitable_value = isset( $view_args['default'] ) ? $view_args['default'] : ''; | |
| 17 | 23 | } |
| 18 | 24 | |
| 19 | -$form_action_url = isset( $view_args['form_action_url'] ) ? $view_args['form_action_url'] : ''; | |
| 20 | -$form_action_method = isset( $view_args['form_action_method'] ) ? $view_args['form_action_method'] : 'POST'; | |
| 21 | -$button_label = isset( $view_args['button_label'] ) ? $view_args['button_label'] : 'Submit'; | |
| 22 | -$nonce_action_name = isset( $view_args['nonce_action_name'] ) ? $view_args['nonce_action_name'] : 'wpcharitable-action'; | |
| 23 | -$nonce_field_name = isset( $view_args['nonce_field_name'] ) ? $view_args['nonce_field_name'] : false; | |
| 25 | +$charitable_form_action_url = isset( $view_args['form_action_url'] ) ? $view_args['form_action_url'] : ''; | |
| 26 | +$charitable_form_action_method = isset( $view_args['form_action_method'] ) ? $view_args['form_action_method'] : 'POST'; | |
| 27 | +$charitable_button_label = isset( $view_args['button_label'] ) ? $view_args['button_label'] : 'Submit'; | |
| 28 | +$charitable_nonce_action_name = isset( $view_args['nonce_action_name'] ) ? $view_args['nonce_action_name'] : 'wpcharitable-action'; | |
| 29 | +$charitable_nonce_field_name = isset( $view_args['nonce_field_name'] ) ? $view_args['nonce_field_name'] : false; | |
| 30 | +$charitable_error_message = false; | |
| 31 | + | |
| 32 | +// determine if the fields should be shown, based on what we are trying to do with them. | |
| 33 | +if ( isset( $view_args['nonce_action_name'] ) && 'export_campaign' === $view_args['nonce_action_name'] && is_array( $view_args['options'] ) && 0 === count( $view_args['options'] ) ) { | |
| 34 | + $charitable_error_message = '<strong>' . __( 'You have no campaigns to export.', 'charitable' ) . '</strong>'; | |
| 35 | +} elseif ( isset( $view_args['nonce_action_name'] ) && 'export_donations_from_campaign' === $view_args['nonce_action_name'] && is_array( $view_args['options'] ) && 0 === count( $view_args['options'] ) ) { | |
| 36 | + $charitable_error_message = '<strong>' . __( 'You have no donations to export.', 'charitable' ) . '</strong>'; | |
| 37 | +} | |
| 24 | 38 | ?> |
| 25 | -<form action="<?php echo $form_action_url; ?>" method="<?php echo $form_action_method; ?>"> | |
| 39 | +<form action="<?php echo esc_url( $charitable_form_action_url ); ?>" method="<?php echo esc_attr( $charitable_form_action_method ); ?>"> | |
| 26 | 40 | |
| 27 | -<?php wp_nonce_field( $nonce_action_name, $nonce_field_name ); ?> | |
| 41 | + <?php wp_nonce_field( $charitable_nonce_action_name, $charitable_nonce_field_name ); ?> | |
| 28 | 42 | |
| 29 | -<select id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); ?>" | |
| 30 | - name="<?php printf( 'charitable_settings[%s]', $view_args['name'] ); ?>" | |
| 31 | - class="<?php echo esc_attr( $view_args['classes'] ); ?>" | |
| 32 | - <?php echo charitable_get_arbitrary_attributes( $view_args ); ?> | |
| 33 | - > | |
| 34 | - <?php | |
| 35 | - foreach ( $view_args['options'] as $key => $option ) : | |
| 36 | - if ( is_array( $option ) ) : | |
| 37 | - $label = isset( $option['label'] ) ? $option['label'] : ''; | |
| 43 | + <?php if ( ! $charitable_error_message ) { ?> | |
| 44 | + <select id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); // phpcs:ignore ?>" | |
| 45 | + name="<?php printf( 'charitable_settings[%s]', $view_args['name'] ); // phpcs:ignore ?>" | |
| 46 | + class="<?php echo esc_attr( $view_args['classes'] ); ?>" | |
| 47 | + <?php echo charitable_get_arbitrary_attributes( $view_args ); // phpcs:ignore ?> | |
| 48 | + > | |
| 49 | + <?php | |
| 50 | + foreach ( $view_args['options'] as $charitable_key => $charitable_option ) : | |
| 51 | + if ( is_array( $charitable_option ) ) : | |
| 52 | + $charitable_label = isset( $charitable_option['label'] ) ? $charitable_option['label'] : ''; | |
| 53 | + ?> | |
| 54 | + <optgroup label="<?php echo esc_html( $charitable_label ); ?>"> | |
| 55 | + <?php foreach ( $charitable_option['options'] as $charitable_k => $charitable_opt ) : ?> | |
| 56 | + <option value="<?php echo esc_attr( $charitable_k ); ?>" <?php selected( $charitable_k, $charitable_value ); ?>><?php echo esc_html( $charitable_opt ); ?></option> | |
| 57 | + <?php endforeach ?> | |
| 58 | + </optgroup> | |
| 59 | + <?php else : ?> | |
| 60 | + <option value="<?php echo esc_attr( $charitable_key ); ?>" <?php selected( $charitable_key, $charitable_value ); ?>><?php echo $charitable_option; // phpcs:ignore ?></option> | |
| 61 | + <?php | |
| 62 | + endif; | |
| 63 | + endforeach | |
| 38 | 64 | ?> |
| 39 | - <optgroup label="<?php echo $label; ?>"> | |
| 40 | - <?php foreach ( $option['options'] as $k => $opt ) : ?> | |
| 41 | - <option value="<?php echo $k; ?>" <?php selected( $k, $value ); ?>><?php echo $opt; ?></option> | |
| 42 | - <?php endforeach ?> | |
| 43 | - </optgroup> | |
| 44 | - <?php else : ?> | |
| 45 | - <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $value ); ?>><?php echo $option; ?></option> | |
| 46 | - <?php | |
| 47 | - endif; | |
| 48 | - endforeach | |
| 49 | - ?> | |
| 50 | -</select> | |
| 51 | -<input class="button button-primary" type="submit" value="<?php echo $button_label; ?>"> | |
| 65 | + </select> | |
| 66 | + <input class="button button-primary" type="submit" value="<?php echo esc_html( $charitable_button_label ); ?>"> | |
| 67 | + <?php } else { ?> | |
| 68 | + <p><?php echo $charitable_error_message; // phpcs:ignore ?></p> | |
| 69 | + <?php } ?> | |
| 52 | 70 | </form> |
| 53 | 71 | <?php if ( isset( $view_args['help'] ) ) : ?> |
| 54 | - <div class="charitable-help"><?php echo $view_args['help']; ?></div> | |
| 72 | + <div class="charitable-help"><?php echo $view_args['help']; // phpcs:ignore ?></div> | |
| 55 | 73 | <?php |
| 56 | 74 | endif; |