Reputation: 39
In the error log of my server i´m getting the following PHP Warning:
in_array() expects parameter 2 to be array, boolean given in " //..." on line 45.
In line 45 i have set a function that checks wether WooCommerce plug-in is active.
/**
* 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();
}
Checking if it´s active with the if statement is necessary, is there anything i´m not seeing?
The error keeps popping up in my error log.
Upvotes: 0
Views: 219
Reputation: 9135
You need to change the method how you verify if a plugin is available.
if(!is_plugin_active('woocommerce/woocommerce.php')) {
return;
}
Your method fails, because you check with in_array()
which needs to have the 2nd parameter being an array, but apply_filters()
returns a bool.
You could try to cast the result of apply_filters()
being an array.
if ( ! in_array( 'woocommerce/woocommerce.php', (array)apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
return;
}
Upvotes: 1