Hello !

I've put some PHP code in a page visibility parameters of a block to hide the block if user doesn't own certain roles. It works fine when a user is connected, but if it disconnects then the block appears. So I want to know how to hide blocks if nobody is connected to the site.

Here is the code I'm using:

global $user;

if (in_array(['RoleBE','admin user'],$user->roles)) 
  return TRUE;
else
return FALSE;

Thanks for help.
Michel.

Comments

tyswan’s picture

to check if a user is logged in or not, use this snippet
http://drupal.org/node/23449

I'm not a php expert, but I think it should be:

global $user;

if ((in_array(['RoleBE','admin user'],$user->roles))
       AND ($user->uid))
  return TRUE;
else
return FALSE;