phpwordpressvisual-composer

How to remove this warning" Warning: array_shift() expects parameter 1 to be array, null given in ..." from the top of my website?


I am using Visual Composer plugin in Wordpress. I was trying to change the header's bg color. The appearance>customize didn't work, so I installed a plugin named "Simple Custom CSS". I added the CSS to this plugin, then the header is ok but I get this Warning on the top of the website :

Warning: array_shift() expects parameter 1 to be array, null given in /home/dejpaad/public_html/wp-content/themes/businext/myfuncations.php on line 411

http://dejpaad.com/

This is the line the warning is talking about:

/**
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' );
}

Solution

  • $user_roles = $current_user->roles;
    if (is_array($user_roles) && array_shift($user_roles) == "stgh_client") {
        add_filter( 'woocommerce_prevent_admin_access', '__return_false' );
    }