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
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
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:
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.
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()
.
You could hook into the different forms that user_admin()
uses.
There is:
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
}