Action Hook since 2.0.0
admin_init
Fires at the beginning of every admin page
Description
admin_init is the admin counterpart to init: settings, redirects, and capability checks that must not run on the front-end.
When it runs
wp-admin only, on every admin request including admin-ajax. Does not run on the public site.
Signature
do_action( 'admin_init' );Examples
Basic
add_action( 'admin_init', function() {
register_setting( 'my_options_group', 'my_option_name' );
} );Register a settings API option on admin load.
Real case
add_action( 'admin_init', function() {
if ( ! current_user_can( 'manage_options' ) && ! wp_doing_ajax() ) {
wp_safe_redirect( home_url() );
exit;
}
} );Block non-admins from the wp-admin dashboard, while allowing AJAX requests through.
Common Use Cases
- Register plugin settings
- Redirect non-admin users
- Handle admin form submissions
- Add admin notices conditionally
Common mistakes
- Registering front-end post types on admin_init — they will be missing on the public site
Related hooks
FAQ
Can I redirect users away from wp-admin on admin_init?
Yes, that's a very common pattern — check current_user_can() and wp_redirect() + exit if the check fails, being careful to allow admin-ajax.php requests through.
Source: wp-admin/admin.php