0

As mentioned here admin_init is the first hook triggered when access wordpress dashboard.

But when I test it I found tgmpa_register triggers first

add_action( 'admin_init', 'sr_admin_init' );
add_action( 'tgmpa_register', 'sr_register_required_plugins' );

function sr_admin_init(){
   // I NEED THIS TO TRIGGER FIRST
    wp_die("sr_admin_init");
}

function sr_register_required_plugins(){
   // this triggers first
    wp_die("sr_register_required_plugins");
}

Action hooks triggers:

  1. tgmpa_register
  2. admin_init: defines some variable like $GLOBALS['admin_page_hooks']

I have a complicated case, but in general I need to use variable $GLOBALS['admin_page_hooks'] in sr_register_required_plugins. But it is not working because tgmpa_register triggers first.

What should I do?

2

The codex entry you site is simply wrong! There are a lot of hooks fired before admin_init during admin requests, not least of which is init, which a lot of plugins use to do their initialization.

In particular, the TGM Plugin Activation plugin hooks into init (with the default priority = 10) with a function that calls do_action ('tgmpa_register').

Hence, you'll need to do something like:

// make sure we register this hook func with lower priority value than 
// TGM Plugin Activation does
add_action ('init', 'sr_admin_init', 9) ;

function
sr_admin_init ()
{
    if (!is_admin ()) {
        return ;
        }

    // I NEED THIS TO TRIGGER FIRST
    wp_die("sr_admin_init");
}

Edit

To be more charitable to the author of the codex entry you site: admin_init is the 1st "strictly admin"-related hook fired for admin requests. It's just not the 1st hook fired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.