When authoring WordPress plugins it is important to have an understanding of how WordPress loads. This knowledge will help you determine where in the sequence you’d like to inject your plugin code.
Here are the general calls as broken down in the WordPress Codex
Actions run during a typical request
These actions are run when a logged-in user opens the home page in Version 2.7 under the default theme:
1. plugins_loaded
2. sanitize_comment_cookies
3. setup_theme
4. auth_cookie_malformed
5. auth_cookie_valid
6. set_current_user
7. init
8. widgets_init
9. parse_request
10. send_headers
11. pre_get_posts
12. posts_selection
13. wp
14. template_redirect
15. get_header
16. wp_head
17. wp_print_styles
18. wp_print_scripts
19. loop_start
20. loop_end
21. get_sidebar
22. wp_meta
23. get_footer
24. wp_footer
Grouping them together in blocks, the sequence is as follows:
- Core Functionality Loads: Plugins & Pluggable Functions Loaded, Theme and Current User are Setup
- Init: init is an action that is fired after everything in WP has been loaded, but before wp() has been run.
- Start Wordpress: this includes the Parse Request, Applying rewrite rules, and sending the header
- Query Posts: Parse the Query, Get the Posts – there are more than 30 hooks and plugins available for modifying the queried data
- 404’s handled – Globals Registered
- Template Redirect:
- Template Load: Get header, Get Sidebar, Get Footer – all template filters and actions handled here too
* Special Thanks to Shawn Parker for his presentation