DataGuy
DataGuy

Reputation: 1725

block visibility by role

I am using Drupal 7 with block visibility rules. I just need my blocks to show when users have registered for the site (authenticated) and not to show when non-registered users (anonymous) are visiting the site. I have the visibility settings by role correct in my blocks configuration, but the blocks are still displayed regardless of role.

Whats really weird is that I have one page that is working correctly and the other 40+ that arent.

Ive ready that I should be able to control the visibility in the block content itself using PHP and something like this:

<?php
global $user;
  if (in_array('Approved Role',$user->roles)) {
return TRUE;
 } else {
return FALSE;
}
?>

But Im not sure how to implement it. I have the PHP filter on, but where do I add my content?

Thanks!

Upvotes: 0

Views: 399

Answers (1)

DataGuy
DataGuy

Reputation: 1725

figured it out!

<?php
global $user;
if ($user->uid){ ?>

html goes here

} else {
return FALSE;
}
?>

Upvotes: 2

Related Questions