Wordpress - How to get WordPress' hooks/actions run sequence?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

-The Adventure of the Copper Beeches

So let's gather some real data from an install with no plugins and the TwentyTwelve theme activated with only a single Text widget.

For the home page the following do_action calls are made in the following order:

muplugins_loaded
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_post_type
registered_post_type
registered_post_type
registered_post_type
registered_post_type
plugins_loaded
sanitize_comment_cookies
setup_theme
unload_textdomain
load_textdomain
after_setup_theme
load_textdomain
load_textdomain
auth_cookie_malformed
auth_cookie_valid
set_current_user
init
registered_post_type
registered_post_type
registered_post_type
registered_post_type
registered_post_type
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_taxonomy
widgets_init
register_sidebar
register_sidebar
register_sidebar
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_register_sidebar_widget
wp_loaded
parse_tax_query
parse_tax_query
posts_selection
template_redirect
admin_bar_init
add_admin_bar_menus
get_header
wp_head
wp_enqueue_scripts
wp_print_styles
wp_print_scripts
get_template_part_content
begin_fetch_post_thumbnail_html
end_fetch_post_thumbnail_html
get_template_part_content
get_template_part_content
get_template_part_content
get_template_part_content
get_template_part_content
get_template_part_content
get_template_part_content
get_template_part_content
get_template_part_content
begin_fetch_post_thumbnail_html
end_fetch_post_thumbnail_html
get_sidebar
dynamic_sidebar_before
dynamic_sidebar
dynamic_sidebar_after
get_footer
twentytwelve_credits
wp_footer
wp_print_footer_scripts
wp_before_admin_bar_render
wp_after_admin_bar_render
shutdown

If you want to check the order of actions and how many times each one is fired, then you can use for example:

add_action( 'shutdown', function(){
    print_r( $GLOBALS['wp_actions'] ); 
});

or this prettified version:

add_action( 'shutdown', function(){
    foreach( $GLOBALS['wp_actions'] as $action => $count )
        printf( '%s (%d) <br/>' . PHP_EOL, $action, $count );

});

to get the following list:

muplugins_loaded (1) 
registered_taxonomy (10) 
registered_post_type (10) 
plugins_loaded (1) 
sanitize_comment_cookies (1) 
setup_theme (1) 
unload_textdomain (1) 
load_textdomain (3) 
after_setup_theme (1) 
auth_cookie_malformed (1) 
auth_cookie_valid (1) 
set_current_user (1) 
init (1) 
widgets_init (1) 
register_sidebar (3) 
wp_register_sidebar_widget (12) 
wp_loaded (1) 
parse_request (1) 
send_headers (1) 
parse_tax_query (2) 
parse_query (1) 
pre_get_posts (1) 
posts_selection (1) 
wp (1) 
template_redirect (1) 
wp_default_scripts (1) 
wp_default_styles (1) 
admin_bar_init (1) 
add_admin_bar_menus (1) 
get_header (1) 
wp_head (1) 
wp_enqueue_scripts (1) 
wp_print_styles (1) 
wp_print_scripts (1) 
loop_start (1) 
the_post (10) 
get_template_part_content (10) 
begin_fetch_post_thumbnail_html (2) 
end_fetch_post_thumbnail_html (2) 
loop_end (1) 
get_sidebar (1) 
dynamic_sidebar_before (1) 
dynamic_sidebar (1) 
dynamic_sidebar_after (1) 
get_footer (1) 
twentytwelve_credits (1) 
wp_footer (1) 
wp_print_footer_scripts (1) 
admin_bar_menu (1) 
wp_before_admin_bar_render (1) 
wp_after_admin_bar_render (1) 
shutdown (1) 

PS: You should also check out the great Query Monitor plugin by John Blackbourn. (I'm not related to this plugin)


Here is the WordPress load chart

WordPress Load Chart

→ Source by @Rarst


Found Solution!

Thanks @birgire for nice answer. I will add to that, muplugins_loaded sometimes is not fired, so I will use plugins_loaded as the most first hook (but at that time, user-authorization is not done yet. If you want to check user's authorization, then init is the earliest for that)...

p.s. there exist excellent plugins:

1) Query Monitor - You can see everything what happens on the page-load, i.e. duration of each executed function and much more(view all screenshots on plugin page):

enter image description here

2) WP-DEBUG-BAR + WP-DEBUG-SLOW-ACTIONS:
a) debug hooks(actions) run list on your site.
b) See duration of each action (not function): enter image description here

Tags:

Hooks