致命错误:Uncaught错误:调用未定义的函数get_field()



我有如下问题:

Fatal error: Uncaught Error: Call to undefined function get_field()
in /Users/My Repo/project_prod/wp-content/themes/project/functions.php:388
Stack trace:
#0 /Users/My Repo/project_prod/wp-includes/class-wp-hook.php(308): {closure}('')
#1 /Users/My Repo/project_prod/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#2 /Users/My Repo/project_prod/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /Users//My Repo/project_prod/wp-includes/script-loader.php(2012): do_action('wp_print_script...')
#4 /Users//My Repo/project_prod/wp-includes/class-wp-hook.php(308): print_head_scripts('')
#5 /Users//My Repo/project_prod/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#6 /Users//My Repo/project_prod/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#7 /Users//My Repo/project_prod/wp-admin/admin-header.php(146): do_action('admin_print_scr...')
#8 /Users//My Repo/project_prod/wp-admin/index.php(137): require_once('/Users//My ...')
#9 {main} thrown in /Users//My Repo/project_prod/wp-content/themes/project/functions.php on line 388

不幸的是,这个问题阻碍了对管理面板和主页的访问。我确实通过数据库更改了主题以更新冲突的插件(可能是ACF),不幸的是这是不可能的-插件列表为空。

在functions.php中抛出错误的行如下:

add_action('wp_print_scripts', function () {
global $post;
$sections =  get_field('sekcje',$post);
$dequeue = true;
if (!empty($sections)) {
foreach ($sections as $section) {
if ($section["acf_fc_layout"] == 'kontakt') {
$dequeue = false;
}
}
}
wp_dequeue_script( 'google-recaptcha' );
wp_dequeue_script( 'wpcf7-recaptcha' );
});

有人有主意吗

问题是你的代码是在你加载ACF插件之前执行的。如果所有的代码都放在plugins_loaded钩子中,那将是最好的。

add_action('plugins_loaded', function () {
add_action('wp_print_scripts', function () {
global $post;
$sections =  get_field('sekcje',$post);
$dequeue = true;
if (!empty($sections)) {
foreach ($sections as $section) {
if ($section["acf_fc_layout"] == 'kontakt') {
$dequeue = false;
}
}
}
wp_dequeue_script( 'google-recaptcha' );
wp_dequeue_script( 'wpcf7-recaptcha' );
});
});

也许重新激活ACF就能解决问题。

一般来说,你需要在你的插件工作之前强制加载ACF。

相关内容

最新更新