This information has been updated!
请访问ACF的网站:
https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/你只要检查一下ACF类是否存在if( !class_exists(\'acf\') )
要检查用户是否已经安装了ACF,如果没有安装,请返回您的ACF版本以及插件或主题,设置ACF_LITE
“至”;“不是”;向用户显示ACF菜单。。。
但是,如果用户决定自己安装ACF,它将按照预期覆盖插件或主题中包含的版本:)。
// Optionally you can use below to check by plugin location:
// if((is_plugin_active(\'advanced-custom-fields/acf.php\'))|| (is_plugin_active(\'advanced-custom-fields-pro/acf.php\'))):
// Check if ACF Classes exists:
if(!class_exists(\'acf_pro\') || !class_exists(\'acf\')):
// Define path and URL to the ACF plugin.
define( \'MY_ACF_PATH\', get_stylesheet_directory() . \'/includes/acf/\' );
define( \'MY_ACF_URL\', get_stylesheet_directory_uri() . \'/includes/acf/\' );
// Include the ACF plugin.
include_once( MY_ACF_PATH . \'acf.php\' );
// Customize the url setting to fix incorrect asset URLs.
add_filter(\'acf/settings/url\', \'my_acf_settings_url\');
function my_acf_settings_url( $url ) {
return MY_ACF_URL;
}
// (Optional) Hide the ACF admin menu item.
add_filter(\'acf/settings/show_admin\', \'my_acf_settings_show_admin\');
function my_acf_settings_show_admin( $show_admin ) {
return false;
}
endif;
还有。使用ACF创建字段和字段组后,使用ACF的导出功能将它们导出到PHP。然后将导出的PHP包含到插件/主题中。
ACF是如此强大。我很感谢Elliott的慷慨,他甚至允许我们使用PRO制作插件!