-1

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' );
}
shaaidaa
  • 3
  • 2
  • you check that `$user_roles` is an array before trying to call `array_shift()` on it like the warning is telling you about... – Scuzzy Nov 10 '19 at 08:16
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Scuzzy Nov 10 '19 at 08:17

2 Answers2

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

You can turn off your debugging in order to omit this warning from appearing on your website.

Locate the wp-config.php file for your WordPress website Edit the file and find the definition for WP_DEBUG it will somewhat look like: define( 'WP_DEBUG', true );

Change it to: define( 'WP_DEBUG', false ); Save the file, and reload your website.

Hope this works for you.

Tanish
  • 59
  • 4
  • Just turning off the error seems like a bad suggestion - what if something else went wrong? – Nigel Ren Nov 10 '19 at 08:19
  • I understand your conern about something else going wrong. But developers turn debugging ON only when the website is under development, in order to work on the code. When website is live, debugging need not be ON. – Tanish Nov 10 '19 at 08:20
  • The point of turning it on when developing locally is to catch these issues with code, not ignore them. The correct thing to do is listen to these warnings and not feed `null` into `array_shift` by wrapping it with conditional checking. – Scuzzy Nov 10 '19 at 08:32