Do you use the ACF Local JSON feature? You should!
Only bad part is, tying custom fields to a theme isn’t optimal, which I’ve spoken about earlier.
Here’s a quick way to put your ACF JSON field groups inside a plugin!
<?php
/*
Plugin Name: ACF Local JSON plugin
Plugin URI:
Description: Put this file in a plugin folder and create an /acf directory inside the plugin, ie: /my-plugin/acf
Author: khromov
Version: 0.1
*/
//Change ACF Local JSON save location to /acf folder inside this plugin
add_filter('acf/settings/save_json', function() {
return dirname(__FILE__) . '/acf';
});
//Include the /acf folder in the places to look for ACF Local JSON files
add_filter('acf/settings/load_json', function($paths) {
$paths[] = dirname(__FILE__) . '/acf';
return $paths;
});
After you create the main plugin file, make sure to create an empty folder called acf
as well in the plugin root – that’s where your local JSON files will be saved.