PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.0-beta2
Secure Custom Fields v6.4.0-beta2
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 / compatibility.php
secure-custom-fields / includes Last commit date
Blocks 1 year ago admin 1 year ago ajax 1 year ago api 1 year ago fields 1 year ago forms 1 year ago legacy 1 year ago locations 1 year ago post-types 1 year ago rest-api 1 year ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 1 year ago acf-field-group-functions.php 1 year ago acf-form-functions.php 1 year ago acf-helper-functions.php 1 year ago acf-hook-functions.php 1 year ago acf-input-functions.php 1 year ago acf-internal-post-type-functions.php 1 year ago acf-meta-functions.php 1 year ago acf-post-functions.php 1 year ago acf-post-type-functions.php 1 year ago acf-taxonomy-functions.php 1 year ago acf-user-functions.php 1 year ago acf-utility-functions.php 1 year ago acf-value-functions.php 1 year ago acf-wp-functions.php 1 year ago assets.php 1 year ago class-acf-data.php 1 year ago class-acf-internal-post-type.php 1 year ago class-acf-site-health.php 1 year ago compatibility.php 1 year ago deprecated.php 1 year ago fields.php 1 year ago index.php 1 year ago l10n.php 1 year ago local-fields.php 1 year ago local-json.php 1 year ago local-meta.php 1 year ago locations.php 1 year ago loop.php 1 year ago media.php 1 year ago rest-api.php 1 year ago revisions.php 1 year ago third-party.php 1 year ago upgrades.php 1 year ago validation.php 1 year ago wpml.php 1 year ago
compatibility.php
483 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Compatibility' ) ) :
8
9 class ACF_Compatibility {
10
11 /**
12 * __construct
13 *
14 * Sets up the class functionality.
15 *
16 * @date 30/04/2014
17 * @since 5.0.0
18 *
19 * @param void
20 * @return void
21 */
22 function __construct() {
23
24 // actions
25 add_filter( 'acf/validate_field', array( $this, 'validate_field' ), 20, 1 );
26 add_filter( 'acf/validate_field/type=textarea', array( $this, 'validate_textarea_field' ), 20, 1 );
27 add_filter( 'acf/validate_field/type=relationship', array( $this, 'validate_relationship_field' ), 20, 1 );
28 add_filter( 'acf/validate_field/type=post_object', array( $this, 'validate_relationship_field' ), 20, 1 );
29 add_filter( 'acf/validate_field/type=page_link', array( $this, 'validate_relationship_field' ), 20, 1 );
30 add_filter( 'acf/validate_field/type=image', array( $this, 'validate_image_field' ), 20, 1 );
31 add_filter( 'acf/validate_field/type=file', array( $this, 'validate_image_field' ), 20, 1 );
32 add_filter( 'acf/validate_field/type=wysiwyg', array( $this, 'validate_wysiwyg_field' ), 20, 1 );
33 add_filter( 'acf/validate_field/type=date_picker', array( $this, 'validate_date_picker_field' ), 20, 1 );
34 add_filter( 'acf/validate_field/type=taxonomy', array( $this, 'validate_taxonomy_field' ), 20, 1 );
35 add_filter( 'acf/validate_field/type=date_time_picker', array( $this, 'validate_date_time_picker_field' ), 20, 1 );
36 add_filter( 'acf/validate_field/type=user', array( $this, 'validate_user_field' ), 20, 1 );
37 add_filter( 'acf/validate_field_group', array( $this, 'validate_field_group' ), 20, 1 );
38
39 // Modify field wrapper attributes
40 add_filter( 'acf/field_wrapper_attributes', array( $this, 'field_wrapper_attributes' ), 20, 2 );
41
42 // location
43 add_filter( 'acf/location/validate_rule/type=post_taxonomy', array( $this, 'validate_post_taxonomy_location_rule' ), 20, 1 );
44 add_filter( 'acf/location/validate_rule/type=post_category', array( $this, 'validate_post_taxonomy_location_rule' ), 20, 1 );
45
46 // Update settings
47 add_action( 'acf/init', array( $this, 'init' ) );
48 }
49
50 /**
51 * init
52 *
53 * Adds compatibility for deprecated settings.
54 *
55 * @date 10/6/19
56 * @since 5.8.1
57 *
58 * @param void
59 * @return void
60 */
61 function init() {
62
63 // Update "show_admin" setting based on defined constant.
64 if ( defined( 'ACF_LITE' ) && ACF_LITE ) {
65 acf_update_setting( 'show_admin', false );
66 }
67 }
68
69 /**
70 * field_wrapper_attributes
71 *
72 * Adds compatibility with deprecated field wrap attributes.
73 *
74 * @date 21/1/19
75 * @since 5.7.10
76 *
77 * @param array $wrapper The wrapper attributes array.
78 * @param array $field The field array.
79 */
80 function field_wrapper_attributes( $wrapper, $field ) {
81
82 // Check compatibility setting.
83 if ( acf_get_compatibility( 'field_wrapper_class' ) ) {
84 $wrapper['class'] .= " field_type-{$field['type']}";
85 if ( $field['key'] ) {
86 $wrapper['class'] .= " field_key-{$field['key']}";
87 }
88 }
89
90 // Return wrapper.
91 return $wrapper;
92 }
93
94 /**
95 * validate_field
96 *
97 * Adds compatibility with deprecated settings
98 *
99 * @date 23/04/2014
100 * @since 5.0.0
101 *
102 * @param array $field The field array.
103 * @return array $field
104 */
105 function validate_field( $field ) {
106
107 // conditional logic data structure changed to groups in version 5.0.0
108 // convert previous data (status, rules, allorany) into groups
109 if ( isset( $field['conditional_logic']['status'] ) ) {
110
111 // check status
112 if ( $field['conditional_logic']['status'] ) {
113 $field['conditional_logic'] = acf_convert_rules_to_groups( $field['conditional_logic']['rules'], $field['conditional_logic']['allorany'] );
114 } else {
115 $field['conditional_logic'] = 0;
116 }
117 }
118
119 // return
120 return $field;
121 }
122
123 /**
124 * validate_textarea_field
125 *
126 * Adds compatibility with deprecated settings
127 *
128 * @date 23/04/2014
129 * @since 5.0.0
130 *
131 * @param array $field The field array.
132 * @return array $field
133 */
134 function validate_textarea_field( $field ) {
135
136 // formatting has been removed
137 $formatting = acf_extract_var( $field, 'formatting' );
138 if ( $formatting === 'br' ) {
139 $field['new_lines'] = 'br';
140 }
141
142 // return
143 return $field;
144 }
145
146 /**
147 * validate_relationship_field
148 *
149 * Adds compatibility with deprecated settings
150 *
151 * @date 23/04/2014
152 * @since 5.0.0
153 *
154 * @param array $field The field array.
155 * @return array $field
156 */
157 function validate_relationship_field( $field ) {
158
159 // remove 'all' from post_type
160 if ( acf_in_array( 'all', $field['post_type'] ) ) {
161 $field['post_type'] = array();
162 }
163
164 // remove 'all' from taxonomy
165 if ( acf_in_array( 'all', $field['taxonomy'] ) ) {
166 $field['taxonomy'] = array();
167 }
168
169 // result_elements is now elements
170 if ( isset( $field['result_elements'] ) ) {
171 $field['elements'] = acf_extract_var( $field, 'result_elements' );
172 }
173
174 // return
175 return $field;
176 }
177
178 /**
179 * validate_image_field
180 *
181 * Adds compatibility with deprecated settings
182 *
183 * @date 23/04/2014
184 * @since 5.0.0
185 *
186 * @param array $field The field array.
187 * @return array $field
188 */
189 function validate_image_field( $field ) {
190
191 // save_format is now return_format
192 if ( isset( $field['save_format'] ) ) {
193 $field['return_format'] = acf_extract_var( $field, 'save_format' );
194 }
195
196 // object is now array
197 if ( $field['return_format'] == 'object' ) {
198 $field['return_format'] = 'array';
199 }
200
201 // return
202 return $field;
203 }
204
205 /**
206 * validate_wysiwyg_field
207 *
208 * Adds compatibility with deprecated settings
209 *
210 * @date 23/04/2014
211 * @since 5.0.0
212 *
213 * @param array $field The field array.
214 * @return array $field
215 */
216 function validate_wysiwyg_field( $field ) {
217
218 // media_upload is now numeric
219 if ( $field['media_upload'] === 'yes' ) {
220 $field['media_upload'] = 1;
221 } elseif ( $field['media_upload'] === 'no' ) {
222 $field['media_upload'] = 0;
223 }
224
225 // return
226 return $field;
227 }
228
229 /**
230 * validate_date_picker_field
231 *
232 * Adds compatibility with deprecated settings
233 *
234 * @date 23/04/2014
235 * @since 5.0.0
236 *
237 * @param array $field The field array.
238 * @return array $field
239 */
240 function validate_date_picker_field( $field ) {
241
242 // date_format has changed to display_format
243 if ( isset( $field['date_format'] ) ) {
244
245 // extract vars
246 $date_format = $field['date_format'];
247 $display_format = $field['display_format'];
248
249 // convert from js to php
250 $display_format = acf_convert_date_to_php( $display_format );
251
252 // append settings
253 $field['display_format'] = $display_format;
254 $field['save_format'] = $date_format;
255
256 // clean up
257 unset( $field['date_format'] );
258 }
259
260 // return
261 return $field;
262 }
263
264 /**
265 * validate_taxonomy_field
266 *
267 * Adds compatibility with deprecated settings
268 *
269 * @date 23/04/2014
270 * @since 5.2.7
271 *
272 * @param array $field The field array.
273 * @return array $field
274 */
275 function validate_taxonomy_field( $field ) {
276
277 // load_save_terms deprecated in favour of separate save_terms
278 if ( isset( $field['load_save_terms'] ) ) {
279 $field['save_terms'] = acf_extract_var( $field, 'load_save_terms' );
280 }
281
282 // return
283 return $field;
284 }
285
286 /**
287 * validate_date_time_picker_field
288 *
289 * Adds compatibility with deprecated settings
290 *
291 * @date 23/04/2014
292 * @since 5.2.7
293 *
294 * @param array $field The field array.
295 * @return array $field
296 */
297 function validate_date_time_picker_field( $field ) {
298
299 // 3rd party date time picker
300 // https://github.com/soderlind/acf-field-date-time-picker
301 if ( ! empty( $field['time_format'] ) ) {
302
303 // extract vars
304 $time_format = acf_extract_var( $field, 'time_format' );
305 $date_format = acf_extract_var( $field, 'date_format' );
306 $get_as_timestamp = acf_extract_var( $field, 'get_as_timestamp' );
307
308 // convert from js to php
309 $time_format = acf_convert_time_to_php( $time_format );
310 $date_format = acf_convert_date_to_php( $date_format );
311
312 // append settings
313 $field['return_format'] = $date_format . ' ' . $time_format;
314 $field['display_format'] = $date_format . ' ' . $time_format;
315
316 // timestamp
317 if ( $get_as_timestamp === 'true' ) {
318 $field['return_format'] = 'U';
319 }
320 }
321
322 // return
323 return $field;
324 }
325
326 /**
327 * validate_user_field
328 *
329 * Adds compatibility with deprecated settings
330 *
331 * @date 23/04/2014
332 * @since 5.2.7
333 *
334 * @param array $field The field array.
335 * @return array $field
336 */
337 function validate_user_field( $field ) {
338
339 // remove 'all' from roles
340 if ( acf_in_array( 'all', $field['role'] ) ) {
341 $field['role'] = '';
342 }
343
344 // field_type removed in favour of multiple
345 if ( isset( $field['field_type'] ) ) {
346
347 // extract vars
348 $field_type = acf_extract_var( $field, 'field_type' );
349
350 // multiple
351 if ( $field_type === 'multi_select' ) {
352 $field['multiple'] = true;
353 }
354 }
355
356 // return
357 return $field;
358 }
359
360 /**
361 * This function will provide compatibility with ACF4 field groups
362 *
363 * @type function
364 * @date 23/04/2014
365 * @since 5.0.0
366 *
367 * @param $field_group (array)
368 * @return $field_group
369 */
370 function validate_field_group( $field_group ) {
371
372 // vars
373 $version = 5;
374
375 // field group key was added in version 5.0.0
376 // detect ACF4 data and generate key
377 if ( ! $field_group['key'] ) {
378 $version = 4;
379 $field_group['key'] = isset( $field_group['id'] ) ? "group_{$field_group['id']}" : uniqid( 'group_' );
380 }
381
382 // prior to version 5.0.0, settings were saved in an 'options' array
383 // extract and merge options into the field group
384 if ( isset( $field_group['options'] ) ) {
385 $options = acf_extract_var( $field_group, 'options' );
386 $field_group = array_merge( $field_group, $options );
387 }
388
389 // location data structure changed to groups in version 4.1.0
390 // convert previous data (rules, allorany) into groups
391 if ( isset( $field_group['location']['rules'] ) ) {
392 $field_group['location'] = acf_convert_rules_to_groups( $field_group['location']['rules'], $field_group['location']['allorany'] );
393 }
394
395 // some location rule names have changed in version 5.0.0
396 // loop over location data and modify rules
397 $replace = array(
398 'taxonomy' => 'post_taxonomy',
399 'ef_media' => 'attachment',
400 'ef_taxonomy' => 'taxonomy',
401 'ef_user' => 'user_role',
402 'user_type' => 'current_user_role', // 5.2.0
403 );
404
405 // only replace 'taxonomy' rule if is an ACF4 field group
406 if ( $version > 4 ) {
407 unset( $replace['taxonomy'] );
408 }
409
410 // loop over location groups
411 if ( $field_group['location'] ) {
412 foreach ( $field_group['location'] as $i => $group ) {
413
414 // loop over group rules
415 if ( $group ) {
416 foreach ( $group as $j => $rule ) {
417
418 // migrate param
419 if ( isset( $replace[ $rule['param'] ] ) ) {
420 $field_group['location'][ $i ][ $j ]['param'] = $replace[ $rule['param'] ];
421 }
422 }
423 }
424 }
425 }
426
427 // change layout to style (v5.0.0)
428 if ( isset( $field_group['layout'] ) ) {
429 $field_group['style'] = acf_extract_var( $field_group, 'layout' );
430 }
431
432 // change no_box to seamless (v5.0.0)
433 if ( $field_group['style'] === 'no_box' ) {
434 $field_group['style'] = 'seamless';
435 }
436
437 // return
438 return $field_group;
439 }
440
441 /**
442 * validate_post_taxonomy_location_rule
443 *
444 * description
445 *
446 * @date 27/8/18
447 * @since 5.7.4
448 *
449 * @param type $var Description. Default.
450 * @return type Description.
451 */
452 function validate_post_taxonomy_location_rule( $rule ) {
453
454 // previous versions of ACF (v4.4.12) saved value as term_id
455 // convert term_id into "taxonomy:slug" string
456 if ( is_numeric( $rule['value'] ) ) {
457 $term = acf_get_term( $rule['value'] );
458 if ( $term ) {
459 $rule['value'] = acf_encode_term( $term );
460 }
461 }
462
463 // return
464 return $rule;
465 }
466 }
467
468 acf_new_instance( 'ACF_Compatibility' );
469 endif; // class_exists check
470
471 /**
472 * Returns true if compatibility is enabled for the given component.
473 *
474 * @date 20/1/15
475 * @since 5.1.5
476 *
477 * @param string $name The name of the component to check.
478 * @return boolean
479 */
480 function acf_get_compatibility( $name ) {
481 return apply_filters( "acf/compatibility/{$name}", false );
482 }
483