1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?php
abstract class CMB2_Type_Picker_Base extends CMB2_Type_Text {
public function parse_picker_options( $arg = 'date', $args = array() ) {
$att = 'data-' . $arg . 'picker';
$update = empty( $args );
$atts = array();
$format = $this->field->args( $arg . '_format' );
if ( $js_format = CMB2_Utils::php_to_js_dateformat( $format ) ) {
if ( $update ) {
$atts = $this->field->args( 'attributes' );
} else {
$atts = isset( $args['attributes'] )
? $args['attributes']
: $atts;
}
$data = isset( $atts[ $att ] )
? json_decode( $atts[ $att ], true )
: array();
$data[ $arg . 'Format' ] = $js_format;
$atts[ $att ] = function_exists( 'wp_json_encode' )
? wp_json_encode( $data )
: json_encode( $data );
}
if ( $update ) {
$this->field->args['attributes'] = $atts;
}
return array_merge( $args, $atts );
}
}