Home › Forums › General Issues › Error integrate with plugin
I’m trying to integrate the AFC with a plugin but an error occurs. The fields are all out of place
it is like this
so I had to is
What can be wrong?
I am using it in my plugin:
add_filter('acf/settings/path', 'my_acf_settings_path');
function my_acf_settings_path( $path ) {
// update path
$path = plugin_dir_path(__FILE__).'functions/acf/';
// return
return $path;
}
// 2. customize ACF dir
add_filter('acf/settings/dir', 'my_acf_settings_dir');
function my_acf_settings_dir( $dir ) {
// update path
$dir = plugins_url(). 'functions/acf/';
// return
return $dir;
}
// 3. Hide ACF field group menu item
add_filter('acf/settings/show_admin', '__return_false');
// 4. Include ACF
require_once( plugin_dir_path(__FILE__) . 'functions/acf/acf.php' );
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[] = plugin_dir_path(__FILE__).'functions/acf/json';
// return
return $paths;
}
Hi @atrevido
It’s possible that your code is executed before ACF is loaded. Could you please try to add the code in acf/init
hook? This page should give you more idea about it: https://www.advancedcustomfields.com/resources/acfinit/.
Also, please make sure that the returned path and URL are correct. You can also check the developer tools on your browser for any error messages on the page.
I hope this helps 🙂
remove this part and is now functioning normally
add_filter (‘acf /settings/dir’, ‘my_acf_settings dir’);
Hi @atrevido
Then it means there’s something wrong with how you set the directory. I believe you need to pass __FILE__
constant to get the current directory of the plugin like this:
$dir = plugins_url( 'functions/acf/', dirname(__FILE__) );
This page should give you more idea about it: https://codex.wordpress.org/Function_Reference/plugins_url.
I hope this helps 🙂
The topic ‘Error integrate with plugin’ 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.