| @@ -1,12 +1,20 @@ | ||
| 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 datepicker form fields. |
| 4 | 10 | * |
| 5 | - * @author Studio 164a | |
| 11 | + * @author WP Charitable LLC | |
| 6 | 12 | * @package Charitable/Templates/Form Fields |
| 7 | 13 | * @since 1.0.0 |
| 8 | - * @version 1.0.0 | |
| 14 | + * @version 1.6.40 | |
| 15 | + * @version 1.8.6.1 Added description output. | |
| 16 | + * @version 1.8.8.6 | |
| 9 | 17 | */ |
| 10 | 18 | |
| 11 | 19 | if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) { |
| 12 | 20 | return; |
| @@ -11,28 +19,34 @@ | ||
| 11 | 19 | if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) { |
| 12 | 20 | return; |
| 13 | 21 | } |
| 14 | 22 | |
| 15 | -$form = $view_args['form']; | |
| 16 | -$field = $view_args['field']; | |
| 17 | -$classes = esc_attr( $view_args['classes'] ); | |
| 18 | -$is_required = isset( $field['required'] ) ? $field['required'] : false; | |
| 19 | -$value = isset( $field['value'] ) ? esc_attr( $field['value'] ) : ''; | |
| 20 | -$min_date = isset( $field['min_date'] ) ? esc_attr( $field['min_date'] ) : ''; | |
| 21 | -$max_date = isset( $field['max_date'] ) ? esc_attr( $field['max_date'] ) : ''; | |
| 22 | -$date_format = array_key_exists( 'date_format', $field ) ? $field['date_format'] : 'MM d, yy'; | |
| 23 | -$json_args = array( | |
| 24 | - 'changeMonth' => true, | |
| 25 | - 'changeYear' => true, | |
| 26 | - 'dateFormat' => $date_format, | |
| 23 | +global $wp_locale; | |
| 24 | + | |
| 25 | +$charitable_form = $view_args['form']; | |
| 26 | +$charitable_field = $view_args['field']; | |
| 27 | +$charitable_classes = esc_attr( $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'] ) : ''; | |
| 30 | +$charitable_min_date = isset( $charitable_field['min_date'] ) ? esc_attr( $charitable_field['min_date'] ) : ''; | |
| 31 | +$charitable_max_date = isset( $charitable_field['max_date'] ) ? esc_attr( $charitable_field['max_date'] ) : ''; | |
| 32 | +$charitable_year_range = array_key_exists( 'year_range', $charitable_field ) ? $charitable_field['year_range'] : 'c-100:c'; | |
| 33 | +$charitable_date_format = array_key_exists( 'date_format', $charitable_field ) ? $charitable_field['date_format'] : charitable()->registry()->get( 'i18n' )->get_js_datepicker_format( 'MM d, yy' ); | |
| 34 | +$charitable_json_args = array( | |
| 35 | + 'changeMonth' => true, | |
| 36 | + 'changeYear' => true, | |
| 37 | + 'dateFormat' => $charitable_date_format, | |
| 38 | + 'yearRange' => $charitable_year_range, | |
| 39 | + 'monthNames' => array_values( $wp_locale->month ), | |
| 40 | + 'monthNamesShort' => array_values( $wp_locale->month_abbrev ), | |
| 27 | 41 | ); |
| 28 | 42 | |
| 29 | -if ( array_key_exists( 'min_date', $field ) ) { | |
| 30 | - $json_args['minDate'] = '+' . $field['min_date']; | |
| 43 | +if ( array_key_exists( 'min_date', $charitable_field ) ) { | |
| 44 | + $charitable_json_args['minDate'] = '+' . $charitable_field['min_date']; | |
| 31 | 45 | } |
| 32 | 46 | |
| 33 | -if ( array_key_exists( 'max_date', $field ) ) { | |
| 34 | - $json_args['maxDate'] = '+' . $field['max_date']; | |
| 47 | +if ( array_key_exists( 'max_date', $charitable_field ) ) { | |
| 48 | + $charitable_json_args['maxDate'] = '+' . $charitable_field['max_date']; | |
| 35 | 49 | } |
| 36 | 50 | |
| 37 | 51 | /* Enqueue the datepicker */ |
| 38 | 52 | if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) { |
| @@ -38,23 +52,24 @@ | ||
| 38 | 52 | if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) { |
| 39 | 53 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 40 | 54 | } |
| 41 | 55 | |
| 42 | -$datepicker_json_args = json_encode( $json_args ); | |
| 56 | +$charitable_datepicker_json_args = wp_json_encode( $charitable_json_args ); | |
| 43 | 57 | |
| 44 | -wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready( function(){ | |
| 45 | - jQuery( '.datepicker' ).datepicker( {$datepicker_json_args} ); | |
| 46 | -});" ); | |
| 58 | +wp_add_inline_script( | |
| 59 | + 'jquery-ui-datepicker', | |
| 60 | + "jQuery(document).ready( function(){ jQuery( '.datepicker' ).datepicker( {$charitable_datepicker_json_args} ); });" | |
| 61 | +); | |
| 47 | 62 | |
| 48 | 63 | wp_enqueue_style( 'charitable-datepicker' ); |
| 49 | 64 | |
| 50 | 65 | ?> |
| 51 | -<div id="charitable_field_<?php echo esc_attr( $field['key'] ); ?>" class="<?php echo $classes; ?>"> | |
| 52 | - <?php if ( isset( $field['label'] ) ) : ?> | |
| 53 | - <label for="charitable_field_<?php echo esc_attr( $field['key'] ); ?>_element"> | |
| 54 | - <?php echo $field['label']; ?> | |
| 55 | - <?php if ( $is_required ) : ?> | |
| 56 | - <abbr class="required" title="required">*</abbr> | |
| 66 | +<div id="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>" class="<?php echo esc_attr( $charitable_classes ); ?>"> | |
| 67 | + <?php if ( isset( $charitable_field['label'] ) ) : ?> | |
| 68 | + <label for="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>_element"> | |
| 69 | + <?php echo wp_kses_post( $charitable_field['label'] ); ?> | |
| 70 | + <?php if ( $charitable_is_required ) : ?> | |
| 71 | + <abbr class="required" title="<?php esc_html_e( 'Required', 'charitable' ); ?>">*</abbr> | |
| 57 | 72 | <?php endif ?> |
| 58 | 73 | </label> |
| 59 | 74 | <?php endif ?> |
| 60 | 75 | <input |
| @@ -59,10 +74,18 @@ | ||
| 59 | 74 | <?php endif ?> |
| 60 | 75 | <input |
| 61 | 76 | type="text" |
| 62 | 77 | class="datepicker" |
| 63 | - name="<?php echo esc_attr( $field['key'] ); ?>" | |
| 64 | - value="<?php echo esc_attr( $value ); ?>" | |
| 65 | - id="charitable_field_<?php echo esc_attr( $field['key'] ); ?>_element" | |
| 66 | - <?php echo charitable_get_arbitrary_attributes( $field ); ?> | |
| 78 | + name="<?php echo esc_attr( $charitable_field['key'] ); ?>" | |
| 79 | + value="<?php echo esc_attr( $charitable_value ); ?>" | |
| 80 | + id="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>_element" | |
| 81 | + <?php echo charitable_get_arbitrary_attributes( $charitable_field ); // phpcs:ignore ?> | |
| 67 | 82 | /> |
| 68 | -</div> | |
| 83 | + <?php | |
| 84 | + | |
| 85 | + // If there is a description, add it after the input. | |
| 86 | + if ( isset( $charitable_field['description'] ) && ! empty( $charitable_field['description'] ) ) { | |
| 87 | + echo '<p class="charitable-field-description">' . wp_kses_post( $charitable_field['description'] ) . '</p>'; | |
| 88 | + } | |
| 89 | + | |
| 90 | + ?> | |
| 91 | +</div> | |