I am planning on using ACF as the core framework for my own custom theme to be used on multiple websites.
In my parent theme, I want to load through a selection of custom field groups whenever this parent theme is installed. Ideally, I would also like these fields to be non-destructible, meaning that a client is unable to delete these from within ACF itself, and would need to manually edit the parent theme folder in order to do so.
I have already utilised the following code to change the default location of the acf-json folder from my child theme to my parent theme:
function my_acf_json_save_point($path) {
// Update the path to the 'acf-json' folder in your parent theme
$path = get_template_directory() . '/acf-json';
return $path;
}
add_filter('acf/settings/save_json', 'my_acf_json_save_point');
function my_acf_json_load_point($paths) {
// Remove the default 'acf-json' folder path
unset($paths[0]);
// Add the path to the 'acf-json' folder in your parent theme
$paths[] = get_template_directory() . '/acf-json';
return $paths;
}
add_filter('acf/settings/load_json', 'my_acf_json_load_point');
My concern is that by taking this approach, all new custom field groups will now be automatically created in the parent theme folder, and if I were to create a bunch of site-specific fields groups for each individual website, then I worry that these would be overwritten as soon as a parent theme update is pulled through, deleting all any new custom fields groups.
Is there an obvious way to easily achieve the functionality I am after?
Thank you in advance!
Remove the acf/settings/save_json filter. The only place this field group should be editable is when editing the parent theme.
Add the private argument to your JSON files as described here https://www.advancedcustomfields.com/resources/synchronized-json/ to prevent syncing (and editing).
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.