Show block to certain users or roles only- Drupal 4.6
Note: Some of the examples from this section may not work with versions of Drupal older than 4.5.
Example: you want to show a block only to logged-in users. Site administrators often wish to restrict anonymous users from seeing certain (custom) blocks. Placing the following code in a PHP block will achieve this.
<?php
global $user;
if ($user->uid) {
return "This block is only visible for logged-in users.";
} else {
return;
}
?>Replace the string "This block is only visible for logged-in users." with anything you want to display only to logged-in users.
You could also put the contents in an IF / ENDIF statement:
<?php
global $user;
if ($user->uid): ?>
<ol>
<li><a href="/linky">lorem ipsum</a></li>
<li><a href="/linky_too">lorum ipsum</a></li>
</ol>
<?php else:
return;
endif;
?>If you want a more html friendly way to display the information contained.
The block will not be shown at all for users who are not logged-in. You can replace the single return in the else-block with, e.g.,
<?php
return "This block is only visible for logged-in users.";
?>to show some text instead of not displaying the block at all.
Example: Wrapping HTML content so it is visible only to anonymous users. This example uses an if/endif construction to wrap some HTML in a few lines of PHP which will show the content only to anonymous users.
<?php
global $user;
if (!$user->uid) : ?>
<p>This content will be visible only to anonymous users.</p>
<?php else {
return;
}
endif;
?> 4.6 Example: Showing a block only to certain users. If you want to show a certain custom block only to a certain user, you can use the following code in a PHP block:
<?php
global $user;
if ($user->uid == 19) {
return "This block is only visible for the user with the user-ID 19.";
} else {
return;
}
?>4.6 Example:To show to specific roles only in Drupal 4.6. In this example the role is "admin user".
<?php
global $user;
$output = '';
if (in_array('admin user',$user->roles)) {
$output .= '<i>A block for admin users</i>';
$output .= '<ul>';
$output .= '<li><a href=/"?q=Admin/">Administration interface</a></li>';
$output .= '</ul>';
}
return $output;
?>
transparent admin
drupal 6.x, v6 transparent admin
I am looking for transparent administration, open, visible and sometimes editable admin settings with security. based on permissions, locked individually (as a node?), password protected, view and/or edit choice for admin inserted at the top or bottom of all admin/settings pages. even better, password or radio button next to every settings choice as viewable and/or editable similar to form field protect. a prominent notification to the user, “you can view this page of administration settings, if they require edit, please email administration with your request link”. Possibly even attached comment or site note section, ability to insert instruction or voting widget.
I gather this is the approach taken by adding access control to the core and maybe it is similar to drupal core building. I have been looking at everything I can find and I’m not a programmer yet, so I need to pass what I’ve found on to someone else here. If someone can put these pieces together or have experience with something similar with any version 4,5,6,7. i'm listing this at all of these locations aswell. Rsvp, elisa
http://drupal.org/node/109157 access control
http://drupal.org/node/131101#comment-735943 Add disabled attribute to protected fields
http://drupal.org/node/245900 How to Protect Nodes From Editing on Demand
http://drupal.org/node/31143#comment-796152 Node Privacy by Role not working
http://drupal.org/project/nodeaccess nodeaccess
http://drupal.org/node/126129#comment-703933 password protect a page
http://drupal.org/node/222263#comment-902378 Port of Content access for D6
http://drupal.org/node/29991#comment-51352 Protected content
http://drupal.org/node/13266 Show block to certain users or roles only- Drupal 4.6
http://drupal.org/project/simple_access simple access
http://drupal.org/node/118404#comment-735895 View, but not edit, field at node/xxx/edit