| 1 |
<?php |
| 2 |
/** |
| 3 |
* The template used to display datepicker form fields. |
| 4 |
* |
| 5 |
* @author WP Charitable LLC |
| 6 |
* @package Charitable/Templates/Form Fields |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.6.40 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
global $wp_locale; |
| 16 |
|
| 17 |
$form = $view_args['form']; |
| 18 |
$field = $view_args['field']; |
| 19 |
$classes = esc_attr( $view_args['classes'] ); |
| 20 |
$is_required = isset( $field['required'] ) ? $field['required'] : false; |
| 21 |
$value = isset( $field['value'] ) ? esc_attr( $field['value'] ) : ''; |
| 22 |
$min_date = isset( $field['min_date'] ) ? esc_attr( $field['min_date'] ) : ''; |
| 23 |
$max_date = isset( $field['max_date'] ) ? esc_attr( $field['max_date'] ) : ''; |
| 24 |
$year_range = array_key_exists( 'year_range', $field ) ? $field['year_range'] : 'c-100:c'; |
| 25 |
$date_format = array_key_exists( 'date_format', $field ) ? $field['date_format'] : charitable()->registry()->get( 'i18n' )->get_js_datepicker_format( 'MM d, yy' ); |
| 26 |
$json_args = array( |
| 27 |
'changeMonth' => true, |
| 28 |
'changeYear' => true, |
| 29 |
'dateFormat' => $date_format, |
| 30 |
'yearRange' => $year_range, |
| 31 |
'monthNames' => array_values( $wp_locale->month ), |
| 32 |
'monthNamesShort' => array_values( $wp_locale->month_abbrev ), |
| 33 |
); |
| 34 |
|
| 35 |
if ( array_key_exists( 'min_date', $field ) ) { |
| 36 |
$json_args['minDate'] = '+' . $field['min_date']; |
| 37 |
} |
| 38 |
|
| 39 |
if ( array_key_exists( 'max_date', $field ) ) { |
| 40 |
$json_args['maxDate'] = '+' . $field['max_date']; |
| 41 |
} |
| 42 |
|
| 43 |
/* Enqueue the datepicker */ |
| 44 |
if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) { |
| 45 |
wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 46 |
} |
| 47 |
|
| 48 |
$datepicker_json_args = json_encode( $json_args ); |
| 49 |
|
| 50 |
wp_add_inline_script( |
| 51 |
'jquery-ui-datepicker', |
| 52 |
"jQuery(document).ready( function(){ jQuery( '.datepicker' ).datepicker( {$datepicker_json_args} ); });" |
| 53 |
); |
| 54 |
|
| 55 |
wp_enqueue_style( 'charitable-datepicker' ); |
| 56 |
|
| 57 |
?> |
| 58 |
<div id="charitable_field_<?php echo esc_attr( $field['key'] ); ?>" class="<?php echo $classes; ?>"> |
| 59 |
<?php if ( isset( $field['label'] ) ) : ?> |
| 60 |
<label for="charitable_field_<?php echo esc_attr( $field['key'] ); ?>_element"> |
| 61 |
<?php echo $field['label']; ?> |
| 62 |
<?php if ( $is_required ) : ?> |
| 63 |
<abbr class="required" title="required">*</abbr> |
| 64 |
<?php endif ?> |
| 65 |
</label> |
| 66 |
<?php endif ?> |
| 67 |
<input |
| 68 |
type="text" |
| 69 |
class="datepicker" |
| 70 |
name="<?php echo esc_attr( $field['key'] ); ?>" |
| 71 |
value="<?php echo esc_attr( $value ); ?>" |
| 72 |
id="charitable_field_<?php echo esc_attr( $field['key'] ); ?>_element" |
| 73 |
<?php echo charitable_get_arbitrary_attributes( $field ); ?> |
| 74 |
/> |
| 75 |
</div> |
| 76 |
|