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

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

admin_init → init

functions.php — admin_init
functions.php
PHP admin_init · Hook 1 of 2 · Step 1 of 7

Practice the admin_init WordPress action hook in our interactive sandbox — a VS Code-style editor with a step-by-step admin_init tutorial, add_action exercises, and instant feedback. No local WordPress install required.