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