2

I'm trying to find a D7 hook that runs on admin pages (admin/people/create to be exact). I've tried many hooks, but none of them seem to be firing on admin pages. What is the best way to detect if user is on admin/people/create?

Thanks

2
  • Depends what you're trying to accomplish
    – Clive
    Commented Jan 29, 2016 at 15:27
  • If it is a hook related to the theme it should go in the template.php file of the admin theme. Commented Jan 31, 2016 at 4:33

2 Answers 2

3

In case other people have the same question for D7, you can always use hook_page_alter(). It will be invoked on all pages. Here's an example:

function YOUR_MODULE_page_alter(&$page) {
  // Check if the user is on /admin/people/create.
  if (current_path() == 'admin/people/create') {
    // Do whatever you want.
  }
}

However, do bear in mind that:

  1. This code needs to be in a custom module in order to be invoked everywhere.
    If you add this to your front end theme, it will not be executed unless you are using the front end theme for managing the site as well.

  2. This way you can recognize if the user on that page, but you will not be able to alter the form. To alter the form, check out @Weboide's answer - you'll have to use hook_form_alter().

0

You could hook into the different forms that user_admin() uses.

There is:

  • user_register_form (for creating users)
  • user_multiple_cancel_confirm (for cancelling accounts)
  • user_filter_form (searching for users)
  • user_admin_account (also searching for users, but to do a mass update)

For example, to see when they're creating a user, using a hook like this could work:

function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id)
{
  // do your thing.
  if(user_access('administer users'))
    // then an admin is creating the account
}

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.