首页 > 解决方案 > WordPress 调试 - call_user_func_array() 期望参数 1 是有效的回调

问题描述

我刚刚将我的 WordPress 更新到了新版本,我收到了这个错误:

警告:call_user_func_array() 期望参数 1 是有效的回调,在第 287 行的 /home/burngeopk/public_html/members/wp-includes/class-wp-hook.php 中未找到函数“restrict_admin”或无效函数名

在我的主题的function.php 中只有1 个字符串具有restrict_admin。我正在寻找如何改写这个字符串以使其工作的指导。

add_action( 'admin_init', 'restrict_admin', 1 );
function my_function_admin_bar($content) {
  return ( current_user_can( 'administrator' ) ) ? $content : false;
}

标签: phpwordpresswordpress-theming

解决方案


看起来这个功能restrict_admin已经不存在了。

尝试将其添加回您的主题?这里是它的源代码:

function restrict_admin() {
 
    if ( ! current_user_can( 'manage_options' ) && ( ! wp_doing_ajax() ) ) {
        wp_die( __( 'You are not allowed to access this part of the site' ) );
    }
}

来源: https ://developer.wordpress.org/reference/hooks/admin_init/


推荐阅读