Support

Account

Home Forums ACF PRO Creating non-destructible Local JSON field groups in a parent theme?

Solved

Creating non-destructible Local JSON field groups in a parent theme?

  • 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).

  • Thank you very much kind sir!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.