Open luukee opened 4 days ago
The article you shared highlights a common issue with using ACF Local JSON in a collaborative environment, especially when ACF fields are directly edited on the production site. The core problem arises when the production database has newer ACF field modifications than the acf-json
files, causing inconsistencies and ignoring JSON changes from version control.
To address this, the goal is to shift your workflow so that ACF fields are only managed via acf-json
files stored in your version control, and the production site always loads fields exclusively from these JSON files. Below, I'll guide you through safely transitioning from your current setup to a more controlled environment where field groups are managed only through acf-json
files.
Backup Your Production Database
Export Existing ACF Field Groups from Production
Tools > Export > ACF JSON
). This ensures you capture the latest settings directly from the production database.Replace Local acf-json
Files with Production Exports
acf-json/
directory locally. This step ensures your local environment is now in sync with the production site’s ACF configuration.Clear ACF Field Groups from the Production Database
wp acf export --all --path=./wp-content/themes/your-theme/acf-json
wp acf delete --all
Deploy the Clean Slate to Production
acf-json
files to the production site. This step sets the groundwork for the production site to rely on JSON files only.Force Production to Load ACF Field Groups from JSON Only
Modify your theme’s functions.php
to ensure ACF only loads from JSON files and not from the database. Here’s a code snippet to enforce this:
add_filter('acf/settings/load_json', function ($paths) {
// Remove original path (optional but recommended)
unset($paths[0]);
// Append our JSON path
$paths[] = get_stylesheet_directory() . '/acf-json';
return $paths;
});
add_action('admin_menu', function () {
// Hide ACF admin on production to prevent accidental edits
if (!current_user_can('manage_options')) {
remove_menu_page('edit.php?post_type=acf-field-group');
}
});
acf-json
directory and hides the ACF menu to prevent accidental changes.Test the Production Site
Establish a New Workflow for ACF Field Group Changes
Communicate the Workflow Changes with Your Team
By following these steps, you can successfully transition from managing ACF fields directly on the production database to a controlled environment where ACF field groups are managed exclusively through JSON files in version control. This approach minimizes conflicts, maintains consistency across environments, and aligns your workflow with best practices for collaborative development with ACF.
Production site:
acf-json/
field groupsLocal Devs
acf-json/
field groupsLinks for help: