Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “如何删除此警告”;警告:array_shift()要求参数1为数组,在“…”中为空;从我的网站顶部?_Php_Wordpress_Visual Composer - Fatal编程技术网

Php “如何删除此警告”;警告:array_shift()要求参数1为数组,在“…”中为空;从我的网站顶部?

Php “如何删除此警告”;警告:array_shift()要求参数1为数组,在“…”中为空;从我的网站顶部?,php,wordpress,visual-composer,Php,Wordpress,Visual Composer,我正在Wordpress中使用Visual Composer插件。我试图改变标题的背景颜色。外观>自定义不起作用,所以我安装了一个名为“简单自定义CSS”的插件。我将CSS添加到这个插件中,然后标题就可以了,但我在网站顶部得到了以下警告: 警告:array_shift()要求参数1为数组,在 /home/devpaad/public_html/wp content/themes/businext/myfunctions.php 在线411 这就是警告所说的那条线: /** Allow cust

我正在Wordpress中使用Visual Composer插件。我试图改变标题的背景颜色。外观>自定义不起作用,所以我安装了一个名为“简单自定义CSS”的插件。我将CSS添加到这个插件中,然后标题就可以了,但我在网站顶部得到了以下警告:

警告:array_shift()要求参数1为数组,在 /home/devpaad/public_html/wp content/themes/businext/myfunctions.php 在线411

这就是警告所说的那条线:

/**
Allow customers to access wp-admin
*/
global $current_user; 
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if($user_role == "stgh_client") {
    add_filter( 'woocommerce_prevent_admin_access', '__return_false' );
}

您可以关闭调试,以便在网站上忽略此警告

找到WordPress网站的wp-config.php文件 编辑该文件并查找WP_DEBUG的定义 它看起来有点像:define('WP_DEBUG',true)

将其更改为:define('WP_DEBUG',false) 保存文件,然后重新加载网站


希望这对您有用。

在尝试调用
array\u shift()
之前,请检查
$user\u roles
是否为数组,就像警告告诉您的那样……这是否回答了您的问题?仅仅关闭错误似乎是一个坏建议-如果其他事情出错了怎么办?我理解你对其他事情出错的看法。但是开发人员只有在网站处于开发阶段时才打开调试,以便处理代码。当网站处于活动状态时,调试不需要打开。在本地开发时打开调试的目的是用代码捕捉这些问题,而不是忽略它们。正确的做法是倾听这些警告,而不是通过使用条件检查将
null
馈送到
array\u shift
中。非常感谢:)
$user_roles = $current_user->roles;
if (is_array($user_roles) && array_shift($user_roles) == "stgh_client") {
    add_filter( 'woocommerce_prevent_admin_access', '__return_false' );
}