| @@ -1,14 +1,22 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +// Exit if accessed directly. | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 2 | 8 | /** |
| 3 | 9 | * The template used to display checkbox form fields. |
| 4 | 10 | * |
| 5 | 11 | * Override this template by copying it to yourtheme/charitable/form-fields/checkbox.php |
| 6 | 12 | * |
| 7 | - * @author Studio 164a | |
| 13 | + * @author WP Charitable LLC | |
| 8 | 14 | * @package Charitable/Templates/Form Fields |
| 9 | 15 | * @since 1.0.0 |
| 10 | 16 | * @version 1.2.0 |
| 17 | + * @version 1.8.6.1 Added description. | |
| 18 | + * @version 1.8.8.6 | |
| 11 | 19 | */ |
| 12 | 20 | |
| 13 | 21 | if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) { |
| 14 | 22 | return; |
| @@ -13,37 +21,45 @@ | ||
| 13 | 21 | if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) { |
| 14 | 22 | return; |
| 15 | 23 | } |
| 16 | 24 | |
| 17 | -$form = $view_args['form']; | |
| 18 | -$field = $view_args['field']; | |
| 19 | -$classes = $view_args['classes']; | |
| 20 | -$is_required = isset( $field['required'] ) ? $field['required'] : false; | |
| 21 | -$value = isset( $field['value'] ) ? esc_attr( $field['value'] ) : '1'; | |
| 25 | +$charitable_form = $view_args['form']; | |
| 26 | +$charitable_field = $view_args['field']; | |
| 27 | +$charitable_classes = $view_args['classes']; | |
| 28 | +$charitable_is_required = isset( $charitable_field['required'] ) ? $charitable_field['required'] : false; | |
| 29 | +$charitable_value = isset( $charitable_field['value'] ) ? esc_attr( $charitable_field['value'] ) : '1'; | |
| 22 | 30 | |
| 23 | -if ( isset( $field['checked'] ) ) { | |
| 24 | - $checked = $field['checked']; | |
| 31 | +if ( isset( $charitable_field['checked'] ) ) { | |
| 32 | + $charitable_checked = $charitable_field['checked']; | |
| 25 | 33 | } else { |
| 26 | - $checked = isset( $field['default'] ) ? $field['default'] : 0; | |
| 34 | + $charitable_checked = isset( $charitable_field['default'] ) ? $charitable_field['default'] : 0; | |
| 27 | 35 | } |
| 28 | 36 | ?> |
| 29 | -<div id="charitable_field_<?php echo $field['key']; ?>" class="<?php echo $classes; ?>"> | |
| 37 | +<div id="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>" class="<?php echo esc_attr( $charitable_classes ); ?>"> | |
| 30 | 38 | <input |
| 31 | 39 | type="checkbox" |
| 32 | - name="<?php echo $field['key']; ?>" | |
| 33 | - value="<?php echo $value; ?>" | |
| 34 | - id="charitable_field_<?php echo $field['key']; ?>_element" | |
| 35 | - <?php checked( $checked ); ?> | |
| 36 | - <?php echo charitable_get_arbitrary_attributes( $field ); ?> | |
| 40 | + name="<?php echo esc_attr( $charitable_field['key'] ); ?>" | |
| 41 | + value="<?php echo esc_attr( $charitable_value ); ?>" | |
| 42 | + id="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>_element" | |
| 43 | + <?php checked( $charitable_checked ); ?> | |
| 44 | + <?php echo charitable_get_arbitrary_attributes( $charitable_field ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 37 | 45 | /> |
| 38 | - <?php if ( isset( $field['label'] ) ) : ?> | |
| 39 | - <label for="charitable_field_<?php echo $field['key']; ?>_element"> | |
| 40 | - <?php echo $field['label']; ?> | |
| 41 | - <?php if ( $is_required ) : ?> | |
| 42 | - <abbr class="required" title="required">*</abbr> | |
| 46 | + <?php if ( isset( $charitable_field['label'] ) ) : ?> | |
| 47 | + <label for="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>_element"> | |
| 48 | + <?php echo wp_kses_post( $charitable_field['label'] ); ?> | |
| 49 | + <?php if ( $charitable_is_required ) : ?> | |
| 50 | + <abbr class="required" title="<?php esc_html_e( 'Required', 'charitable' ); ?>">*</abbr> | |
| 43 | 51 | <?php endif ?> |
| 44 | 52 | </label> |
| 45 | 53 | <?php endif ?> |
| 46 | - <?php if ( isset( $field['help'] ) ) : ?> | |
| 47 | - <p class="charitable-field-help"><?php echo $field['help']; ?></p> | |
| 54 | + <?php if ( isset( $charitable_field['help'] ) ) : ?> | |
| 55 | + <p class="charitable-field-help"><?php echo wp_kses_post( $charitable_field['help'] ); ?></p> | |
| 48 | 56 | <?php endif ?> |
| 49 | -</div> | |
| 57 | + <?php | |
| 58 | + | |
| 59 | + // If there is a description, add it after the input. | |
| 60 | + if ( isset( $charitable_field['description'] ) && ! empty( $charitable_field['description'] ) ) { | |
| 61 | + echo '<p class="charitable-field-description">' . wp_kses_post( $charitable_field['description'] ) . '</p>'; | |
| 62 | + } | |
| 63 | + | |
| 64 | + ?> | |
| 65 | +</div> | |