When is admin_init Action ran?

I have this function below that is called with the admin_init Action

function my_flush_rewrites() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

Like this

Read More
add_action('admin_init', 'my_flush_rewrites');

I am curious, when is this called? Is this called on every page load? Hopefully not

Related posts

Leave a Reply

3 comments

  1. From the Codex:

    admin_init is triggered before any other hook when a user access the
    admin area. This hook doesn’t provide any parameters, so it can only
    be used to callback a specified function.

    So yes, it’s run on every admin page load.

  2. All the hooks are executed after the core WordPress application completes its loading process.

    So initialization hooks are mainly used to initialize the process in plugins and themes.

    Available init hooks in WordPress, in the order of their execution are –

    1)init -> runs after WordPress has finished loading but before any headers are sent. Generally, this used by plugins to initialize their process.

    2)widgets_init -> is used to register sidebar widgets of the application. The register_widgetfunction is executed within this hook.

    3)admin_init -> is executed as the first action, when user access the admin section of WordPress. Generally, it’s used to initialize settings specific to the admin area.

    admin_init hook runs every time admin page is rendered.

    You can also look into WordPress Codex for more information about activation process.

  3. admin_init is triggered when a user accesses the admin area. It is the first hook to be triggered. It can be used in cases like:

    1. We want to block access to the admin panel for users that do not have the Administrator Role.
    2. We want automatic redirection of users lacking the specified capability, to the homepage.
    3. We want to register a new setting for use by a plugin.