Following this giude: http://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/
I’ve got a plugin that is calling a script. It checks if the class “acf” exists. If it does not exist, it includes ACF Pro from the plugin files. This should let you use ACF Pro as a plugin if you want to keep it updated.
So I’ve got it figured out, with the help of a couple global vars to transmit the paths:
function limelight_include_acf_files( $acf_path, $acf_url, $hide_menu = false ) {
global $ld_acf_paths;
$ld_acf_paths = array(
'path' => $acf_path,
'url' => $acf_url,
);
// 1. customize ACF path
add_filter('acf/settings/path', 'limelight_acf_settings_path');
// 2. customize ACF dir
add_filter('acf/settings/dir', 'limelight_acf_settings_dir');
// 3. Hide ACF field group menu item
if ( $hide_menu ) add_filter('acf/settings/show_admin', '__return_false');
// 4. Include ACF
include_once( $acf_path . 'acf.php' );
var_dump($ld_acf_paths);
var_dump($acf_path . 'acf.php');
var_dump(acf()->settings);
}
function limelight_acf_settings_path( $path ) {
global $ld_acf_paths;
return $ld_acf_paths['path'];
}
function limelight_acf_settings_dir( $dir ) {
global $ld_acf_paths;
return $ld_acf_paths['url'];
}
See the var_dumps at the end of “limelight_include_acf_files”? They report the following:
'path' => string 'G:\Web Development\Wamp Server\www\sports\wp-content\plugins\limelight-ezad-replacement\acf/advanced-custom-fields-pro/' (length=119)
'url' => string 'http://localhost/sports/wp-content/plugins/limelight-ezad-replacement/acf/advanced-custom-fields-pro/' (length=101)
string 'G:\Web Development\Wamp Server\www\sports\wp-content\plugins\limelight-ezad-replacement\acf/advanced-custom-fields-pro/acf.php' (length=126)
array (size=21)
'name' => string 'Advanced Custom Fields PRO' (length=26)
'version' => string '5.3.2.2' (length=7)
'basename' => string 'limelight-ezad-replacement/acf/advanced-custom-fields-pro/acf.php' (length=65)
'path' => string 'G:\Web Development\Wamp Server\www\sports\wp-content\plugins\limelight-ezad-replacement\acf\advanced-custom-fields-pro/' (length=119)
'dir' => string 'http://localhost/sports/wp-content/plugins/limelight-ezad-replacement/acf/advanced-custom-fields-pro/' (length=101)
'show_admin' => boolean true
......
'pro' => boolean true
}
This all looks good. The directory and URLs are correct (barring the backslash/forward slash mixup, but PHP doesn’t mind that). The ACF function is pulling in the settings properly, as we can see at the end.
All is well so far, but I get a ton of errors on the admin.
( ! ) Notice: Trying to get property of non-object in G:\Web Development\Wamp Server\www\sports\wp-content\plugins\limelight-ezad-replacement\acf\advanced-custom-fields-pro\api\api-helpers.php on line 19
Line 19: $settings = acf()->settings;
( ! ) Warning: Attempt to modify property of non-object in G:\Web Development\Wamp Server\www\sports\wp-content\plugins\limelight-ezad-replacement\acf\advanced-custom-fields-pro\api\api-helpers.php on line 72
Line 72: acf()->settings[ $name ] = $value;
—
It’s as if acf() isn’t available anymore.
Any ideas?
Here is a copy of the plugin so far. Which is almost nothing. I removed ACF Pro itself from the “acf” folder so you’ll need to put that in t here yourself.
https://drive.google.com/file/d/0B91C2X4n3qgRaW5aN0lETnY3Vm8/view?usp=sharing
Hi
I have the same issue here
Did you success to solve it?
Michael
No, unfortunately. I’ve tried a few things to get it to work but in the end I had given up.
Hi
Ive succeeded to solve this issue at least in my end
Heres the code:
// 1. customize ACF path
add_filter('acf/settings/path', 'my_acf_settings_path');
function my_acf_settings_path( $path ) {
// update path
$path = dirname( __FILE__ ) . '/libs/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 = plugin_dir_url( __FILE__ ) . 'libs/acf/';
// return
return $dir;
}
// 3. Hide ACF field group menu item
//add_filter('acf/settings/show_admin', '__return_false');
// 4. Include ACF
include_once( 'libs/acf/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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 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.