Home › Forums › General Issues › Bundling ACF in plugin
I am trying to bundle ACF in a plugin as per documentation but having issues.
https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/
No problems inserting in the theme.
What changes do I need to make for the plugin load?
Eg:
function sh_setup_acf()
{
// Include ACF.
// 1. customize ACF path
add_filter('acf/settings/path', 'my_acf_settings_path');
function my_acf_settings_path( $path )
{
// update path
$path = plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/';
// 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 = plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/';
// return
return $dir;
}
// 3. Hide ACF field group menu item
add_filter('acf/settings/show_admin', '__return_true');
// 4. Include ACF
include_once( plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/acf.php' );
}
add_action( 'plugins_loaded', 'sh_setup_acf');
More than likely ACF has called those hooks before ‘plugins_loaded’, but that’s just a guess.
Try not adding the filters inside of another filter. You can add filters when the file that function is in is loaded.
Also, functions added inside of function become top level function in ACF, however… A function inside of a filter, well, the filter is called inside a class in WP and if I’m not mistaken, those functions become part of the class. It could be that just moving the functions outside of your action filter will correct the problem.
Sorry the code should have been
function my_acf_settings_path( $path )
{
// update path
$path = plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/';
// return
return $path;
}
function my_acf_settings_dir( $dir )
{
// update path
$dir = plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/';
// return
return $dir;
}
function sh_setup_acf()
{
// Include ACF.
// 1. customize ACF path
add_filter('acf/settings/path', 'my_acf_settings_path');
// 2. customize ACF dir
add_filter('acf/settings/dir', 'my_acf_settings_dir');
// 3. Hide ACF field group menu item
add_filter('acf/settings/show_admin', '__return_true');
// 4. Include ACF
include_once( plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/acf.php' );
}
add_action( 'plugins_loaded', 'sh_setup_acf');
Essentially I am just looking for the standard way of adding ACF to a plugin
I don’t know that there is a standard way to set up acf in a plugin other than what is posted.
But I would try adding the filters for the acf functions without them being in another filter first to see if that corrects the problem you’re seeing.
function my_acf_settings_path( $path )
{
// update path
$path = plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/';
// return
return $path;
}
function my_acf_settings_dir( $dir )
{
// update path
$dir = plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/';
// return
return $dir;
}
// Include ACF.
// 1. customize ACF path
add_filter('acf/settings/path', 'my_acf_settings_path');
// 2. customize ACF dir
add_filter('acf/settings/dir', 'my_acf_settings_dir');
// 3. Hide ACF field group menu item
add_filter('acf/settings/show_admin', '__return_true');
// 4. Include ACF
include_once( plugin_dir_path() . 'myplugin/vendors/advanced-custom-fields-pro/acf.php' );
You must be logged in to reply to this topic.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.