2

When a user is blocked the (core) user profile is still accessible. I would rather show a message "this user profile has been removed".

I could write an exception into the user-profile.tpl.php. Is there a better way?

2 Answers 2

2

You should be able to implement hook_user_view in a custom module.

First create a page which contains your preferred content (e.g. "This user profile has been removed"). Let's call this node/1337 for now.

Secondly, you want something along the lines of the following:

function mymodule_user_view($account, $view_mode, $langcode) {
  if ($account->status == '0') {
    drupal_goto('node/1337');
  }
}

There are other parameters you can pass to drupal_goto if you wish (such as HTTP response code) - check out the API for more info :-)

2
  • Ooh, another note..you might want to put some authentication in for user 1 - as it's written, the code will block user 1 out of the profile as well. Sorry.
    – Chapabu
    Commented Dec 31, 2011 at 16:55
  • that's great, thank you. Looks like I can use the same code to hide the admin profile.
    – uwe
    Commented Dec 31, 2011 at 19:34
0

You can try to alter the page callback of user profile page, change the access callback to point to your custom function that determine whether a user is blocked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.