Replace any X with your information.
What is the current behavior?
When attempting to use the ACF plugin's Local JSON feature, ACF JSON data is never saved into the acf-json directory.
What is the expected or desired behavior?
Expected behavior is what is outlined in the ACF docs for Local JSON.
(delete this section if not applicable)
Please provide steps to reproduce, including full log output:
acf-json directory in the theme folder.At this point, a JSON file should be saved into the acf-json directory. Due to how Sage 9 rewrites the theme location, this does not happen.
Please describe your local environment:
WordPress version: 4.6
OS: OSX & Linux
NPM/Node version: N/A
Where did the bug happen? Development or remote servers?
Local, Virtual, and Production servers.
Other relevant information:
I published a Gist that fixes the issue. I was hesitant to mark it as a bug, since not everyone uses ACF. However, it is recommended by Sage and thus it may be beneficial to add this fix into the Sage setup.php before the official release, or at least documenting the issue. If this is something the Sage developers would like to fix, I would be more than happy to submit a PR!
In the meantime, here is the Gist for any puzzled Sage developers out there: https://gist.github.com/samrap/d4a19858c2ed1d238c27df91580350e0
Definitely good to know, as we use this feature on almost every site we build.
thanks for pointing this out, this raises concerns about other compatibility issues with our new templates setup
i tend to save ACF JSON in 1 of 2 places outside of the theme since this is functionality that shouldn't usually be theme specific:
mu-plugins/client-name/field-groups/app/acf-json/// mu-plugins example
add_filter('acf/settings/save_json', function($path) {
return dirname(__FILE__) . '/client-name/field-groups';
});
// wp-content/app example
add_filter('acf/settings/save_json', function($path) {
return WP_CONTENT_DIR . '/acf-json';
});
@AdamWills Same here, all of our client WordPress sites use flexible ACF templates.
@retlehs The way we build sites for our clients makes the ACF pretty theme-specific as we build out one single template and provide all our modules as Flex Fields. Although I suppose storing them outside of the theme also makes sense either way.
closed by #1751
@retlehs @QWp6t looks like this is an issue again since switching the directory structure up. Looking into it.
Does it work if you create the following folder: sage/resources/acf-json?
Creating the folder at sage/resources/acf-json does not work for me using the latest Sage 9 beta.
However, putting it inside sage/resources/views/acf-json does work.
Apologies for not seeing the response. I could not get it to work by creating the directory. Had to use the code in the gist I originally posted to get it working. Have not tried @jmreid solution.
Any way we could re-open this issue, or should I submit a new one?
Thanks! @retlehs I will be looking into this in the next couple days
This should work now as of https://github.com/roots/sage/pull/1919/commits/1a8dce9b092e8bbe1d1921c43eb3691f3399b0a7
Theme folder is sage/resources (that's where functions.php, style.css, and index.php are).
Creating sage/resources/acf-json should work, I think.
Feel free to let me know if it doesn't and I'll look into this again.
I suggest wp_upload_dir() so that any site duplicator, migrator will back that up.
We can also override directory name using:
/**
* ACF save json folder
*/
add_filter( 'acf/settings/save_json', 'my_acf_json_save_point' );
function my_acf_json_save_point( $path ) {
return get_stylesheet_directory() . '/acf-json-custom-folder';
}
/**
* ACF load json folder
*/
add_filter( 'acf/settings/load_json', 'my_acf_json_load_point' );
function my_acf_json_load_point( $paths ) {
$paths[] = get_stylesheet_directory() . '/acf-json-custom-folder';
return $paths;
}
get_stylesheet_directory() point to theresources/ folder.
From local JSON ACF documentation.
Most helpful comment
This should work now as of https://github.com/roots/sage/pull/1919/commits/1a8dce9b092e8bbe1d1921c43eb3691f3399b0a7
Theme folder is sage/resources (that's where functions.php, style.css, and index.php are).
Creating sage/resources/acf-json should work, I think.
Feel free to let me know if it doesn't and I'll look into this again.