Support

Account

Home Forums ACF PRO Is it possible to have local JSON files in both theme and plugin folders Reply To: Is it possible to have local JSON files in both theme and plugin folders

  • I’ve managed to get it working using your code as a starting point. This is my first try at anything plugin related so there might be a better/cleaner way to do it, or things I haven’t considered.

    I have 2 ACF field groups

    • group_5d9700e0b69a7 – related to my theme and saves/loads/syncs from my-theme/acf-json folder
    • group_5d921d2978e9e – related to my plugin and saves/loads/syncs from my-plugin/acf-json folder
    /********************************/
    // Save and load plugin specific ACF field groups via the /acf-json folder.
    /********************************/
    
    // Save
    function my_plugin_update_field_group($group) {
      // list of field groups that should be saved to my-plugin/acf-json
      $groups = array('group_5d921d2978e9e');
    
      if (in_array($group['key'], $groups)) {
        add_filter('acf/settings/save_json', function() {
          return dirname(__FILE__) . '/acf-json';
        });
      }
    }
    add_action('acf/update_field_group', 'my_plugin_update_field_group', 1, 1);
    
    // Load - includes the /acf-json folder in this plugin to the places to look for ACF Local JSON files
    add_filter('acf/settings/load_json', function($paths) {
      $paths[] = dirname(__FILE__) . '/acf-json';
      return $paths;
    });