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
upgrades.php
818 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_upgrades')): |
| 8 | |
| 9 | class acfe_upgrades{ |
| 10 | |
| 11 | public $upgrades = array( |
| 12 | 'do_0_8_5' => '0.8.5', |
| 13 | 'do_0_8_6' => '0.8.6', |
| 14 | 'do_0_8_8' => '0.8.8', |
| 15 | 'do_reset' => '0.0', |
| 16 | ); |
| 17 | |
| 18 | public $model = array( |
| 19 | 'version' => ACFE_VERSION, |
| 20 | 'modules' => array( |
| 21 | 'block_types' => array(), |
| 22 | 'options_pages' => array(), |
| 23 | 'post_types' => array(), |
| 24 | 'taxonomies' => array(), |
| 25 | ) |
| 26 | ); |
| 27 | |
| 28 | function __construct(){ |
| 29 | |
| 30 | $db_version = acfe_get_settings('version'); |
| 31 | |
| 32 | // Bail early |
| 33 | if(acf_version_compare($db_version, '>=', ACFE_VERSION)) |
| 34 | return; |
| 35 | |
| 36 | // Loop upgrades |
| 37 | foreach($this->upgrades as $upgrade_function => $upgrade_version){ |
| 38 | |
| 39 | if(acf_version_compare($upgrade_version, '<=', $db_version)) |
| 40 | continue; |
| 41 | |
| 42 | add_action('acf/init', array($this, $upgrade_function), 999); |
| 43 | |
| 44 | } |
| 45 | |
| 46 | $settings = acfe_get_settings(); |
| 47 | |
| 48 | $model = $this->parse_args_r($settings, $this->model); |
| 49 | $model['version'] = ACFE_VERSION; |
| 50 | |
| 51 | acfe_update_settings($model); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Reset Modules |
| 57 | */ |
| 58 | function do_reset(){ |
| 59 | |
| 60 | // Modules |
| 61 | acf_get_instance('acfe_dynamic_block_types')->reset(); |
| 62 | acf_get_instance('acfe_dynamic_options_pages')->reset(); |
| 63 | acf_get_instance('acfe_dynamic_post_types')->reset(); |
| 64 | acf_get_instance('acfe_dynamic_taxonomies')->reset(); |
| 65 | |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * ACF Extended: 0.8.8 |
| 70 | */ |
| 71 | function do_0_8_8(){ |
| 72 | |
| 73 | $tasks = array( |
| 74 | 'block_types', |
| 75 | 'options_pages', |
| 76 | 'post_types', |
| 77 | 'taxonomies', |
| 78 | 'clean', |
| 79 | ); |
| 80 | |
| 81 | foreach($tasks as $task){ |
| 82 | |
| 83 | /* |
| 84 | * Block Types |
| 85 | */ |
| 86 | if($task === 'block_types'){ |
| 87 | |
| 88 | $old = acfe_get_settings('modules.dynamic_block_type.data', array()); |
| 89 | $new = acfe_get_settings('modules.block_types', array()); |
| 90 | |
| 91 | // Check |
| 92 | if(empty($old)) |
| 93 | continue; |
| 94 | |
| 95 | // Log |
| 96 | acf_log('[ACF Extended] 0.8.8 Upgrade: Block Types'); |
| 97 | |
| 98 | // Update |
| 99 | acfe_update_settings('modules.block_types', array_merge($old, $new)); |
| 100 | |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Options Pages |
| 105 | */ |
| 106 | elseif($task === 'options_pages'){ |
| 107 | |
| 108 | $old = acfe_get_settings('modules.dynamic_option.data', array()); |
| 109 | $new = acfe_get_settings('modules.options_pages', array()); |
| 110 | |
| 111 | // Check |
| 112 | if(empty($old)) |
| 113 | continue; |
| 114 | |
| 115 | // Log |
| 116 | acf_log('[ACF Extended] 0.8.8 Upgrade: Options Pages'); |
| 117 | |
| 118 | // Update |
| 119 | acfe_update_settings('modules.options_pages', array_merge($old, $new)); |
| 120 | |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * Post Types |
| 125 | */ |
| 126 | elseif($task === 'post_types'){ |
| 127 | |
| 128 | $old = acfe_get_settings('modules.dynamic_post_type.data', array()); |
| 129 | $new = acfe_get_settings('modules.post_types', array()); |
| 130 | |
| 131 | // Check |
| 132 | if(empty($old)) |
| 133 | continue; |
| 134 | |
| 135 | // Log |
| 136 | acf_log('[ACF Extended] 0.8.8 Upgrade: Post Types'); |
| 137 | |
| 138 | // Update |
| 139 | acfe_update_settings('modules.post_types', array_merge($old, $new)); |
| 140 | |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Taxonomies |
| 145 | */ |
| 146 | elseif($task === 'taxonomies'){ |
| 147 | |
| 148 | $old = acfe_get_settings('modules.dynamic_taxonomy.data', array()); |
| 149 | $new = acfe_get_settings('modules.taxonomies', array()); |
| 150 | |
| 151 | // Check |
| 152 | if(empty($old)) |
| 153 | continue; |
| 154 | |
| 155 | // Log |
| 156 | acf_log('[ACF Extended] 0.8.8 Upgrade: Taxonomies'); |
| 157 | |
| 158 | // Update |
| 159 | acfe_update_settings('modules.taxonomies', array_merge($old, $new)); |
| 160 | |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Clean |
| 165 | */ |
| 166 | elseif($task === 'clean'){ |
| 167 | |
| 168 | acfe_delete_settings('modules.author'); |
| 169 | acfe_delete_settings('modules.dev'); |
| 170 | acfe_delete_settings('modules.meta'); |
| 171 | acfe_delete_settings('modules.option'); |
| 172 | acfe_delete_settings('modules.ui'); |
| 173 | acfe_delete_settings('modules.dynamic_block_type'); |
| 174 | acfe_delete_settings('modules.dynamic_form'); |
| 175 | acfe_delete_settings('modules.dynamic_option'); |
| 176 | acfe_delete_settings('modules.dynamic_post_type'); |
| 177 | acfe_delete_settings('modules.dynamic_taxonomy'); |
| 178 | acfe_delete_settings('upgrades'); |
| 179 | |
| 180 | } |
| 181 | |
| 182 | } |
| 183 | |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * ACF Extended: 0.8.6 |
| 188 | */ |
| 189 | function do_0_8_6(){ |
| 190 | |
| 191 | $get_options = get_posts(array( |
| 192 | 'post_type' => 'acfe-dop', |
| 193 | 'posts_per_page' => -1, |
| 194 | 'fields' => 'ids' |
| 195 | )); |
| 196 | |
| 197 | if(!empty($get_options)){ |
| 198 | |
| 199 | $updated = false; |
| 200 | |
| 201 | foreach($get_options as $post_id){ |
| 202 | |
| 203 | $menu_slug = get_field('menu_slug', $post_id); |
| 204 | $acfe_dop_name = get_field('acfe_dop_name', $post_id); |
| 205 | $post_name = get_post_field('post_name', $post_id); |
| 206 | |
| 207 | // Update empty 'menu_slug' fields in options pages |
| 208 | if(empty($menu_slug)){ |
| 209 | |
| 210 | // Page Title |
| 211 | $page_title = get_post_field('post_title', $post_id); |
| 212 | |
| 213 | // Menu Title |
| 214 | $menu_title = get_field('menu_title', $post_id); |
| 215 | |
| 216 | if(empty($menu_title)){ |
| 217 | |
| 218 | $menu_title = $page_title; |
| 219 | |
| 220 | } |
| 221 | |
| 222 | // Menu Slug |
| 223 | $menu_slug = sanitize_title($menu_title); |
| 224 | |
| 225 | // Update field |
| 226 | update_field('menu_slug', $menu_slug, $post_id); |
| 227 | |
| 228 | $updated = true; |
| 229 | |
| 230 | } |
| 231 | |
| 232 | // Upgrade old name to menu_slug |
| 233 | if($acfe_dop_name === $post_name){ |
| 234 | |
| 235 | // Get ACFE option |
| 236 | $option = acfe_get_settings('modules.options_pages', array()); |
| 237 | |
| 238 | // Check ACFE option |
| 239 | if(isset($option[$acfe_dop_name])){ |
| 240 | |
| 241 | $register_args = $option[$acfe_dop_name]; |
| 242 | |
| 243 | // Delete old option page slug |
| 244 | unset($option[$acfe_dop_name]); |
| 245 | |
| 246 | // Re-assign to menu_slug |
| 247 | $option[$menu_slug] = $register_args; |
| 248 | |
| 249 | // Sort keys ASC |
| 250 | ksort($option); |
| 251 | |
| 252 | // Update ACFE option |
| 253 | acfe_update_settings('modules.options_pages', $option); |
| 254 | |
| 255 | // Update post: force menu slug as name |
| 256 | wp_update_post(array( |
| 257 | 'ID' => $post_id, |
| 258 | 'post_name' => $menu_slug, |
| 259 | )); |
| 260 | |
| 261 | $updated = true; |
| 262 | |
| 263 | } |
| 264 | |
| 265 | } |
| 266 | |
| 267 | } |
| 268 | |
| 269 | if($updated) |
| 270 | acf_log('[ACF Extended] 0.8.6 Upgrade: Options Pages'); |
| 271 | |
| 272 | } |
| 273 | |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * ACF Extended: 0.8.5 |
| 278 | */ |
| 279 | function do_0_8_5(){ |
| 280 | |
| 281 | $tasks = array( |
| 282 | 'forms', |
| 283 | 'post_types', |
| 284 | 'taxonomies', |
| 285 | 'block_types', |
| 286 | 'options_pages', |
| 287 | ); |
| 288 | |
| 289 | foreach($tasks as $task){ |
| 290 | |
| 291 | /* |
| 292 | * Forms |
| 293 | */ |
| 294 | if($task === 'forms'){ |
| 295 | |
| 296 | // Retrieve all forms posts |
| 297 | $get_forms = get_posts(array( |
| 298 | 'post_type' => 'acfe-form', |
| 299 | 'posts_per_page' => -1, |
| 300 | 'fields' => 'ids', |
| 301 | 'post_status' => 'any' |
| 302 | )); |
| 303 | |
| 304 | // Bail early if no form found |
| 305 | if(empty($get_forms)) |
| 306 | continue; |
| 307 | |
| 308 | $flexible = acf_get_field_type('flexible_content'); |
| 309 | $field = acf_get_field('acfe_form_actions'); |
| 310 | |
| 311 | global $wpdb; |
| 312 | |
| 313 | foreach($get_forms as $post_id){ |
| 314 | |
| 315 | // init |
| 316 | $wp_meta = array(); |
| 317 | $acf_meta = array(); |
| 318 | |
| 319 | // Retrieve meta |
| 320 | $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d ", $post_id)); |
| 321 | |
| 322 | // Sort |
| 323 | usort($get_meta, function($a, $b){ |
| 324 | return strcmp($a->meta_key, $b->meta_key); |
| 325 | }); |
| 326 | |
| 327 | // Store |
| 328 | foreach($get_meta as $meta){ |
| 329 | |
| 330 | $wp_meta[$meta->meta_key] = $meta->meta_value; |
| 331 | |
| 332 | } |
| 333 | |
| 334 | // Check if is acf meta |
| 335 | foreach($wp_meta as $key => $value){ |
| 336 | |
| 337 | // ACF Meta |
| 338 | if(isset($wp_meta["_$key"])){ |
| 339 | |
| 340 | $acf_meta[] = array( |
| 341 | 'key' => $key, |
| 342 | 'value' => $wp_meta[$key], |
| 343 | ); |
| 344 | |
| 345 | } |
| 346 | |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * Step 1: Upgrade old group fields |
| 351 | */ |
| 352 | $prefix = 'acfe_form_actions'; |
| 353 | |
| 354 | // Define script rules |
| 355 | $rules = array( |
| 356 | |
| 357 | // Post: title |
| 358 | array( |
| 359 | 'group' => 'acfe_form_post_save_post_title_group', |
| 360 | 'sub_field' => 'acfe_form_post_save_post_title_group_acfe_form_post_save_post_title', |
| 361 | 'sub_field_custom' => 'acfe_form_post_save_post_title_group_acfe_form_post_save_post_title_custom', |
| 362 | 'new_field' => 'acfe_form_post_save_post_title', |
| 363 | ), |
| 364 | |
| 365 | // Post: name |
| 366 | array( |
| 367 | 'group' => 'acfe_form_post_save_post_name_group', |
| 368 | 'sub_field' => 'acfe_form_post_save_post_name_group_acfe_form_post_save_post_name', |
| 369 | 'sub_field_custom' => 'acfe_form_post_save_post_name_group_acfe_form_post_save_post_name_custom', |
| 370 | 'new_field' => 'acfe_form_post_save_post_name', |
| 371 | ), |
| 372 | |
| 373 | // Term: name |
| 374 | array( |
| 375 | 'group' => 'acfe_form_term_save_name_group', |
| 376 | 'sub_field' => 'acfe_form_term_save_name_group_acfe_form_term_save_name', |
| 377 | 'sub_field_custom' => 'acfe_form_term_save_name_group_acfe_form_term_save_name_custom', |
| 378 | 'new_field' => 'acfe_form_term_save_name', |
| 379 | ), |
| 380 | |
| 381 | // Term: slug |
| 382 | array( |
| 383 | 'group' => 'acfe_form_term_save_slug_group', |
| 384 | 'sub_field' => 'acfe_form_term_save_slug_group_acfe_form_term_save_slug', |
| 385 | 'sub_field_custom' => 'acfe_form_term_save_slug_group_acfe_form_term_save_slug_custom', |
| 386 | 'new_field' => 'acfe_form_term_save_slug', |
| 387 | ), |
| 388 | |
| 389 | // User: e-mail |
| 390 | array( |
| 391 | 'group' => 'acfe_form_user_save_email_group', |
| 392 | 'sub_field' => 'acfe_form_user_save_email_group_acfe_form_user_save_email', |
| 393 | 'sub_field_custom' => 'acfe_form_user_save_email_group_acfe_form_user_save_email_custom', |
| 394 | 'new_field' => 'acfe_form_user_save_email', |
| 395 | ), |
| 396 | |
| 397 | // User: username |
| 398 | array( |
| 399 | 'group' => 'acfe_form_user_save_username_group', |
| 400 | 'sub_field' => 'acfe_form_user_save_username_group_acfe_form_user_save_username', |
| 401 | 'sub_field_custom' => 'acfe_form_user_save_username_group_acfe_form_user_save_username_custom', |
| 402 | 'new_field' => 'acfe_form_user_save_username', |
| 403 | ), |
| 404 | |
| 405 | // User: password |
| 406 | array( |
| 407 | 'group' => 'acfe_form_user_save_password_group', |
| 408 | 'sub_field' => 'acfe_form_user_save_password_group_acfe_form_user_save_password', |
| 409 | 'sub_field_custom' => 'acfe_form_user_save_password_group_acfe_form_user_save_password_custom', |
| 410 | 'new_field' => 'acfe_form_user_save_password', |
| 411 | ), |
| 412 | |
| 413 | // User: first name |
| 414 | array( |
| 415 | 'group' => 'acfe_form_user_save_first_name_group', |
| 416 | 'sub_field' => 'acfe_form_user_save_first_name_group_acfe_form_user_save_first_name', |
| 417 | 'sub_field_custom' => 'acfe_form_user_save_first_name_group_acfe_form_user_save_first_name_custom', |
| 418 | 'new_field' => 'acfe_form_user_save_first_name', |
| 419 | ), |
| 420 | |
| 421 | // User: last name |
| 422 | array( |
| 423 | 'group' => 'acfe_form_user_save_last_name_group', |
| 424 | 'sub_field' => 'acfe_form_user_save_last_name_group_acfe_form_user_save_last_name', |
| 425 | 'sub_field_custom' => 'acfe_form_user_save_last_name_group_acfe_form_user_save_last_name_custom', |
| 426 | 'new_field' => 'acfe_form_user_save_last_name', |
| 427 | ), |
| 428 | |
| 429 | // User: nickname |
| 430 | array( |
| 431 | 'group' => 'acfe_form_user_save_nickname_group', |
| 432 | 'sub_field' => 'acfe_form_user_save_nickname_group_acfe_form_user_save_nickname', |
| 433 | 'sub_field_custom' => 'acfe_form_user_save_nickname_group_acfe_form_user_save_nickname_custom', |
| 434 | 'new_field' => 'acfe_form_user_save_nickname', |
| 435 | ), |
| 436 | |
| 437 | // User: display name |
| 438 | array( |
| 439 | 'group' => 'acfe_form_user_save_display_name_group', |
| 440 | 'sub_field' => 'acfe_form_user_save_display_name_group_acfe_form_user_save_display_name', |
| 441 | 'sub_field_custom' => 'acfe_form_user_save_display_name_group_acfe_form_user_save_display_name_custom', |
| 442 | 'new_field' => 'acfe_form_user_save_display_name', |
| 443 | ), |
| 444 | |
| 445 | // User: website |
| 446 | array( |
| 447 | 'group' => 'acfe_form_user_save_website_group', |
| 448 | 'sub_field' => 'acfe_form_user_save_website_group_acfe_form_user_save_website', |
| 449 | 'sub_field_custom' => 'acfe_form_user_save_website_group_acfe_form_user_save_website_custom', |
| 450 | 'new_field' => 'acfe_form_user_save_website', |
| 451 | ), |
| 452 | |
| 453 | ); |
| 454 | |
| 455 | // Process rules |
| 456 | foreach($rules as $rule){ |
| 457 | |
| 458 | $updates = array(); |
| 459 | |
| 460 | foreach($acf_meta as $acf){ |
| 461 | |
| 462 | // Bail early if doesn't starts with 'acfe_form_actions' |
| 463 | if(strpos($acf['key'], $prefix) !== 0) |
| 464 | continue; |
| 465 | |
| 466 | // Regex: 'acfe_form_actions_2_acfe_form_post_save_post_title_group' |
| 467 | // Match: '2' |
| 468 | if(preg_match('/^' . $prefix . '_([0-9]+)_' . $rule['group'] . '$/', $acf['key'], $match)){ |
| 469 | |
| 470 | $updates[$rule['new_field']][$match[1]]['group'] = array( |
| 471 | 'key' => $acf['key'], |
| 472 | 'value' => $acf['value'], |
| 473 | ); |
| 474 | |
| 475 | // Regex: 'acfe_form_post_2_save_post_title_group_acfe_form_post_save_post_title' |
| 476 | // Match: '2' |
| 477 | }elseif(preg_match('/^' . $prefix . '_([0-9]+)_' . $rule['sub_field'] . '$/', $acf['key'], $match)){ |
| 478 | |
| 479 | $updates[$rule['new_field']][$match[1]]['sub_field'] = array( |
| 480 | 'key' => $acf['key'], |
| 481 | 'value' => $acf['value'], |
| 482 | ); |
| 483 | |
| 484 | // Regex: 'acfe_form_post_2_save_post_title_group_acfe_form_post_save_post_title_custom' |
| 485 | // Match: '2' |
| 486 | }elseif(preg_match('/^' . $prefix . '_([0-9]+)_' . $rule['sub_field_custom'] . '$/', $acf['key'], $match)){ |
| 487 | |
| 488 | // Generate: array[acfe_form_post_save_post_title][2]['sub_field_custom'] |
| 489 | $updates[$rule['new_field']][$match[1]]['sub_field_custom'] = array( |
| 490 | 'key' => $acf['key'], |
| 491 | 'value' => $acf['value'], |
| 492 | ); |
| 493 | |
| 494 | } |
| 495 | |
| 496 | } |
| 497 | |
| 498 | if(!empty($updates)){ |
| 499 | |
| 500 | acf_log('[ACF Extended] 0.8.5 Upgrade: Forms'); |
| 501 | |
| 502 | // Update meta |
| 503 | foreach($updates as $new_field => $data){ |
| 504 | |
| 505 | foreach($data as $i => $row){ |
| 506 | |
| 507 | $group = acf_maybe_get($row, 'group'); |
| 508 | $sub_field = acf_maybe_get($row, 'sub_field'); |
| 509 | $sub_field_custom = acf_maybe_get($row, 'sub_field_custom'); |
| 510 | |
| 511 | if($sub_field){ |
| 512 | |
| 513 | $new_field_name = "{$prefix}_{$i}_{$new_field}"; |
| 514 | |
| 515 | // update field |
| 516 | if($sub_field['value'] === 'custom'){ |
| 517 | |
| 518 | update_post_meta($post_id, $new_field_name, $sub_field_custom['value']); |
| 519 | |
| 520 | }else{ |
| 521 | |
| 522 | update_post_meta($post_id, $new_field_name, $sub_field['value']); |
| 523 | |
| 524 | } |
| 525 | |
| 526 | // update reference |
| 527 | update_post_meta($post_id, '_' . $new_field_name, 'field_' . $new_field); |
| 528 | |
| 529 | } |
| 530 | |
| 531 | // Delete old group |
| 532 | delete_post_meta($post_id, $group['key']); |
| 533 | delete_post_meta($post_id, $sub_field['key']); |
| 534 | delete_post_meta($post_id, $sub_field_custom['key']); |
| 535 | |
| 536 | } |
| 537 | |
| 538 | } |
| 539 | |
| 540 | } |
| 541 | |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * Step 2: Upgrade map fields which now require "Load values" to be enabled |
| 546 | */ |
| 547 | if(have_rows('acfe_form_actions', $post_id)): |
| 548 | while(have_rows('acfe_form_actions', $post_id)): the_row(); |
| 549 | |
| 550 | $layout = get_row_layout(); |
| 551 | $row = get_row_index(); |
| 552 | $i = $row-1; |
| 553 | |
| 554 | // Post Action |
| 555 | if($layout === 'post'){ |
| 556 | |
| 557 | $load_values = get_sub_field('acfe_form_post_load_values'); |
| 558 | |
| 559 | $fields = array( |
| 560 | 'field_acfe_form_post_save_post_type' => get_sub_field('acfe_form_post_map_post_type', false), |
| 561 | 'field_acfe_form_post_save_post_status' => get_sub_field('acfe_form_post_map_post_status', false), |
| 562 | 'field_acfe_form_post_save_post_title' => get_sub_field('acfe_form_post_map_post_title', false), |
| 563 | 'field_acfe_form_post_save_post_name' => get_sub_field('acfe_form_post_map_post_name', false), |
| 564 | 'field_acfe_form_post_save_post_content' => get_sub_field('acfe_form_post_map_post_content', false), |
| 565 | 'field_acfe_form_post_save_post_author' => get_sub_field('acfe_form_post_map_post_author', false), |
| 566 | 'field_acfe_form_post_save_post_parent' => get_sub_field('acfe_form_post_map_post_parent', false), |
| 567 | 'field_acfe_form_post_save_post_terms' => get_sub_field('acfe_form_post_map_post_terms', false), |
| 568 | ); |
| 569 | |
| 570 | if(!$load_values){ |
| 571 | |
| 572 | foreach($fields as $field_key => $field_value){ |
| 573 | |
| 574 | // Bail early if map field has no value |
| 575 | if(empty($field_value)) |
| 576 | continue; |
| 577 | |
| 578 | // args |
| 579 | $update = array(); |
| 580 | $update['acf_fc_layout'] = $layout; |
| 581 | |
| 582 | // Post content inside group |
| 583 | if($field_key === 'field_acfe_form_post_save_post_content'){ |
| 584 | |
| 585 | $update['field_acfe_form_post_save_post_content_group'] = array( |
| 586 | 'field_acfe_form_post_save_post_content' => $field_value |
| 587 | ); |
| 588 | |
| 589 | }else{ |
| 590 | |
| 591 | $update[$field_key] = $field_value; |
| 592 | |
| 593 | } |
| 594 | |
| 595 | // update |
| 596 | $flexible->update_row($update, $i, $field, $post_id); |
| 597 | |
| 598 | } |
| 599 | |
| 600 | } |
| 601 | |
| 602 | } |
| 603 | |
| 604 | // Term Action |
| 605 | elseif($layout === 'term'){ |
| 606 | |
| 607 | $load_values = get_sub_field('acfe_form_term_load_values'); |
| 608 | |
| 609 | $fields = array( |
| 610 | 'field_acfe_form_term_save_name' => get_sub_field('acfe_form_term_map_name', false), |
| 611 | 'field_acfe_form_term_save_slug' => get_sub_field('acfe_form_term_map_slug', false), |
| 612 | 'field_acfe_form_term_save_taxonomy' => get_sub_field('acfe_form_term_map_taxonomy', false), |
| 613 | 'field_acfe_form_term_save_parent' => get_sub_field('acfe_form_term_map_parent', false), |
| 614 | 'field_acfe_form_term_save_description' => get_sub_field('acfe_form_term_map_description', false), |
| 615 | ); |
| 616 | |
| 617 | if(!$load_values){ |
| 618 | |
| 619 | foreach($fields as $field_key => $field_value){ |
| 620 | |
| 621 | // Bail early if map field has no value |
| 622 | if(empty($field_value)) |
| 623 | continue; |
| 624 | |
| 625 | // args |
| 626 | $update = array(); |
| 627 | $update['acf_fc_layout'] = $layout; |
| 628 | |
| 629 | // Post content inside group |
| 630 | if($field_key === 'field_acfe_form_term_save_description'){ |
| 631 | |
| 632 | $update['field_acfe_form_term_save_description_group'] = array( |
| 633 | 'field_acfe_form_term_save_description' => $field_value |
| 634 | ); |
| 635 | |
| 636 | }else{ |
| 637 | |
| 638 | $update[$field_key] = $field_value; |
| 639 | |
| 640 | } |
| 641 | |
| 642 | // update |
| 643 | $flexible->update_row($update, $i, $field, $post_id); |
| 644 | |
| 645 | } |
| 646 | |
| 647 | } |
| 648 | |
| 649 | } |
| 650 | |
| 651 | // User Action |
| 652 | elseif($layout === 'user'){ |
| 653 | |
| 654 | $load_values = get_sub_field('acfe_form_user_load_values'); |
| 655 | |
| 656 | $fields = array( |
| 657 | 'field_acfe_form_user_save_email' => get_sub_field('acfe_form_user_map_email', false), |
| 658 | 'field_acfe_form_user_save_username' => get_sub_field('acfe_form_user_map_username', false), |
| 659 | 'field_acfe_form_user_save_password' => get_sub_field('acfe_form_user_map_password', false), |
| 660 | 'field_acfe_form_user_save_first_name' => get_sub_field('acfe_form_user_map_first_name', false), |
| 661 | 'field_acfe_form_user_save_last_name' => get_sub_field('acfe_form_user_map_last_name', false), |
| 662 | 'field_acfe_form_user_save_nickname' => get_sub_field('acfe_form_user_map_nickname', false), |
| 663 | 'field_acfe_form_user_save_display_name' => get_sub_field('acfe_form_user_map_display_name', false), |
| 664 | 'field_acfe_form_user_save_website' => get_sub_field('acfe_form_user_map_website', false), |
| 665 | 'field_acfe_form_user_save_description' => get_sub_field('acfe_form_user_map_description', false), |
| 666 | 'field_acfe_form_user_save_role' => get_sub_field('acfe_form_user_map_role', false), |
| 667 | ); |
| 668 | |
| 669 | if(!$load_values){ |
| 670 | |
| 671 | foreach($fields as $field_key => $field_value){ |
| 672 | |
| 673 | // Bail early if map field has no value |
| 674 | if(empty($field_value)) |
| 675 | continue; |
| 676 | |
| 677 | // args |
| 678 | $update = array(); |
| 679 | $update['acf_fc_layout'] = $layout; |
| 680 | |
| 681 | // Post content inside group |
| 682 | if($field_key === 'field_acfe_form_user_save_description'){ |
| 683 | |
| 684 | $update['field_acfe_form_user_save_description_group'] = array( |
| 685 | 'field_acfe_form_user_save_description' => $field_value |
| 686 | ); |
| 687 | |
| 688 | }else{ |
| 689 | |
| 690 | $update[$field_key] = $field_value; |
| 691 | |
| 692 | } |
| 693 | |
| 694 | // update |
| 695 | $flexible->update_row($update, $i, $field, $post_id); |
| 696 | |
| 697 | } |
| 698 | |
| 699 | } |
| 700 | |
| 701 | } |
| 702 | |
| 703 | endwhile; |
| 704 | endif; |
| 705 | |
| 706 | } |
| 707 | |
| 708 | } |
| 709 | |
| 710 | /* |
| 711 | * Post Types |
| 712 | */ |
| 713 | elseif($task === 'post_types'){ |
| 714 | |
| 715 | $old = get_option('acfe_dynamic_post_types', array()); |
| 716 | $new = acfe_get_settings('modules.post_types', array()); |
| 717 | |
| 718 | delete_option('acfe_dynamic_post_types'); |
| 719 | |
| 720 | if(empty($old)) |
| 721 | continue; |
| 722 | |
| 723 | acf_log('[ACF Extended] 0.8.5 Upgrade: Post Types'); |
| 724 | |
| 725 | // Update |
| 726 | acfe_update_settings('modules.post_types', array_merge($old, $new)); |
| 727 | |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | * Taxonomies |
| 732 | */ |
| 733 | elseif($task === 'taxonomies'){ |
| 734 | |
| 735 | $old = get_option('acfe_dynamic_taxonomies', array()); |
| 736 | $new = acfe_get_settings('modules.taxonomies', array()); |
| 737 | |
| 738 | delete_option('acfe_dynamic_taxonomies'); |
| 739 | |
| 740 | if(empty($old)) |
| 741 | continue; |
| 742 | |
| 743 | acf_log('[ACF Extended] 0.8.5 Upgrade: Taxonomies'); |
| 744 | |
| 745 | // Update |
| 746 | acfe_update_settings('modules.taxonomies', array_merge($old, $new)); |
| 747 | |
| 748 | } |
| 749 | |
| 750 | /* |
| 751 | * Block Types |
| 752 | */ |
| 753 | elseif($task === 'block_types'){ |
| 754 | |
| 755 | $old = get_option('acfe_dynamic_block_types', array()); |
| 756 | $new = acfe_get_settings('modules.block_types', array()); |
| 757 | |
| 758 | delete_option('acfe_dynamic_block_types'); |
| 759 | |
| 760 | if(empty($old)) |
| 761 | continue; |
| 762 | |
| 763 | acf_log('[ACF Extended] 0.8.5 Upgrade: Block Types'); |
| 764 | |
| 765 | // Update |
| 766 | acfe_update_settings('modules.block_types', array_merge($old, $new)); |
| 767 | |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * Option Pages |
| 772 | */ |
| 773 | elseif($task === 'options_pages'){ |
| 774 | |
| 775 | $old = get_option('acfe_dynamic_options_pages', array()); |
| 776 | $new = acfe_get_settings('modules.options_pages', array()); |
| 777 | |
| 778 | delete_option('acfe_dynamic_options_pages'); |
| 779 | |
| 780 | if(empty($old)) |
| 781 | continue; |
| 782 | |
| 783 | acf_log('[ACF Extended] 0.8.5 Upgrade: Options Pages'); |
| 784 | |
| 785 | // Update |
| 786 | acfe_update_settings('modules.options_pages', array_merge($old, $new)); |
| 787 | |
| 788 | } |
| 789 | |
| 790 | } |
| 791 | |
| 792 | } |
| 793 | |
| 794 | function parse_args_r(&$a, $b){ |
| 795 | |
| 796 | $a = (array) $a; |
| 797 | $b = (array) $b; |
| 798 | $r = $b; |
| 799 | |
| 800 | foreach($a as $k => &$v){ |
| 801 | |
| 802 | if(is_array($v) && isset($r[ $k ])){ |
| 803 | $r[$k] = $this->parse_args_r($v, $r[ $k ]); |
| 804 | }else{ |
| 805 | $r[$k] = $v; |
| 806 | } |
| 807 | |
| 808 | } |
| 809 | |
| 810 | return $r; |
| 811 | |
| 812 | } |
| 813 | |
| 814 | } |
| 815 | |
| 816 | acf_new_instance('acfe_upgrades'); |
| 817 | |
| 818 | endif; |