name = 'date_time_picker';
$this->label = __('Date and Time Picker');
$this->category = __("jQuery", $this->domain); // Basic, Content, Choice, etc
$this->domain = 'acf-date_time_picker';
$this->defaults = array(
'value' => ''
, 'label' => __( 'Choose Time', $this->domain )
, 'time_format' => 'hh:mm'
, 'show_date' => true
, 'date_format' => 'mm/dd/yy'
, 'show_week_number' => false
, 'picker' => 'slider'
);
// do not delete!
parent::__construct();
// settings
$this->settings = array(
'path' => apply_filters('acf/helpers/get_path', __FILE__)
, 'dir' => apply_filters('acf/helpers/get_dir', __FILE__)
, 'version' => '2.0.0.beta'
);
}
/*
* create_options()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field - an array holding all the field's data
*/
function create_options( $field )
{
$field = array_merge($this->defaults, $field);
$key = $field['name'];
?>
|
|
'radio'
, 'name' => 'fields['.$key.'][show_date]'
, 'value' => $field['show_date']
, 'layout' => 'horizontal'
, 'choices' => array(
'true' => __( 'Date and Time Picker', $this->domain )
, 'false' => __( 'Time Picker', $this->domain )
)
) );
?>
|
|
formatting date", $this->domain ),"http://docs.jquery.com/UI/Datepicker/formatDate");?>
|
'text'
, 'name' => 'fields[' . $key . '][date_format]'
, 'value' => $field['date_format']
) );
?>
|
|
formatting time", $this->domain ),"http://trentrichardson.com/examples/timepicker/#tp-formatting");?>
|
'text'
, 'name' => 'fields[' . $key . '][time_format]'
, 'value' => $field['time_format']
) );
?>
|
|
|
'radio'
, 'name' => 'fields['.$key.'][show_week_number]'
, 'value' => $field['show_week_number']
, 'layout' => 'horizontal'
, 'choices' => array(
'true' => __( 'Yes', $this->domain )
, 'false' => __( 'No', $this->domain )
)
) );
?>
|
|
|
'radio'
, 'name' => 'fields['.$key.'][picker]'
, 'value' => $field['picker']
, 'layout' => 'horizontal'
, 'choices' => array(
'slider' => __( 'Slider', $this->domain )
, 'select' => __( 'Dropdown', $this->domain )
)
) );
?>
|
defaults, $field );
extract( $field, EXTR_SKIP ); //Declare each item in $field as its own variable i.e.: $name, $value, $label, $time_format, $date_format and $show_week_number
if ( $show_date != 'true' ) {
echo '';
} else {
echo '';
}
}
/*
* input_admin_enqueue_scripts()
*
* This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
* Use this action to add css + javascript to assist your create_field() action.
*
* $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
* @type action
* @since 3.6
* @date 23/01/13
*/
function input_admin_enqueue_scripts() {
global $wp_locale;
$has_locale = false;
$js_locale = $this->get_js_locale(get_locale());
wp_enqueue_script( 'jquery-ui-timepicker', $this->settings['dir'] . 'js/jquery-ui-timepicker-addon.js', array(
'jquery-ui-datepicker',
'jquery-ui-slider'
), $this->settings['version'], true );
if ( file_exists( dirname( __FILE__ ) . '/js/localization/jquery-ui-timepicker-' . $js_locale . '.js' ) ) {
wp_enqueue_script( 'timepicker-localization', $this->settings['dir'] . 'js/localization/jquery-ui-timepicker-' . $js_locale . '.js', array(
'jquery-ui-timepicker'
), $this->settings['version'], true );
wp_enqueue_script( 'timepicker', $this->settings['dir'] . 'js/timepicker.js', array(
'timepicker-localization'
), $this->settings['version'], true );
$has_locale = true;
} else {
wp_enqueue_script( 'timepicker', $this->settings['dir'] . 'js/timepicker.js', array(
'jquery-ui-timepicker'
), $this->settings['version'], true );
}
if ( ! $has_locale && $js_locale != 'en' ) {
$timepicker_locale = array(
'closeText' => __( 'Done', $this->domain )
, 'currentText' => __( 'Today', $this->domain )
, 'prevText' => __( 'Prev', $this->domain )
, 'nextText' => __( 'Next', $this->domain )
, 'monthStatus' => __( 'Show a different month', $this->domain )
, 'weekHeader' => __( 'Wk', $this->domain )
, 'timeText' => __( "Time", $this->domain )
, 'hourText' => __( "Hour", $this->domain )
, 'minuteText' => __( "Minute", $this->domain )
, 'secondText' => __( "Second", $this->domain )
, 'millisecText' => __( "Millisecond", $this->domain )
, 'timezoneText' => __( "Time Zone", $this->domain )
, 'isRTL' => $wp_locale->is_rtl()
);
}
$timepicker_wp_locale = array(
'monthNames' => $this->strip_array_indices( $wp_locale->month )
, 'monthNamesShort' => $this->strip_array_indices( $wp_locale->month_abbrev )
, 'dayNames' => $this->strip_array_indices( $wp_locale->weekday )
, 'dayNamesShort' => $this->strip_array_indices( $wp_locale->weekday_abbrev )
, 'dayNamesMin' => $this->strip_array_indices( $wp_locale->weekday_initial )
, 'showMonthAfterYear' => false
, 'showWeek' => false
, 'firstDay' => get_option( 'start_of_week' )
);
$l10n = ( isset( $timepicker_locale ) ) ? array_merge( $timepicker_wp_locale, $timepicker_locale ) : $timepicker_wp_locale;
wp_localize_script( 'timepicker', 'timepicker_objectL10n', $l10n );
wp_enqueue_style('jquery-style', $this->settings['dir'] . 'css/jquery-ui.css');
wp_enqueue_style('timepicker', $this->settings['dir'] . 'css/jquery-ui-timepicker-addon.css',array(
'jquery-style'
),$this->settings['version']);
}
/**
* helper function, see: http://www.renegadetechconsulting.com/tutorials/jquery-datepicker-and-wordpress-i18n
* @param array $ArrayToStrip
* @return array
*/
function strip_array_indices( $ArrayToStrip ) {
foreach ( $ArrayToStrip as $objArrayItem ) {
$NewArray[] = $objArrayItem;
}
return $NewArray;
}
function get_js_locale($locale) {
$tmp_locale = ( '' == $locale ) ? 'en' : strtolower($locale);
if (strpos($tmp_locale,'_') !== false) {
return substr( $tmp_locale, 3, 2 );
} else {
return $tmp_locale;
}
}
}
// create field
new acf_field_date_time_picker();
?>