Hi,

I have created a custom block containing a few pictures and links. On my page, nothing is enabled for anonymous users (whole content is disabled), they just see the does-not-have-authorization text plus the login block.
And also this custom block appears. How can I disable it?

Thanks,
hf

Comments

jjeff’s picture

Go to admin/block and click on "configure" for the block you want to control. Under "Page specific visibility settings", select "Show if the following PHP code returns TRUE" and type the following code into the "Pages" textarea:

-------------8< cut here -----------------

global $user;
return ($user->uid > 0);

----------------------------------------------

Explanation: Anonymous users have the user id 0, so this block will only show up for users whose user id is greater than (>) zero. This is all logged-in users.

Enjoy!

--= Jeff Robbins | www.lullabot.com =--

heine’s picture

Drupal 4.6 doesn't have this functionality :-). You'll have to make the custom block do the work.

To do this go to the configuration page of your custom block, set the input filter to PHP and add the following code to the top of the contents:

global $user;
if(!$user->uid) 
  return;

(content goes below the code)

The above code, checks whether the user ID is 0 (NOT 0 is true) and if so, silently returns; the block won't be displayed.

If the user ID is > 0 it the block won't 'return' prematurely and is displayed.

(edit: added more of an explanation)
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

hf’s picture

I have 4.6.5 and I have only these settings:
Page specific visibility settings
Show block on specific pages:

  • Show on every page except the listed pages.
  • Show on only the listed pages.

    Heine's idea works. Thanks!!!

    Should I upgrade to 4.7? What is the experience in general with 4.7?