Home › Forums › General Issues › Handle acf-json outside of the theme
I am looking for a consistent way to handle the acf-json local files outside of theme and within a plugin.
add_filter('acf/settings/save_json', 'my_acf_json_save_point');
function my_acf_json_save_point( $path ) {
// update path
$path = get_stylesheet_directory() . '/my-custom-folder';
// return
return $path;
}
How do we reproduce this in a plugin and deal with dependencies / priority so that it loads properly? I would also suggest the documentation (http://www.advancedcustomfields.com/resources/local-json/) be updated to reflect the strong movement towards moving functionality out of the theme.
Any help would be appreciated!
Here is the answer
<?php
add_filter('acf/settings/save_json', 'my_acf_json_save_point');
function my_acf_json_save_point( $path ) {
// update path
$path = dirname( __FILE__ ) . '/acf-json';
// return
return $path;
}
add_filter('acf/settings/load_json', 'my_acf_json_load_point');
function my_acf_json_load_point( $paths ) {
// remove original path (optional)
unset($paths[0]);
// append path
$paths[] = dirname( __FILE__ ) . '/acf-json';
// return
return $paths;
}
The problem with setting the save point to somewhere in you plugin is that there can only be one save point. So if you override it your plugin then all saves will go to your plugin folder, unless that’s what you’re aiming for. However, as another developer that uses ACF I wouldn’t be to happy about a plugin changing the save point, just saying.
I’d prefer to see the /acf-json/ directory and files located one level up in the /wp-content/ root.
Perhaps still also looking in the /theme-name/ directory as a secondary lookup if not found in /wp-content/ to preserve backward compatibility.
This would be in-keeping with other plugins that do this, like:
WP-CFM:
https://wordpress.org/plugins/wp-cfm/
Saves in > /wp-content/config/
Custom Global Variables:
https://wordpress.org/plugins/custom-global-variables/
Saves in > /wp-content/custom-global-variables/
The topic ‘Handle acf-json outside of the theme’ is closed to new replies.
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.