PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.1-beta7
Secure Custom Fields v6.4.1-beta7
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / fields / class-acf-field-date_time_picker.php
secure-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 1 year ago class-acf-field-button-group.php 1 year ago class-acf-field-checkbox.php 1 year ago class-acf-field-clone.php 1 year ago class-acf-field-color_picker.php 1 year ago class-acf-field-date_picker.php 1 year ago class-acf-field-date_time_picker.php 1 year ago class-acf-field-email.php 1 year ago class-acf-field-file.php 1 year ago class-acf-field-flexible-content.php 1 year ago class-acf-field-gallery.php 1 year ago class-acf-field-google-map.php 1 year ago class-acf-field-group.php 1 year ago class-acf-field-icon_picker.php 1 year ago class-acf-field-image.php 1 year ago class-acf-field-link.php 1 year ago class-acf-field-message.php 1 year ago class-acf-field-number.php 1 year ago class-acf-field-oembed.php 1 year ago class-acf-field-output.php 1 year ago class-acf-field-page_link.php 1 year ago class-acf-field-password.php 1 year ago class-acf-field-post_object.php 1 year ago class-acf-field-radio.php 1 year ago class-acf-field-range.php 1 year ago class-acf-field-relationship.php 1 year ago class-acf-field-repeater.php 1 year ago class-acf-field-select.php 1 year ago class-acf-field-separator.php 1 year ago class-acf-field-tab.php 1 year ago class-acf-field-taxonomy.php 1 year ago class-acf-field-text.php 1 year ago class-acf-field-textarea.php 1 year ago class-acf-field-time_picker.php 1 year ago class-acf-field-true_false.php 1 year ago class-acf-field-url.php 1 year ago class-acf-field-user.php 1 year ago class-acf-field-wysiwyg.php 1 year ago class-acf-field.php 1 year ago class-acf-repeater-table.php 1 year ago index.php 1 year ago
class-acf-field-date_time_picker.php
277 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_date_and_time_picker' ) ) :
4
5 class acf_field_date_and_time_picker extends acf_field {
6
7
8 /**
9 * This function will setup the field type data
10 *
11 * @type function
12 * @date 5/03/2014
13 * @since ACF 5.0.0
14 *
15 * @param n/a
16 * @return n/a
17 */
18 function initialize() {
19
20 // vars
21 $this->name = 'date_time_picker';
22 $this->label = __( 'Date Time Picker', 'secure-custom-fields' );
23 $this->category = 'advanced';
24 $this->description = __( 'An interactive UI for picking a date and time. The date return format can be customized using the field settings.', 'secure-custom-fields' );
25 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-date-time.png';
26 $this->doc_url = 'https://developer.wordpress.org/secure-custom-fields/features/fields/date-time-picker/';
27 $this->tutorial_url = 'https://developer.wordpress.org/secure-custom-fields/features/fields/date-time-picker/date-time-picker-tutorial/';
28 $this->defaults = array(
29 'display_format' => 'd/m/Y g:i a',
30 'return_format' => 'd/m/Y g:i a',
31 'first_day' => 1,
32 );
33 }
34
35
36 /**
37 * description
38 *
39 * @type function
40 * @date 16/12/2015
41 * @since ACF 5.3.2
42 *
43 * @param $post_id (int)
44 * @return $post_id (int)
45 */
46 function input_admin_enqueue_scripts() {
47
48 // bail early if no enqueue
49 if ( ! acf_get_setting( 'enqueue_datetimepicker' ) ) {
50 return;
51 }
52
53 // vars
54 $version = '1.6.1';
55
56 // script
57 wp_enqueue_script( 'acf-timepicker', acf_get_url( 'assets/inc/timepicker/jquery-ui-timepicker-addon.min.js' ), array( 'jquery-ui-datepicker' ), $version );
58
59 // style
60 wp_enqueue_style( 'acf-timepicker', acf_get_url( 'assets/inc/timepicker/jquery-ui-timepicker-addon.min.css' ), '', $version );
61
62 // localize
63 acf_localize_data(
64 array(
65 'dateTimePickerL10n' => array(
66 'timeOnlyTitle' => _x( 'Choose Time', 'Date Time Picker JS timeOnlyTitle', 'secure-custom-fields' ),
67 'timeText' => _x( 'Time', 'Date Time Picker JS timeText', 'secure-custom-fields' ),
68 'hourText' => _x( 'Hour', 'Date Time Picker JS hourText', 'secure-custom-fields' ),
69 'minuteText' => _x( 'Minute', 'Date Time Picker JS minuteText', 'secure-custom-fields' ),
70 'secondText' => _x( 'Second', 'Date Time Picker JS secondText', 'secure-custom-fields' ),
71 'millisecText' => _x( 'Millisecond', 'Date Time Picker JS millisecText', 'secure-custom-fields' ),
72 'microsecText' => _x( 'Microsecond', 'Date Time Picker JS microsecText', 'secure-custom-fields' ),
73 'timezoneText' => _x( 'Time Zone', 'Date Time Picker JS timezoneText', 'secure-custom-fields' ),
74 'currentText' => _x( 'Now', 'Date Time Picker JS currentText', 'secure-custom-fields' ),
75 'closeText' => _x( 'Done', 'Date Time Picker JS closeText', 'secure-custom-fields' ),
76 'selectText' => _x( 'Select', 'Date Time Picker JS selectText', 'secure-custom-fields' ),
77 'amNames' => array(
78 _x( 'AM', 'Date Time Picker JS amText', 'secure-custom-fields' ),
79 _x( 'A', 'Date Time Picker JS amTextShort', 'secure-custom-fields' ),
80 ),
81 'pmNames' => array(
82 _x( 'PM', 'Date Time Picker JS pmText', 'secure-custom-fields' ),
83 _x( 'P', 'Date Time Picker JS pmTextShort', 'secure-custom-fields' ),
84 ),
85 ),
86 )
87 );
88 }
89
90
91 /**
92 * Create the HTML interface for your field
93 *
94 * @param $field - an array holding all the field's data
95 *
96 * @type action
97 * @since ACF 3.6
98 * @date 23/01/13
99 */
100 function render_field( $field ) {
101
102 // Set value.
103 $hidden_value = '';
104 $display_value = '';
105
106 if ( $field['value'] ) {
107 $hidden_value = acf_format_date( $field['value'], 'Y-m-d H:i:s' );
108 $display_value = acf_format_date( $field['value'], $field['display_format'] );
109 }
110
111 // Convert "display_format" setting to individual date and time formats.
112 $formats = acf_split_date_time( $field['display_format'] );
113
114 // Elements.
115 $div = array(
116 'class' => 'acf-date-time-picker acf-input-wrap',
117 'data-date_format' => acf_convert_date_to_js( $formats['date'] ),
118 'data-time_format' => acf_convert_time_to_js( $formats['time'] ),
119 'data-first_day' => $field['first_day'],
120 );
121 $hidden_input = array(
122 'id' => $field['id'],
123 'class' => 'input-alt',
124 'name' => $field['name'],
125 'value' => $hidden_value,
126 );
127 $text_input = array(
128 'class' => $field['class'] . ' input',
129 'value' => $display_value,
130 );
131 foreach ( array( 'readonly', 'disabled' ) as $k ) {
132 if ( ! empty( $field[ $k ] ) ) {
133 $hidden_input[ $k ] = $k;
134 $text_input[ $k ] = $k;
135 }
136 }
137
138 // Output.
139 ?>
140 <div <?php echo acf_esc_attrs( $div ); ?>>
141 <?php acf_hidden_input( $hidden_input ); ?>
142 <?php acf_text_input( $text_input ); ?>
143 </div>
144 <?php
145 }
146
147
148 /**
149 * Create extra options for your field. This is rendered when editing a field.
150 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
151 *
152 * @type action
153 * @since ACF 3.6
154 * @date 23/01/13
155 *
156 * @param $field - an array holding all the field's data
157 */
158 function render_field_settings( $field ) {
159 global $wp_locale;
160
161 $d_m_Y = date_i18n( 'd/m/Y g:i a' );
162 $m_d_Y = date_i18n( 'm/d/Y g:i a' );
163 $F_j_Y = date_i18n( 'F j, Y g:i a' );
164 $Ymd = date_i18n( 'Y-m-d H:i:s' );
165
166 echo '<div class="acf-field-settings-split">';
167
168 acf_render_field_setting(
169 $field,
170 array(
171 'label' => __( 'Display Format', 'secure-custom-fields' ),
172 'hint' => __( 'The format displayed when editing a post', 'secure-custom-fields' ),
173 'type' => 'radio',
174 'name' => 'display_format',
175 'other_choice' => 1,
176 'choices' => array(
177 'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
178 'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
179 'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
180 'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
181 'other' => '<span>' . __( 'Custom:', 'secure-custom-fields' ) . '</span>',
182 ),
183 )
184 );
185
186 acf_render_field_setting(
187 $field,
188 array(
189 'label' => __( 'Return Format', 'secure-custom-fields' ),
190 'hint' => __( 'The format returned via template functions', 'secure-custom-fields' ),
191 'type' => 'radio',
192 'name' => 'return_format',
193 'other_choice' => 1,
194 'choices' => array(
195 'd/m/Y g:i a' => '<span>' . $d_m_Y . '</span><code>d/m/Y g:i a</code>',
196 'm/d/Y g:i a' => '<span>' . $m_d_Y . '</span><code>m/d/Y g:i a</code>',
197 'F j, Y g:i a' => '<span>' . $F_j_Y . '</span><code>F j, Y g:i a</code>',
198 'Y-m-d H:i:s' => '<span>' . $Ymd . '</span><code>Y-m-d H:i:s</code>',
199 'other' => '<span>' . __( 'Custom:', 'secure-custom-fields' ) . '</span>',
200 ),
201 )
202 );
203
204 echo '</div>';
205
206 acf_render_field_setting(
207 $field,
208 array(
209 'label' => __( 'Week Starts On', 'secure-custom-fields' ),
210 'instructions' => '',
211 'type' => 'select',
212 'name' => 'first_day',
213 'choices' => array_values( $wp_locale->weekday ),
214 )
215 );
216 }
217
218 /**
219 * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
220 *
221 * @type filter
222 * @since ACF 3.6
223 *
224 * @param mixed $value The value which was loaded from the database
225 * @param mixed $post_id The post_id from which the value was loaded
226 * @param array $field The field array holding all the field options
227 * @return mixed $value The modified value
228 */
229 public function format_value( $value, $post_id, $field ) {
230 return acf_format_date( $value, $field['return_format'] );
231 }
232
233
234 /**
235 * This filter is applied to the $field after it is loaded from the database
236 * and ensures the return and display values are set.
237 *
238 * @type filter
239 * @since ACF 5.11.0
240 *
241 * @param array $field The field array holding all the field options.
242 * @return array
243 */
244 public function load_field( $field ) {
245 if ( empty( $field['display_format'] ) ) {
246 $field['display_format'] = $this->defaults['display_format'];
247 }
248
249 if ( empty( $field['return_format'] ) ) {
250 $field['return_format'] = $this->defaults['return_format'];
251 }
252
253 return $field;
254 }
255
256 /**
257 * Return the schema array for the REST API.
258 *
259 * @param array $field
260 * @return array
261 */
262 public function get_rest_schema( array $field ) {
263 return array(
264 'type' => array( 'string', 'null' ),
265 'description' => 'A `Y-m-d H:i:s` formatted date string.',
266 'required' => ! empty( $field['required'] ),
267 );
268 }
269 }
270
271
272 // initialize
273 acf_register_field_type( 'acf_field_date_and_time_picker' );
274 endif; // class_exists check
275
276 ?>
277