Support

Account

Home Forums Backend Issues (wp-admin) Edits to Field Groups Synced Through JSON

Solved

Edits to Field Groups Synced Through JSON

  • Hi! I have synced several field groups with JSON via a plugin. Once those field groups are synced, some installs will need to edit specific permissions, etc. However, none of those edits are applied (they show on the field groups but it appears the JSON keeps overriding them). If I delete the JSON file from the plugin, they remain active and the edits work. Is there a way to have the “active” group over-ride the JSON file? Thanks!

  • I’m a little confused.

    Do you mean that you want to have the changes made to the group override the JSON files?

    It that is it then no, the only way to do this is to delete the JSON files. But if the JSON files exist already then any changes to the field groups will be saved in those JSON files.

    And my last comment confused me more. You’re going to need to give me more details on what you are trying to do.

  • Ha! Thanks for the quick response, and sorry if I was unclear!

    Here’s the steps:
    – load JSON file via plugin
    – sync field group
    – make changes to field group (for example: allow a custom user role to see the fields)
    – WISH that changes to field group would work on the site but they don’t. 🙂
    – delete JSON file from plugin and the field group changes now work

    Does that make more sense? Basically I’m looking for the field group to drive everything, not the JSON (but no, I don’t need/want the JSON file for the plugin to be edited at all).

  • What plugin are you using to load the JSON file? Your losing me here and “Load JSON file via plugin”

  • It’s a custom plugin. Here’s the function I’m using to load the JSON files with the field groups:

    /** Start: Create JSON save point */
      add_filter('acf/settings/save_json', 'wed_acf_json_save_point');
      function wed_acf_json_save_point( $path ) {
        $path = plugin_dir_path( __FILE__ ) . 'acf-json/';
        return $path;
      }
      /** End: Create JSON save point */
      /** Start: Create JSON load point */
      add_filter('acf/settings/load_json', 'wed_acf_json_load_point');
      /** End: Create JSON load point */
  • You are creating a different save point. This will save all field groups edited to the plugin folder. It appears that the file is not being saved to the plugin folder for some reason.

    But you are not loading the json_file from this point, I really don’t know how you’re syncing the field group without adding a load point.

    I’m not sure what exactly you are trying to accomplish, but if it worked you would overwrite the file in the plugin folder and this would then be overwritten when the plugin is updated.

    I think what you want to do is to add a load point to load json files from the plugin and here you want a priority of > 10 to allow the acf-json folder in the theme to be loaded first. This will mean that the JSON file from the plugin will only be loaded if that JSON file does not exist in the theme. Create an acf-json folder in the theme folder. When you sync and then save the field group it will save it to the theme folder and override the json file in the plugin. But doing this will also mean that if you ever updated this field group in the plugin that those changes till not effect any site where they have been changed.

    The best way to have a field group in the plugin that can be overridden by custom settings is to create an options page for editing whatever options you want and then use ACF filters to modify the field group (acf/validate_field_group) based on the values in these options.

  • I think what you want to do is to add a load point to load json files from the plugin and here you want a priority of > 10 to allow the acf-json folder in the theme to be loaded first. This will mean that the JSON file from the plugin will only be loaded if that JSON file does not exist in the theme. Create an acf-json folder in the theme folder. When you sync and then save the field group it will save it to the theme folder and override the json file in the plugin. But doing this will also mean that if you ever updated this field group in the plugin that those changes till not effect any site where they have been changed.

    This is perfect and points me in the right direction, thank you so much!

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

You must be logged in to reply to this topic.