PHP Warning – Invalid argument supplied for foreach()
-
I am getting a php warning showing up in my logs, a simple code tweak will deal with it…
Invalid argument supplied for foreach()
/wp-content/plugins/wp-persistent-login-premium/inc/user-count.php:127$allowed_roles = get_transient(‘persistent_login_allowed_roles_reference’);
foreach( $allowed_roles as $key => $value ) {In my use case, I have not set any of the allowed roles so the transient hasn’t been set yet. simply wrapping the foreach() in an if(is_array() && count()) will fix the warning.
if(is_array($allowed_roles) && count($allowed_roles)){
foreach( $allowed_roles as $key => $value ) {
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘PHP Warning – Invalid argument supplied for foreach()’ is closed to new replies.