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_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_picker.php
316 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_date_picker' ) ) :
4
5 class acf_field_date_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_picker';
22 $this->label = __( 'Date Picker', 'secure-custom-fields' );
23 $this->category = 'advanced';
24 $this->description = __( 'An interactive UI for picking a date. 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-picker.png';
26 $this->doc_url = 'https://developer.wordpress.org/secure-custom-fields/features/fields/date-picker/';
27 $this->tutorial_url = 'https://developer.wordpress.org/secure-custom-fields/features/fields/date-picker/date-picker-tutorial/';
28 $this->defaults = array(
29 'display_format' => 'd/m/Y',
30 'return_format' => 'd/m/Y',
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_datepicker' ) ) {
50 return;
51 }
52
53 // localize
54 global $wp_locale;
55 acf_localize_data(
56 array(
57 'datePickerL10n' => array(
58 'closeText' => _x( 'Done', 'Date Picker JS closeText', 'secure-custom-fields' ),
59 'currentText' => _x( 'Today', 'Date Picker JS currentText', 'secure-custom-fields' ),
60 'nextText' => _x( 'Next', 'Date Picker JS nextText', 'secure-custom-fields' ),
61 'prevText' => _x( 'Prev', 'Date Picker JS prevText', 'secure-custom-fields' ),
62 'weekHeader' => _x( 'Wk', 'Date Picker JS weekHeader', 'secure-custom-fields' ),
63 'monthNames' => array_values( $wp_locale->month ),
64 'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
65 'dayNames' => array_values( $wp_locale->weekday ),
66 'dayNamesMin' => array_values( $wp_locale->weekday_initial ),
67 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ),
68 ),
69 )
70 );
71
72 // script
73 wp_enqueue_script( 'jquery-ui-datepicker' );
74
75 // style
76 wp_enqueue_style( 'acf-datepicker', acf_get_url( 'assets/inc/datepicker/jquery-ui.min.css' ), array(), '1.11.4' );
77 }
78
79
80 /**
81 * Create the HTML interface for your field
82 *
83 * @param $field - an array holding all the field's data
84 *
85 * @type action
86 * @since ACF 3.6
87 * @date 23/01/13
88 */
89 function render_field( $field ) {
90
91 // vars
92 $hidden_value = '';
93 $display_value = '';
94
95 // format value
96 if ( $field['value'] ) {
97 $hidden_value = acf_format_date( $field['value'], 'Ymd' );
98 $display_value = acf_format_date( $field['value'], $field['display_format'] );
99 }
100
101 // elements
102 $div = array(
103 'class' => 'acf-date-picker acf-input-wrap',
104 'data-date_format' => acf_convert_date_to_js( $field['display_format'] ),
105 'data-first_day' => $field['first_day'],
106 );
107 $hidden_input = array(
108 'id' => $field['id'],
109 'name' => $field['name'],
110 'value' => $hidden_value,
111 );
112 $text_input = array(
113 'class' => $field['class'] . ' input',
114 'value' => $display_value,
115 );
116
117 // special attributes
118 foreach ( array( 'readonly', 'disabled' ) as $k ) {
119 if ( ! empty( $field[ $k ] ) ) {
120 $hidden_input[ $k ] = $k;
121 $text_input[ $k ] = $k;
122 }
123 }
124
125 // save_format - compatibility with ACF < 5.0.0
126 if ( ! empty( $field['save_format'] ) ) {
127
128 // add custom JS save format
129 $div['data-save_format'] = $field['save_format'];
130
131 // revert hidden input value to raw DB value
132 $hidden_input['value'] = $field['value'];
133
134 // remove formatted value (will do this via JS)
135 $text_input['value'] = '';
136 }
137
138 // html
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' );
162 $m_d_Y = date_i18n( 'm/d/Y' );
163 $F_j_Y = date_i18n( 'F j, Y' );
164 $Ymd = date_i18n( 'Ymd' );
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' => '<span>' . $d_m_Y . '</span><code>d/m/Y</code>',
178 'm/d/Y' => '<span>' . $m_d_Y . '</span><code>m/d/Y</code>',
179 'F j, Y' => '<span>' . $F_j_Y . '</span><code>F j, Y</code>',
180 'other' => '<span>' . __( 'Custom:', 'secure-custom-fields' ) . '</span>',
181 ),
182 )
183 );
184
185 // save_format - compatibility with ACF < 5.0.0
186 if ( ! empty( $field['save_format'] ) ) {
187 acf_render_field_setting(
188 $field,
189 array(
190 'label' => __( 'Save Format', 'secure-custom-fields' ),
191 'hint' => __( 'The format used when saving a value', 'secure-custom-fields' ),
192 'type' => 'text',
193 'name' => 'save_format',
194 // 'readonly' => 1 // this setting was not readonly in v4
195 )
196 );
197 } else {
198 acf_render_field_setting(
199 $field,
200 array(
201 'label' => __( 'Return Format', 'secure-custom-fields' ),
202 'hint' => __( 'The format returned via template functions', 'secure-custom-fields' ),
203 'type' => 'radio',
204 'name' => 'return_format',
205 'other_choice' => 1,
206 'choices' => array(
207 'd/m/Y' => '<span>' . $d_m_Y . '</span><code>d/m/Y</code>',
208 'm/d/Y' => '<span>' . $m_d_Y . '</span><code>m/d/Y</code>',
209 'F j, Y' => '<span>' . $F_j_Y . '</span><code>F j, Y</code>',
210 'Ymd' => '<span>' . $Ymd . '</span><code>Ymd</code>',
211 'other' => '<span>' . __( 'Custom:', 'secure-custom-fields' ) . '</span>',
212 ),
213 )
214 );
215 }
216
217 echo '</div>';
218
219 acf_render_field_setting(
220 $field,
221 array(
222 'label' => __( 'Week Starts On', 'secure-custom-fields' ),
223 'instructions' => '',
224 'type' => 'select',
225 'name' => 'first_day',
226 'choices' => array_values( $wp_locale->weekday ),
227 )
228 );
229 }
230
231 /**
232 * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
233 *
234 * @type filter
235 * @since ACF 3.6
236 * @date 23/01/13
237 *
238 * @param $value (mixed) the value which was loaded from the database
239 * @param $post_id (mixed) the post_id from which the value was loaded
240 * @param $field (array) the field array holding all the field options
241 *
242 * @return $value (mixed) the modified value
243 */
244 function format_value( $value, $post_id, $field ) {
245
246 // save_format - compatibility with ACF < 5.0.0
247 if ( ! empty( $field['save_format'] ) ) {
248 return $value;
249 }
250
251 // return
252 return acf_format_date( $value, $field['return_format'] );
253 }
254
255
256 /**
257 * This filter is applied to the $field after it is loaded from the database
258 * and ensures the return and display values are set.
259 *
260 * @type filter
261 * @since ACF 5.11.0
262 * @date 28/09/21
263 *
264 * @param array $field The field array holding all the field options.
265 * @return array
266 */
267 public function load_field( $field ) {
268 if ( empty( $field['display_format'] ) ) {
269 $field['display_format'] = $this->defaults['display_format'];
270 }
271
272 if ( empty( $field['return_format'] ) ) {
273 $field['return_format'] = $this->defaults['return_format'];
274 }
275
276 return $field;
277 }
278
279 /**
280 * Return the schema array for the REST API.
281 *
282 * @param array $field The field array
283 * @return array
284 */
285 public function get_rest_schema( array $field ) {
286 return array(
287 'type' => array( 'string', 'null' ),
288 'description' => 'A `Ymd` formatted date string.',
289 'required' => ! empty( $field['required'] ),
290 );
291 }
292
293 /**
294 * Apply basic formatting to prepare the value for default REST output.
295 *
296 * @param mixed $value
297 * @param string|integer $post_id
298 * @param array $field
299 * @return mixed
300 */
301 public function format_value_for_rest( $value, $post_id, array $field ) {
302 if ( ! $value ) {
303 return null;
304 }
305
306 return (string) $value;
307 }
308 }
309
310
311 // initialize
312 acf_register_field_type( 'acf_field_date_picker' );
313 endif; // class_exists check
314
315 ?>
316