admin
3 years ago
field-groups
3 years ago
fields
3 years ago
fields-settings
3 years ago
locations
3 years ago
modules
3 years ago
screens
3 years ago
acfe-field-functions.php
3 years ago
acfe-field-group-functions.php
3 years ago
acfe-file-functions.php
3 years ago
acfe-form-functions.php
3 years ago
acfe-helper-functions.php
3 years ago
acfe-meta-functions.php
3 years ago
acfe-post-functions.php
3 years ago
acfe-screen-functions.php
3 years ago
acfe-template-functions.php
3 years ago
acfe-term-functions.php
3 years ago
acfe-user-functions.php
3 years ago
acfe-wp-functions.php
3 years ago
assets.php
3 years ago
compatibility.php
3 years ago
field-extend.php
3 years ago
field.php
3 years ago
hooks.php
3 years ago
init.php
3 years ago
local-meta.php
3 years ago
multilang.php
3 years ago
settings.php
3 years ago
third-party.php
3 years ago
upgrades.php
3 years ago
compatibility.php
582 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_compatibility')): |
| 8 | |
| 9 | class acfe_compatibility{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | // global |
| 17 | add_action('acf/init', array($this, 'init'), 98); |
| 18 | |
| 19 | // fields |
| 20 | add_filter('acf/validate_field_group', array($this, 'field_group_location_list'), 20); |
| 21 | add_filter('acf/validate_field', array($this, 'field_acfe_update'), 20); |
| 22 | add_filter('acf/validate_field/type=group', array($this, 'field_seamless_style'), 20); |
| 23 | add_filter('acf/validate_field/type=clone', array($this, 'field_seamless_style'), 20); |
| 24 | add_filter('acf/validate_field/type=acfe_dynamic_message', array($this, 'field_dynamic_message'), 20); |
| 25 | add_filter('acf/validate_field/type=acfe_column', array($this, 'field_column'), 20); |
| 26 | add_filter('acf/validate_field/type=image', array($this, 'field_image'), 20); |
| 27 | add_filter('acf/validate_field/type=file', array($this, 'field_image'), 20); |
| 28 | add_filter('acfe/load_fields/type=flexible_content', array($this, 'field_flexible_settings_title'), 20, 2); |
| 29 | add_filter('acf/prepare_field/name=acfe_flexible_category', array($this, 'field_flexible_layout_categories'), 10, 2); |
| 30 | |
| 31 | // modules |
| 32 | add_filter('acfe/form/import_args', array($this, 'acfe_form_import'), 10, 3); |
| 33 | |
| 34 | } |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * init |
| 39 | * |
| 40 | * acf/init:98 |
| 41 | * |
| 42 | * Rename modules |
| 43 | * |
| 44 | * @since 0.8 (20/10/2019) |
| 45 | */ |
| 46 | function init(){ |
| 47 | |
| 48 | // settings list |
| 49 | $settings = array( |
| 50 | 'acfe_php' => 'acfe/php', |
| 51 | 'php_save' => 'acfe/php_save', |
| 52 | 'php_load' => 'acfe/php_load', |
| 53 | 'php_found' => 'acfe/php_found', |
| 54 | 'acfe/modules/dynamic_block_types' => 'acfe/modules/block_types', |
| 55 | 'acfe/modules/dynamic_forms' => 'acfe/modules/forms', |
| 56 | 'acfe/modules/dynamic_options_pages' => 'acfe/modules/options_pages', |
| 57 | 'acfe/modules/dynamic_post_types' => 'acfe/modules/post_types', |
| 58 | 'acfe/modules/dynamic_taxonomies' => 'acfe/modules/taxonomies', |
| 59 | ); |
| 60 | |
| 61 | // loop settings |
| 62 | foreach($settings as $old => $new){ |
| 63 | |
| 64 | if(acf_get_setting($old) !== null){ |
| 65 | acf_update_setting($new, acf_get_setting($old)); |
| 66 | } |
| 67 | |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * field_group_location_list |
| 75 | * |
| 76 | * acf/validate_field_group:20 |
| 77 | * |
| 78 | * Field Group Location: Archive renamed to List |
| 79 | * |
| 80 | * @since 0.8 (20/10/2019) |
| 81 | */ |
| 82 | function field_group_location_list($field_group){ |
| 83 | |
| 84 | if(!acf_maybe_get($field_group, 'location')){ |
| 85 | return $field_group; |
| 86 | } |
| 87 | |
| 88 | foreach($field_group['location'] as &$or){ |
| 89 | |
| 90 | foreach($or as &$and){ |
| 91 | |
| 92 | if(!isset($and['value'])){ |
| 93 | continue; |
| 94 | } |
| 95 | |
| 96 | // Post Type List |
| 97 | if($and['param'] === 'post_type' && acfe_ends_with($and['value'], '_archive')){ |
| 98 | |
| 99 | $and['param'] = 'post_type_list'; |
| 100 | $and['value'] = substr_replace($and['value'], '', -8); |
| 101 | |
| 102 | } |
| 103 | |
| 104 | // Taxonomy List |
| 105 | elseif($and['param'] === 'taxonomy' && acfe_ends_with($and['value'], '_archive')){ |
| 106 | |
| 107 | $and['param'] = 'taxonomy_list'; |
| 108 | $and['value'] = substr_replace($and['value'], '', -8); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | } |
| 113 | |
| 114 | } |
| 115 | |
| 116 | return $field_group; |
| 117 | |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * field_acfe_update |
| 123 | * |
| 124 | * acf/validate_field:20 |
| 125 | * |
| 126 | * Field Filter Value: Removed |
| 127 | * |
| 128 | * @since 0.8 (20/10/2019) |
| 129 | */ |
| 130 | function field_acfe_update($field){ |
| 131 | |
| 132 | if(isset($field['acfe_update'])){ |
| 133 | unset($field['acfe_update']); |
| 134 | } |
| 135 | |
| 136 | return $field; |
| 137 | |
| 138 | } |
| 139 | |
| 140 | |
| 141 | /** |
| 142 | * field_seamless_style |
| 143 | * |
| 144 | * acf/validate_field/type=group:20 |
| 145 | * acf/validate_field/type=clone:20 |
| 146 | * |
| 147 | * Field Group/Clone: Fixed typo 'Seamless' |
| 148 | * |
| 149 | * @since 0.8.5 (15/03/2020) |
| 150 | */ |
| 151 | function field_seamless_style($field){ |
| 152 | |
| 153 | if($seamless = acf_maybe_get($field, 'acfe_seemless_style', false)){ |
| 154 | $field['acfe_seamless_style'] = $seamless; |
| 155 | } |
| 156 | |
| 157 | return $field; |
| 158 | |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * field_dynamic_message |
| 164 | * |
| 165 | * acf/validate_field/type=acfe_dynamic_message:20 |
| 166 | * |
| 167 | * Renamed 'Dynamic Message' field to 'Dynamic Render' |
| 168 | * |
| 169 | * @since 0.8.8.5 (03/09/2021) |
| 170 | */ |
| 171 | function field_dynamic_message($field){ |
| 172 | |
| 173 | $field['type'] = 'acfe_dynamic_render'; |
| 174 | |
| 175 | return $field; |
| 176 | |
| 177 | } |
| 178 | |
| 179 | |
| 180 | /** |
| 181 | * field_column |
| 182 | * |
| 183 | * acf/validate_field/type=acfe_column:20 |
| 184 | * |
| 185 | * Changed columns to 12 grid instead of 6 |
| 186 | * |
| 187 | * @since 0.8.7.3 (29/09/2020) |
| 188 | */ |
| 189 | function field_column($field){ |
| 190 | |
| 191 | if(acfe_ends_with($field['columns'], '/6')){ |
| 192 | |
| 193 | switch($field['columns']){ |
| 194 | |
| 195 | case '1/6': { |
| 196 | $field['columns'] = '2/12'; |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | case '2/6': { |
| 201 | $field['columns'] = '4/12'; |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | case '3/6': { |
| 206 | $field['columns'] = '6/12'; |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | case '4/6': { |
| 211 | $field['columns'] = '8/12'; |
| 212 | break; |
| 213 | } |
| 214 | |
| 215 | case '5/6': { |
| 216 | $field['columns'] = '10/12'; |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | case '6/6': { |
| 221 | $field['columns'] = '12/12'; |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | } |
| 226 | |
| 227 | } |
| 228 | |
| 229 | return $field; |
| 230 | |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /** |
| 235 | * field_image |
| 236 | * |
| 237 | * acf/validate_field/type=image:20 |
| 238 | * acf/validate_field/type=file:20 |
| 239 | * |
| 240 | * Renamed setting 'acfe_uploader' to 'uploader' for image & file |
| 241 | * |
| 242 | * @since 0.8.7.5 (11/12/2020) |
| 243 | */ |
| 244 | function field_image($field){ |
| 245 | |
| 246 | if(acf_maybe_get($field, 'acfe_uploader')){ |
| 247 | |
| 248 | $field['uploader'] = $field['acfe_uploader']; |
| 249 | unset($field['acfe_uploader']); |
| 250 | |
| 251 | } |
| 252 | |
| 253 | return $field; |
| 254 | |
| 255 | } |
| 256 | |
| 257 | |
| 258 | /** |
| 259 | * field_flexible_settings_title |
| 260 | * |
| 261 | * acfe/load_fields/type=flexible_content:20 |
| 262 | * |
| 263 | * Field Flexible Content: Fix duplicated "layout_settings" & "layout_title" |
| 264 | * |
| 265 | * @since 0.8.4.5 (11/02/2020) |
| 266 | */ |
| 267 | function field_flexible_settings_title($fields, $parent){ |
| 268 | |
| 269 | // Check if is tool screen |
| 270 | if(!acf_is_screen(acfe_get_acf_screen_id('acf-tools'))){ |
| 271 | return $fields; |
| 272 | } |
| 273 | |
| 274 | foreach($fields as $_k => $_field){ |
| 275 | |
| 276 | // field name |
| 277 | $_field_name = acf_maybe_get($_field, 'name'); |
| 278 | |
| 279 | // check 'acfe_flexible_layout_title' & 'layout_settings' |
| 280 | if($_field_name !== 'acfe_flexible_layout_title' && $_field_name !== 'layout_settings'){ |
| 281 | continue; |
| 282 | } |
| 283 | |
| 284 | // unset |
| 285 | unset($fields[$_k]); |
| 286 | |
| 287 | } |
| 288 | |
| 289 | return $fields; |
| 290 | |
| 291 | } |
| 292 | |
| 293 | |
| 294 | /** |
| 295 | * field_flexible_layout_categories |
| 296 | * |
| 297 | * acf/prepare_field/name=acfe_flexible_category |
| 298 | * |
| 299 | * Field Flexible Content: Compatibility for Layout Categories |
| 300 | * |
| 301 | * @since 0.8.6.7 (16/07/2020) |
| 302 | */ |
| 303 | function field_flexible_layout_categories($field){ |
| 304 | |
| 305 | $value = acf_maybe_get($field, 'value'); |
| 306 | |
| 307 | if(empty($value)){ |
| 308 | return $field; |
| 309 | } |
| 310 | |
| 311 | if(is_string($value)){ |
| 312 | |
| 313 | $explode = explode('|', $value); |
| 314 | |
| 315 | $choices = array(); |
| 316 | |
| 317 | foreach($explode as $v){ |
| 318 | |
| 319 | $v = trim($v); |
| 320 | $choices[ $v ] = $v; |
| 321 | |
| 322 | } |
| 323 | |
| 324 | $field['choices'] = $choices; |
| 325 | $field['value'] = $choices; |
| 326 | |
| 327 | } |
| 328 | |
| 329 | return $field; |
| 330 | |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /** |
| 335 | * acfe_form_import |
| 336 | * |
| 337 | * acfe/form/import_args |
| 338 | * |
| 339 | * Module Dynamic Forms: Upgrade previous versions |
| 340 | * |
| 341 | * @since 0.8.5 (15/03/2020) |
| 342 | */ |
| 343 | function acfe_form_import($args, $name, $post_id){ |
| 344 | |
| 345 | // ACF Extended: 0.8.5 Compatibility - Step 1 |
| 346 | // Groups upgrade |
| 347 | $has_upgraded = false; |
| 348 | |
| 349 | $rules = array( |
| 350 | |
| 351 | // Post: title |
| 352 | array( |
| 353 | 'group' => 'field_acfe_form_post_save_post_title_group', |
| 354 | 'sub_field' => 'field_acfe_form_post_save_post_title', |
| 355 | 'sub_field_custom' => 'field_acfe_form_post_save_post_title_custom', |
| 356 | ), |
| 357 | |
| 358 | // Post: name |
| 359 | array( |
| 360 | 'group' => 'field_acfe_form_post_save_post_name_group', |
| 361 | 'sub_field' => 'field_acfe_form_post_save_post_name', |
| 362 | 'sub_field_custom' => 'field_acfe_form_post_save_post_name_custom', |
| 363 | ), |
| 364 | |
| 365 | // Term: name |
| 366 | array( |
| 367 | 'group' => 'field_acfe_form_term_save_name_group', |
| 368 | 'sub_field' => 'field_acfe_form_term_save_name', |
| 369 | 'sub_field_custom' => 'field_acfe_form_term_save_name_custom', |
| 370 | ), |
| 371 | |
| 372 | // Term: slug |
| 373 | array( |
| 374 | 'group' => 'field_acfe_form_term_save_slug_group', |
| 375 | 'sub_field' => 'field_acfe_form_term_save_slug', |
| 376 | 'sub_field_custom' => 'field_acfe_form_term_save_slug_custom', |
| 377 | ), |
| 378 | |
| 379 | // User: e-mail |
| 380 | array( |
| 381 | 'group' => 'field_acfe_form_user_save_email_group', |
| 382 | 'sub_field' => 'field_acfe_form_user_save_email', |
| 383 | 'sub_field_custom' => 'field_acfe_form_user_save_email_custom', |
| 384 | ), |
| 385 | |
| 386 | // User: username |
| 387 | array( |
| 388 | 'group' => 'field_acfe_form_user_save_username_group', |
| 389 | 'sub_field' => 'field_acfe_form_user_save_username', |
| 390 | 'sub_field_custom' => 'field_acfe_form_user_save_username_custom', |
| 391 | ), |
| 392 | |
| 393 | // User: password |
| 394 | array( |
| 395 | 'group' => 'field_acfe_form_user_save_password_group', |
| 396 | 'sub_field' => 'field_acfe_form_user_save_password', |
| 397 | 'sub_field_custom' => 'field_acfe_form_user_save_password_custom', |
| 398 | ), |
| 399 | |
| 400 | // User: first name |
| 401 | array( |
| 402 | 'group' => 'field_acfe_form_user_save_first_name_group', |
| 403 | 'sub_field' => 'field_acfe_form_user_save_first_name', |
| 404 | 'sub_field_custom' => 'field_acfe_form_user_save_first_name_custom', |
| 405 | ), |
| 406 | |
| 407 | // User: last name |
| 408 | array( |
| 409 | 'group' => 'field_acfe_form_user_save_last_name_group', |
| 410 | 'sub_field' => 'field_acfe_form_user_save_last_name', |
| 411 | 'sub_field_custom' => 'field_acfe_form_user_save_last_name_custom', |
| 412 | ), |
| 413 | |
| 414 | // User: nickname |
| 415 | array( |
| 416 | 'group' => 'field_acfe_form_user_save_nickname_group', |
| 417 | 'sub_field' => 'field_acfe_form_user_save_nickname', |
| 418 | 'sub_field_custom' => 'field_acfe_form_user_save_nickname_custom', |
| 419 | ), |
| 420 | |
| 421 | // User: display name |
| 422 | array( |
| 423 | 'group' => 'field_acfe_form_user_save_display_name_group', |
| 424 | 'sub_field' => 'field_acfe_form_user_save_display_name', |
| 425 | 'sub_field_custom' => 'field_acfe_form_user_save_display_name_custom', |
| 426 | ), |
| 427 | |
| 428 | // User: website |
| 429 | array( |
| 430 | 'group' => 'field_acfe_form_user_save_website_group', |
| 431 | 'sub_field' => 'field_acfe_form_user_save_website', |
| 432 | 'sub_field_custom' => 'field_acfe_form_user_save_website_custom', |
| 433 | ), |
| 434 | |
| 435 | ); |
| 436 | |
| 437 | foreach($args['acfe_form_actions'] as &$row){ |
| 438 | |
| 439 | foreach($rules as $rule){ |
| 440 | |
| 441 | if(!acf_maybe_get($row, $rule['group'])){ |
| 442 | continue; |
| 443 | } |
| 444 | |
| 445 | $value = null; |
| 446 | $group = $row[$rule['group']]; |
| 447 | |
| 448 | if(acf_maybe_get($group, $rule['sub_field']) === 'custom'){ |
| 449 | $value = acf_maybe_get($group, $rule['sub_field_custom']); |
| 450 | |
| 451 | }else{ |
| 452 | $value = acf_maybe_get($group, $rule['sub_field']); |
| 453 | } |
| 454 | |
| 455 | unset($row[$rule['group']]); |
| 456 | |
| 457 | $row[ $rule['sub_field'] ] = $value; |
| 458 | |
| 459 | $has_upgraded = true; |
| 460 | |
| 461 | } |
| 462 | |
| 463 | } |
| 464 | |
| 465 | // ACF Extended: 0.8.5 Compatibility - Step 2 |
| 466 | // Field mapping upgrade |
| 467 | if($has_upgraded){ |
| 468 | |
| 469 | // Rules |
| 470 | $rules = array( |
| 471 | |
| 472 | array( |
| 473 | 'load_values' => 'field_acfe_form_post_load_values', |
| 474 | 'fields' => array( |
| 475 | 'field_acfe_form_post_map_post_type' => 'field_acfe_form_post_save_post_type', |
| 476 | 'field_acfe_form_post_map_post_status' => 'field_acfe_form_post_save_post_status', |
| 477 | 'field_acfe_form_post_map_post_title' => 'field_acfe_form_post_save_post_title', |
| 478 | 'field_acfe_form_post_map_post_name' => 'field_acfe_form_post_save_post_name', |
| 479 | 'field_acfe_form_post_map_post_content' => 'field_acfe_form_post_save_post_content', |
| 480 | 'field_acfe_form_post_map_post_author' => 'field_acfe_form_post_save_post_author', |
| 481 | 'field_acfe_form_post_map_post_parent' => 'field_acfe_form_post_save_post_parent', |
| 482 | 'field_acfe_form_post_map_post_terms' => 'field_acfe_form_post_save_post_terms', |
| 483 | ) |
| 484 | ), |
| 485 | |
| 486 | array( |
| 487 | 'load_values' => 'field_acfe_form_term_load_values', |
| 488 | 'fields' => array( |
| 489 | 'field_acfe_form_term_map_name' => 'field_acfe_form_term_save_name', |
| 490 | 'field_acfe_form_term_map_slug' => 'field_acfe_form_term_save_slug', |
| 491 | 'field_acfe_form_term_map_taxonomy' => 'field_acfe_form_term_save_taxonomy', |
| 492 | 'field_acfe_form_term_map_parent' => 'field_acfe_form_term_save_parent', |
| 493 | 'field_acfe_form_term_map_description' => 'field_acfe_form_term_save_description', |
| 494 | ) |
| 495 | ), |
| 496 | |
| 497 | array( |
| 498 | 'load_values' => 'field_acfe_form_user_load_values', |
| 499 | 'fields' => array( |
| 500 | 'field_acfe_form_user_map_email' => 'field_acfe_form_user_save_email', |
| 501 | 'field_acfe_form_user_map_username' => 'field_acfe_form_user_save_username', |
| 502 | 'field_acfe_form_user_map_password' => 'field_acfe_form_user_save_password', |
| 503 | 'field_acfe_form_user_map_first_name' => 'field_acfe_form_user_save_first_name', |
| 504 | 'field_acfe_form_user_map_last_name' => 'field_acfe_form_user_save_last_name', |
| 505 | 'field_acfe_form_user_map_nickname' => 'field_acfe_form_user_save_nickname', |
| 506 | 'field_acfe_form_user_map_display_name' => 'field_acfe_form_user_save_display_name', |
| 507 | 'field_acfe_form_user_map_website' => 'field_acfe_form_user_save_website', |
| 508 | 'field_acfe_form_user_map_description' => 'field_acfe_form_user_save_description', |
| 509 | 'field_acfe_form_user_map_role' => 'field_acfe_form_user_save_role', |
| 510 | ) |
| 511 | ), |
| 512 | |
| 513 | ); |
| 514 | |
| 515 | foreach($args['acfe_form_actions'] as &$row){ |
| 516 | |
| 517 | foreach($rules as $rule){ |
| 518 | |
| 519 | $load_values = acf_maybe_get($row, $rule['load_values']); |
| 520 | $fields = $rule['fields']; |
| 521 | |
| 522 | if(!empty($load_values)){ |
| 523 | continue; |
| 524 | } |
| 525 | |
| 526 | foreach($fields as $map => $save){ |
| 527 | |
| 528 | $map_value = acf_maybe_get($row, $map); |
| 529 | |
| 530 | if(empty($map_value)){ |
| 531 | continue; |
| 532 | } |
| 533 | |
| 534 | switch($save){ |
| 535 | |
| 536 | case 'field_acfe_form_post_save_post_content': { |
| 537 | |
| 538 | $row['field_acfe_form_post_save_post_content_group'][ $save ] = $map_value; |
| 539 | break; |
| 540 | |
| 541 | } |
| 542 | |
| 543 | case 'field_acfe_form_term_save_description': { |
| 544 | |
| 545 | $row['field_acfe_form_term_save_description_group'][ $save ] = $map_value; |
| 546 | break; |
| 547 | |
| 548 | } |
| 549 | |
| 550 | case 'field_acfe_form_user_save_description': { |
| 551 | |
| 552 | $row['field_acfe_form_user_save_description_group'][ $save ] = $map_value; |
| 553 | break; |
| 554 | |
| 555 | } |
| 556 | |
| 557 | default: { |
| 558 | |
| 559 | $row[ $save ] = $map_value; |
| 560 | break; |
| 561 | |
| 562 | } |
| 563 | |
| 564 | } |
| 565 | |
| 566 | } |
| 567 | |
| 568 | } |
| 569 | |
| 570 | } |
| 571 | |
| 572 | } |
| 573 | |
| 574 | return $args; |
| 575 | |
| 576 | } |
| 577 | |
| 578 | } |
| 579 | |
| 580 | new acfe_compatibility(); |
| 581 | |
| 582 | endif; |