Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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 in_array()期望参数2是数组,布尔值在第45行给出_Php_Arrays_Wordpress_Woocommerce - Fatal编程技术网

Php in_array()期望参数2是数组,布尔值在第45行给出

Php in_array()期望参数2是数组,布尔值在第45行给出,php,arrays,wordpress,woocommerce,Php,Arrays,Wordpress,Woocommerce,在服务器的错误日志中,我收到以下PHP警告: in_array()希望参数2是数组,布尔值在第45行的“//..”中给出 在第45行中,我设置了一个函数,用于检查WooCommerce插件是否处于活动状态 /** * Construction function */ public function __construct() { // Check if Woocomerce plugin is actived if ( ! in_array( 'woocommerce

在服务器的错误日志中,我收到以下PHP警告:

in_array()希望参数2是数组,布尔值在第45行的“//..”中给出

在第45行中,我设置了一个函数,用于检查WooCommerce插件是否处于活动状态

    /**
 * Construction function
 */
public function __construct() {
    // Check if Woocomerce plugin is actived
    if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
        return;
    }

    $this->new_duration = sober_get_option( 'product_newness' );

    $this->parse_query();
    $this->hooks();
}
用if语句检查它是否处于活动状态是必要的,有什么我没有看到的吗


错误不断出现在我的错误日志中。

您需要更改验证错误是否存在的方法

您的方法失败,因为您在_array()中使用了
,它需要将第二个参数设置为数组,但是
apply\u filters()
返回布尔值

更新 您可以尝试将
apply\u filters()
的结果转换为数组

if(!in_数组('woocommerce/woocommerce.php',(数组)apply_过滤器('active_plugins',get_选项('active_plugins'))){
返回;
}

是否应用过滤器()
返回数组?@MarkusZeller确实如此not@Akintunde-罗蒂米谢谢你。那就很清楚了<_array()中的code>需要第二个参数作为数组。array_filters()将返回一个数组。请检查此处:@Markus Zeller.get_option('active_plugins')--替换为默认的空数组=>get_option('active_plugins',array())--这是正确的WordPress方式。感谢Markus,将检查错误是否仍然存在,并已将代码添加到函数中。这让我很吃惊,因为我以前没有遇到过这个错误,感觉就像是在插件更新之后发生的一样。。我不确定我不喜欢函数混合返回。当你不亲自验证结果时,你不能依靠这一点。所以你可以
$result=apply_过滤器('active_plugins',get_选项('active_plugins'))
然后评估它是否是一个数组。但是如果你想检查一个插件是否处于活动状态,并且确实有一个测试该插件的函数,那么应该使用它。如果更改返回任何错误,我将检查一整天。。要学习的东西太多了……旧代码必须重写,在写了is_plugin_active之后,错误是PHP致命错误:未捕获错误:调用***中未定义的函数is_plugin_active(),然后继续向我展示堆栈竞争。
if(!is_plugin_active('woocommerce/woocommerce.php')) {
    return;
}