├── Readme.md ├── acf-php-recovery.php └── composer.json /Readme.md: -------------------------------------------------------------------------------- 1 | # Advanced Custom Fields v 5.0 Recovery Tool from PHP Export # 2 | 3 | Use this plugin to import fieldsets from PHP exports. Do not use this for your workflow of importing and exporting. Use it only as a recovery tool when you lose the original database and XML files. 4 | 5 | 1. Include the PHP for the ACF fieldsets generated from the PHP export. 6 | 2. Install and activate this plugin. 7 | 3. Go to 'Custom Fields' > 'PHP Recovery' page. 8 | 4. Check the boxes next to the fieldsets to import and then click the 'Import' button. 9 | 5. The fieldset are imported into the database with '(Recovered)' postfixed to the title. 10 | 6. Remove (or just comment out) the PHP defined fields as their UID may conflict with the imported fields. Commonly if you leave them in, you will only see the last field on the fieldset edit screen. 11 | 12 | ## Alternatives ## 13 | 14 | https://github.com/iamntz/acf-recovery 15 | 16 | ## Thanks ## 17 | 18 | Thanks to Elliot Condon http://www.elliotcondon.com/ for creating Advanced Custom Fields. 19 | 20 | Thanks to Seamus Leahy https://github.com/seamusleahy for creating this project. 21 | -------------------------------------------------------------------------------- /acf-php-recovery.php: -------------------------------------------------------------------------------- 1 | = 0 22 | ? acf_get_local_field_groups() 23 | : acf_local(); 24 | $acf_local_fields = acf_get_local_fields(); 25 | 26 | // process the form 27 | if (isset($_POST['acf_php_recovery_action']) && $_POST['acf_php_recovery_action'] == 'import' && isset($_POST['fieldsets']) && check_admin_referer('acf_php_recovery')) { 28 | $import_fieldsets = $_POST['fieldsets']; 29 | 30 | $imported = array(); // Keep track of the imported 31 | 32 | $key_to_post_id = array(); // Group or field key to post id 33 | 34 | // Now we can import the groups 35 | foreach ($acf_local_groups as $key => $group) { 36 | $group['title'] = $group['title'] . ' (Recovered)'; 37 | 38 | // Only import those that were selected 39 | if (in_array($key, $import_fieldsets)) { 40 | $saved_group = acf_update_field_group($group); 41 | 42 | $key_to_post_id[$key] = $saved_group['ID']; 43 | 44 | // For displaying the success message 45 | $imported[] = array( 46 | 'title' => $group['title'], 47 | 'id' => $saved_group['ID'],); 48 | } 49 | } 50 | 51 | // This requires multipile runs to handle sub-fields that have their parent set to the parent field instead of the group 52 | $field_parents = $import_fieldsets; // The groups and fields 53 | $imported_fields = array(); // Keep track of the already imported 54 | do { 55 | $num_import = 0; 56 | foreach ($acf_local_fields as $key => $field) { 57 | if (! in_array($key, $imported_fields) && in_array($field['parent'], $field_parents)) { 58 | $num_import = $num_import + 1; 59 | $field_parents[] = $key; 60 | $imported_fields[] = $key; 61 | 62 | $field['parent'] = $key_to_post_id[$field['parent']]; // Convert the key into the post_parent 63 | $saved_field = acf_update_field($field); 64 | $key_to_post_id[$key] = $saved_field['ID']; 65 | } 66 | } 67 | } while ($num_import > 0); 68 | } 69 | 70 | 71 | // output 72 | ?> 73 |
.
92 |110 | This is a recovery tool. Do not use this as part of your workflow for importing and exporting ACF fieldsets. 111 |
112 | 156 | 157 |159 | 160 |161 | 162 |