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

  • 
    <?php 
      
      new my_pluging_name_acf_group_save();
      
      class my_pluging_name_acf_group_save {
        
        // list of field group IDs used in my plugin
        private $groups = array(
          'group_5cd98d69d9edd',
          'group_5cdd8ef037a51',
          'group_5cdda2c94c13a',
          'group_5ce3e785e644e',
          'group_5d41e7d89ed6c'
        );
        
        public function __construct() {
          // add fitler before acf saves a group
          add_action('acf/update_field_group', array($this, 'update_field_group'), 1, 1);
        } // end public function __construct
        
        public function update_field_group($group) {
          // called when ACF save the field group to the DB
          if (in_array($group['key'], $this->groups)) {
            // if it is one of my groups then add a filter on the save location
            // high priority to make sure it is not overrridded, I hope
            add_filter('acf/settings/save_json',  array($this, 'override_location'), 9999);
          }
          return $group;
        } // end public function update_field_group
        
        public function override_location($path) {
          // remove this filter so it will not effect other goups
          remove_filter('acf/settings/save_json',  array($this, 'override_location'), 9999);
          // override save path
          $path = dirname(plugin_dir_path(__FILE__)).'/acf-json';
          return $path;
        } // end public function override_json_location
        
      } // end class my_pluging_name_acf_group_save
      
    

    There is also a plugin https://github.com/khromov/acf-local-json-manager

    and I’m sure there are other filters available