dtp = new acf_field_date_time_picker_common(); $this->name = $this->dtp->name; $this->label = $this->dtp->label; $this->category = $this->dtp->category; $this->defaults = $this->dtp->defaults; add_action('init', array($this, 'init')); parent::__construct(); $this->settings = array( 'path' => apply_filters('acf/helpers/get_path', __FILE__), 'dir' => apply_filters('acf/helpers/get_dir', __FILE__), 'version' => ACF_DTP_VERSION, ); } /** * Initialize translations * * @since 1.0.0 */ public function init() { $this->l10n = $this->dtp->translations(); } /** * Create extra options for your field. This is rendered when editing a field. * * @since 1.0.0 * * @param array $field Field data */ public function create_options($field) { $field = array_merge($this->defaults, $field); $key = $field['name']; ?> 'radio', 'layout' => 'horizontal', 'name' => 'fields['.$key.'][field_type]', 'value' => $field['field_type'], 'choices' => array('date_time' => __('date & time', 'acf-date-time-picker'), 'time' => __('time only', 'acf-date-time-picker')), )); ?>

date formats', 'acf-date-time-picker'); ?>

'text', 'name' => 'fields['.$key.'][date_format]', 'value' => $field['date_format'], )); ?>

time formats', 'acf-date-time-picker'); ?>

'text', 'name' => 'fields['.$key.'][time_format]', 'value' => $field['time_format'], )); ?> 'radio', 'layout' => 'horizontal', 'name' => 'fields['.$key.'][past_dates]', 'value' => $field['past_dates'], 'choices' => array('yes' => __('yes', 'acf-date-time-picker'), 'no' => __('no', 'acf-date-time-picker'), ), )); ?> 'radio', 'layout' => 'horizontal', 'name' => 'fields['.$key.'][time_selector]', 'value' => $field['time_selector'], 'choices' => array('select' => __('dropdown list', 'acf-date-time-picker'), ), )); ?> weekday); ?> 'select', 'name' => 'fields['.$key.'][first_day]', 'value' => $field['first_day'], 'choices' => $choices, )); ?> defaults, $field); ?>
defaults, $field); if(preg_match('/^dd?\//', $field['date_format'])) { // if start with dd/ or d/ (not supported by strtotime()) $value = str_replace('/', '-', $value); } $value = date('Y-m-d H:i:s', strtotime($value)); return $value; } /** * Format date and time after it is loaded from the db * * @since 1.0.0 * * @param mixed $value The value found in the database * @param mixed $post_id The post ID from which the value was loaded * @param array $field The field array holding all the field options * * @return mixed The formatted date and time */ public function load_value($value, $post_id, $field) { $field = array_merge($this->defaults, $field); return $this->dtp->format_date_time($value, $field); } } // initialize field class new acf_field_date_time_picker(); endif;