Fires as an admin screen or script is being initialized.
Description
Note, this does not just run on user-facing admin screens.
It runs on admin-ajax.php and admin-post.php as well.
This is roughly analogous to the more general ‘init’ hook, which fires earlier.
Source
do_action( 'admin_init' );
Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |
Example migrated from Codex:
Another typical usage is to register a new setting for use by a plugin:
Example migrated from Codex:
This example works similarly to the first example, but it will automatically redirect users lacking the specified capability to the homepage.
Example migrated from Codex:
In this example, we block access to the admin panel for users that do not have the Administrator Role.
The above piece of code will only echo “Hello World” if the user is in admin screen.