Blocks Only On Admin Pages

DanDaMan - March 31, 2006 - 03:49

I've gotten my site to the point where most regular users are just going to make comments and posts in the forums. Therefore, they don't need the main navigation bar.

One option in "configuring" the Navigation block is to have it run when a box of PHP code returns true. Is there a magic set of PHP code to see if the person is a member of this or that role level?

I looked around the forums and found some things, but most seemed to be applicable to 4.6 and creating a custom module. I'd love to use less non-custom and more core settings.

Thanks in advance for your help.

Dan

Menu module

blarg - March 31, 2006 - 04:10

Not sure if this fits what you need, but using the Menu module you can just turn off the things "normal users" don't need and the admin would still have full access to the entire menu.

Do you need more fine grained control over this?

easy snippets for this

pwolanin - March 31, 2006 - 04:12

I previously put together some links to drupal pages covering this topic:

http://drupal.org/node/52142#comment-98381

As an example, the code below could be used to only show a block to users with the role "content adder":

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

Thanks!

DanDaMan - March 31, 2006 - 04:47

Thanks, pwolanin!

I guess I have to learn a bit about how to find what I need on drupal.org. It's usually here, but just not easily visible.

That snippet of code did the trick. You're the best.

Dan "da Man"
Webmaster
http://cMusicWeb.com/
http://da-Man.com/

Can I put this 'page specific visibility settings'?

adoucette - June 24, 2006 - 16:41

I would like to put something like this in the 'page specific visibility settings' of administer -> block so that a certain block will only be shown to certain roles.
Under "Show if the following PHP code returns TRUE (PHP-mode, experts only)." I have put the following code:

global $user;
if (in_array('administrator',$user->roles)) {
  return TRUE;
}
else if (in_array('meduser',$user->roles)) {
  return TRUE;
}
else {
return FALSE;
}

But it doesn't work right for me. I still get the block for every user (even unauthenticated). What have I done wrong?
TIA,
Ariel

Found the answer

adoucette - June 24, 2006 - 17:15

Here's a post that answers my question.
http://drupal.org/node/51325#comment-124601
Ariel

 
 

Drupal is a registered trademark of Dries Buytaert.