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.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / includes / fields / class-acf-field-date_time_picker.php
advanced-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 5 months ago class-acf-field-button-group.php 5 months ago class-acf-field-checkbox.php 2 months ago class-acf-field-color_picker.php 5 months ago class-acf-field-date_picker.php 5 months ago class-acf-field-date_time_picker.php 5 months ago class-acf-field-email.php 5 months ago class-acf-field-file.php 5 months ago class-acf-field-google-map.php 5 months ago class-acf-field-group.php 5 months ago class-acf-field-icon_picker.php 6 months ago class-acf-field-image.php 1 month ago class-acf-field-link.php 5 months ago class-acf-field-message.php 6 months ago class-acf-field-number.php 5 months ago class-acf-field-oembed.php 2 months ago class-acf-field-output.php 6 months ago class-acf-field-page_link.php 1 month ago class-acf-field-password.php 5 months ago class-acf-field-post_object.php 1 month ago class-acf-field-radio.php 2 months ago class-acf-field-range.php 5 months ago class-acf-field-relationship.php 1 month ago class-acf-field-select.php 2 months ago class-acf-field-separator.php 6 months ago class-acf-field-tab.php 6 months ago class-acf-field-taxonomy.php 2 months ago class-acf-field-text.php 5 months ago class-acf-field-textarea.php 5 months ago class-acf-field-time_picker.php 5 months ago class-acf-field-true_false.php 5 months ago class-acf-field-url.php 5 months ago class-acf-field-user.php 2 months ago class-acf-field-wysiwyg.php 5 months ago class-acf-field.php 5 months ago index.php 2 years ago
class-acf-field-date_time_picker.php
336 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if ( ! class_exists( 'acf_field_date_and_time_picker' ) ) :
13
14 class acf_field_date_and_time_picker extends acf_field {
15
16
17 /**
18 * This function will setup the field type data
19 *
20 * @type function
21 * @date 5/03/2014
22 * @since 5.0.0
23 *
24 * @param n/a
25 * @return n/a
26 */
27 function initialize() {
28
29 // vars
30 $this->name = 'date_time_picker';
31 $this->label = __( 'Date Time Picker', 'acf' );
32 $this->category = 'advanced';
33 $this->description = __( 'An interactive UI for picking a date and time. The date return format can be customized using the field settings.', 'acf' );
34 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-date-time.png';
35 $this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/date-time-picker/', 'docs', 'field-type-selection' );
36 $this->defaults = array(
37 'display_format' => 'd/m/Y g:i a',
38 'return_format' => 'd/m/Y g:i a',
39 'first_day' => 1,
40 'default_to_current_date' => 0,
41 );
42 }
43
44
45 /**
46 * description
47 *
48 * @type function
49 * @date 16/12/2015
50 * @since 5.3.2
51 *
52 * @param $post_id (int)
53 * @return $post_id (int)
54 */
55 function input_admin_enqueue_scripts() {
56
57 // bail early if no enqueue
58 if ( ! acf_get_setting( 'enqueue_datetimepicker' ) ) {
59 return;
60 }
61
62 // vars
63 $version = '1.6.1';
64
65 // script
66 wp_enqueue_script( 'acf-timepicker', acf_get_url( 'assets/inc/timepicker/jquery-ui-timepicker-addon.min.js' ), array( 'jquery-ui-datepicker' ), $version );
67
68 // style
69 wp_enqueue_style( 'acf-timepicker', acf_get_url( 'assets/inc/timepicker/jquery-ui-timepicker-addon.min.css' ), '', $version );
70
71 // localize
72 acf_localize_data(
73 array(
74 'dateTimePickerL10n' => array(
75 'timeOnlyTitle' => _x( 'Choose Time', 'Date Time Picker JS timeOnlyTitle', 'acf' ),
76 'timeText' => _x( 'Time', 'Date Time Picker JS timeText', 'acf' ),
77 'hourText' => _x( 'Hour', 'Date Time Picker JS hourText', 'acf' ),
78 'minuteText' => _x( 'Minute', 'Date Time Picker JS minuteText', 'acf' ),
79 'secondText' => _x( 'Second', 'Date Time Picker JS secondText', 'acf' ),
80 'millisecText' => _x( 'Millisecond', 'Date Time Picker JS millisecText', 'acf' ),
81 'microsecText' => _x( 'Microsecond', 'Date Time Picker JS microsecText', 'acf' ),
82 'timezoneText' => _x( 'Time Zone', 'Date Time Picker JS timezoneText', 'acf' ),
83 'currentText' => _x( 'Now', 'Date Time Picker JS currentText', 'acf' ),
84 'closeText' => _x( 'Done', 'Date Time Picker JS closeText', 'acf' ),
85 'selectText' => _x( 'Select', 'Date Time Picker JS selectText', 'acf' ),
86 'amNames' => array(
87 _x( 'AM', 'Date Time Picker JS amText', 'acf' ),
88 _x( 'A', 'Date Time Picker JS amTextShort', 'acf' ),
89 ),
90 'pmNames' => array(
91 _x( 'PM', 'Date Time Picker JS pmText', 'acf' ),
92 _x( 'P', 'Date Time Picker JS pmTextShort', 'acf' ),
93 ),
94 ),
95 )
96 );
97 }
98
99
100 /**
101 * Create the HTML interface for your field
102 *
103 * @param $field - an array holding all the field's data
104 *
105 * @type action
106 * @since 3.6
107 * @date 23/01/13
108 */
109 function render_field( $field ) {
110
111 // Set value.
112 $hidden_value = '';
113 $display_value = '';
114
115 if ( $field['value'] ) {
116 $hidden_value = acf_format_date( $field['value'], 'Y-m-d H:i:s' );
117 $display_value = acf_format_date( $field['value'], $field['display_format'] );
118 }
119
120 // Convert "display_format" setting to individual date and time formats.
121 $formats = acf_split_date_time( $field['display_format'] );
122
123 // Elements.
124 $div = array(
125 'class' => 'acf-date-time-picker acf-input-wrap',
126 'data-date_format' => acf_convert_date_to_js( $formats['date'] ),
127 'data-time_format' => acf_convert_time_to_js( $formats['time'] ),
128 'data-first_day' => $field['first_day'],
129 );
130 $hidden_input = array(
131 'id' => $field['id'],
132 'class' => 'input-alt',
133 'name' => $field['name'],
134 'value' => $hidden_value,
135 );
136 $text_input = array(
137 'class' => $field['class'] . ' input',
138 'value' => $display_value,
139 'data-default-to-today' => $field['default_to_current_date'],
140 );
141 foreach ( array( 'readonly', 'disabled' ) as $k ) {
142 if ( ! empty( $field[ $k ] ) ) {
143 $hidden_input[ $k ] = $k;
144 $text_input[ $k ] = $k;
145 }
146 }
147
148 // Output.
149 ?>
150 <div <?php echo acf_esc_attrs( $div ); ?>>
151 <?php acf_hidden_input( $hidden_input ); ?>
152 <?php acf_text_input( $text_input ); ?>
153 </div>
154 <?php
155 }
156
157
158 /**
159 * Create extra options for your field. This is rendered when editing a field.
160 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
161 *
162 * @type action
163 * @since 3.6
164 * @date 23/01/13
165 *
166 * @param $field - an array holding all the field's data
167 */
168 function render_field_settings( $field ) {
169 global $wp_locale;
170
171 $d_m_Y = date_i18n( 'd/m/Y g:i a' );
172 $m_d_Y = date_i18n( 'm/d/Y g:i a' );
173 $F_j_Y = date_i18n( 'F j, Y g:i a' );
174 $Ymd = date_i18n( 'Y-m-d H:i:s' );
175
176 echo '<div class="acf-field-settings-split">';
177
178 acf_render_field_setting(
179 $field,
180 array(
181 'label' => __( 'Display Format', 'acf' ),
182 'hint' => __( 'The format displayed when editing a post', 'acf' ),
183 'type' => 'radio',
184 'name' => 'display_format',
185 'other_choice' => 1,
186 'choices' => array(
187 'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
188 'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
189 'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
190 'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
191 'other' => '<span>' . __( 'Custom:', 'acf' ) . '</span>',
192 ),
193 )
194 );
195
196 acf_render_field_setting(
197 $field,
198 array(
199 'label' => __( 'Return Format', 'acf' ),
200 'hint' => __( 'The format returned via template functions', 'acf' ),
201 'type' => 'radio',
202 'name' => 'return_format',
203 'other_choice' => 1,
204 'choices' => array(
205 'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
206 'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
207 'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
208 'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
209 'other' => '<span>' . __( 'Custom:', 'acf' ) . '</span>',
210 ),
211 )
212 );
213
214 echo '</div>';
215
216 acf_render_field_setting(
217 $field,
218 array(
219 'label' => __( 'Week Starts On', 'acf' ),
220 'instructions' => '',
221 'type' => 'select',
222 'name' => 'first_day',
223 'choices' => array_values( $wp_locale->weekday ),
224 )
225 );
226
227 acf_render_field_setting(
228 $field,
229 array(
230 'label' => __( 'Default to the current date', 'acf' ),
231 'instructions' => __( 'Use the current date as the default value for this field.', 'acf' ),
232 'type' => 'true_false',
233 'name' => 'default_to_current_date',
234 'ui' => 1,
235 )
236 );
237 }
238
239 /**
240 * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
241 *
242 * @type filter
243 * @since 3.6
244 *
245 * @param mixed $value The value which was loaded from the database
246 * @param mixed $post_id The post_id from which the value was loaded
247 * @param array $field The field array holding all the field options
248 * @return mixed $value The modified value
249 */
250 public function format_value( $value, $post_id, $field ) {
251 return acf_format_date( $value, $field['return_format'] );
252 }
253
254
255 /**
256 * This filter is applied to the $field after it is loaded from the database
257 * and ensures the return and display values are set.
258 *
259 * @type filter
260 * @since 5.11.0
261 *
262 * @param array $field The field array holding all the field options.
263 * @return array
264 */
265 public function load_field( $field ) {
266 if ( empty( $field['display_format'] ) ) {
267 $field['display_format'] = $this->defaults['display_format'];
268 }
269
270 if ( empty( $field['return_format'] ) ) {
271 $field['return_format'] = $this->defaults['return_format'];
272 }
273
274 return $field;
275 }
276
277 /**
278 * Return the schema array for the REST API.
279 *
280 * @param array $field
281 * @return array
282 */
283 public function get_rest_schema( array $field ) {
284 return array(
285 'type' => array( 'string', 'null' ),
286 'description' => 'A `Y-m-d H:i:s` formatted date string.',
287 'required' => ! empty( $field['required'] ),
288 );
289 }
290
291 /**
292 * Returns an array of JSON-LD Property output types that are supported by this field type.
293 *
294 * @since 6.8
295 *
296 * @return string[]
297 */
298 public function get_jsonld_output_types(): array {
299 return array( 'DateTime' );
300 }
301
302 /**
303 * Formats the field value for JSON-LD output.
304 *
305 * Converts the stored Y-m-d H:i:s format to ISO 8601 datetime format.
306 *
307 * @since 6.8.0
308 *
309 * @param mixed $value The value of the field.
310 * @param integer|string $post_id The ID of the post.
311 * @param array $field The field array.
312 * @return string|null ISO 8601 formatted datetime or null.
313 */
314 public function format_value_for_jsonld( $value, $post_id, $field ) {
315 if ( empty( $value ) || ! is_string( $value ) ) {
316 return null;
317 }
318
319 // ACF stores date_time_picker internally as 'Y-m-d H:i:s'.
320 // Use WordPress site timezone so the ISO 8601 offset is correct.
321 $date = \DateTime::createFromFormat( 'Y-m-d H:i:s', $value, wp_timezone() );
322 if ( ! $date ) {
323 return null;
324 }
325
326 // Return ISO 8601 datetime format with timezone.
327 return $date->format( 'c' );
328 }
329 }
330
331 // initialize
332 acf_register_field_type( 'acf_field_date_and_time_picker' );
333 endif; // class_exists check
334
335 ?>
336