Support

Account

Home Forums General Issues Is there a way to revert to the old save behavior for Local JSON?

Solving

Is there a way to revert to the old save behavior for Local JSON?

  • Hello,

    The new way ACF JSON is saved breaks functionality on several plugins I’ve created. Specifically these plugins use saved JSON in the plugin folder to provide default fields, which can then be synced and extended to be theme specific (this is a developer tool for customization). Upon updating, ACF sites using this method lose all customized fields until everything is re-saved, as the field data begins pulling from the default plugin fields which are not up to date (and should not be updated as they are not site specific – plugin updates would break this yet again).

    Is there a filter I can use to change this behavior to restore the old functionality?

  • I agree, this really should have been something that could be toggled back to the old way.

  • I’m not sure what you mean by old save behavior.

    When you sync field groups or save groups in the admin they are saved to the theme’s acf-json folder. Updating the theme will delete the folder. This is standard WP behavior.

    When adding custom fields to a theme that can be updated a child theme should be used with an acf-json folder in the child theme to avoid this.

  • If I’m understanding correctly, I’ve run into the same issue with the old way of saving local json files changing. I used the old save behavior (pre-5.9.0) to manage json files in my development flow. In the functions.php file I’d put the following:

    
    function webpack_acf_json_save_point( $orig_path ) {
      $path = $orig_path; // ACF PATH SETTING
      return $path;
    }
    add_filter('acf/settings/save_json', 'webpack_acf_json_save_point');
    

    The webpack build process would replace $orig_path with the src folder I keep the /acf-json folder in my project.

    So ACF loads up the json files from the regular theme location (such as wordpress-installation/wp-content/themes/my-theme/acf-json) and when I save changes to ACF fields, ACF would write them to the path my build process specified in the filter (my-project/src/acf-json) and webpack would copy them back into the theme folder during development so the dev site worked fine.

    With the new feature that is explained on the blog announcement as: “Now, no matter where the .json file was loaded from, it will be updated when making changes to a Field Group.” means that it no longer saves where I specified in the filter above. It essentially ignores that filter from what I can tell. I would consider that a bug because the filter is there to say, “I know what the default functionality is (new or old), but this is where I want you to write the json files.”

    What I ended up doing is adding in a second filter:

    
    function webpack_acf_json_load_points( $orig_paths ) {
      $paths = $orig_paths; // ACF LOAD PATH SETTING
      return $paths;
    }
    add_filter('acf/settings/load_json', 'webpack_acf_json_load_points');
    

    That is also managed by webpack in a similar way to the other filter and it works with the new feature (I haven’t tested it but I assume I can delete my original filter on save_json and with the new functionality it would save it back to that folder).

    I realize now that I probably should have done it originally with both of the filters in place, but didn’t see that until the new functionality came out.

  • I guess I have to pay more attention, I’ve been extremely busy lately. I did not realize that ACF will not save json files back to my plugin folder automatically, so I have code that needs to be altered.

    I guess what this means is that you now have to use the save path filter if you do not want json saved back to the original location…. Will need some time to work out the details of this.

  • @hube2 The current issue I see is that the acf/settings/save_json filter doesn’t override the new behavior in 5.9.0. It is ignored now so if you’re not using it you should be fine. If you are using it there is no effect from it anymore. The documentation either needs to be updated to reflect that it no longer has any effect (and should be removed) or the logic should be changed so it is a higher precedence than the new 5.9.0 functionality.

  • For several of my plugins and themes I have code that basically does the same thing that ACF is currently doing. I do have one theme where field groups that are synced from the parent theme are then saved in the child theme so that they can be modified on a per site basis. This theme is currently not active on any sites but is is a model that I have been know to use.

    I don’t have an answer for this at the moment

    You might want to send the question to support and see if they can help you with a solution or perhaps add something to ACF in an update that will allow what you are looking for. https://www.advancedcustomfields.com/contact/

  • It appears that in the new version (5.9.1) that this has been reverted. At least that’s what the changelog says.

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

You must be logged in to reply to this topic.