Home › Forums › General Issues › Is there a way to revert to the old save behavior for Local JSON? › Reply To: Is there a way to revert to the old save behavior for Local JSON?
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.