Skip to content

Instantly share code, notes, and snippets.

Last active May 20, 2024 09:35
Show Gist options
  • Save johnbillion/4fa3c4228a8bb53cc71d to your computer and use it in GitHub Desktop.
Save johnbillion/4fa3c4228a8bb53cc71d to your computer and use it in GitHub Desktop.
WordPress Flow
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
load l10n library
load mu plugins
DO_ACTION 'muplugins_loaded' (only accessible to mu plugins)
load active plugins
load pluggables.php
DO_ACTION 'plugins_loaded' (first hook available to plugins)
load rewrite rules
instantiate $wp_query, $wp_rewrite and $wp.
$wp_query is a global instance of the WP_Query class. For more info, see ANY QUERY
$wp_rewrite is a global instance of the WP_Rewrite class and contains our rewrite rules and functions
$wp is a global instance of the WP class and contains the functions that will parse our request and perform the main query (see REQUEST)
DO_ACTION 'setup_theme'
include child theme functions.php
include parent theme functions.php
DO_ACTION 'after_setup_theme' (first hook available to themes)
set up current user object
DO_ACTION 'init'
register widgets (DO_ACTION 'widget_init')
call wp() (which calls $wp->main())
loop over rewrite rules to find a match
APPLY_FILTERS 'query_vars' to the publicly available query vars
fill query vars with $_POSTs, $_GETs, and rewritten vars
APPLY_FILTERS 'request' to the request variables
DO_ACTION_REF_ARRAY 'parse_request' with array of request vars (query vars, request, matched rewrite rules, etc)
DO_ACTION_REF_ARRAY 'send_headers' with the 'WP' object.
if posts are empty, set is_404() (and send 404 headers)
set all the query_vars to global variables
DO_ACTION_REF_ARRAY 'wp' with the main WP object
WP_Query->query( query vars )
WP_Query->parse_query( query vars )
build query parameters based off query vars
set WP_Query->is_* vars based off query parameters
if this query is $wp_the_query then these determine the values of the global is_*() functions too
DO_ACTION_REF_ARRAY 'parse_query' with WP_Query object (query parameters, query vars, conditionals)
DO_ACTION_REF_ARRAY 'pre_get_posts' with WP_Query object
APPLY_FILTERS_REF_ARRAY 'posts_search' with search SQL
series of APPLY_FILTERS on the query SQL (if suppress_filters=false):
* posts_where
* posts_join
* posts_where_paged
* posts_groupby
* posts_join_paged
* posts_orderby
* posts_distinct
* post_limits
* posts_fields
* posts_clauses
APPLY_FILTERS_REF_ARRAY 'posts_request' (if suppress_filters=false)
fetch posts from the database
APPLY_FILTERS_REF_ARRAY 'posts_results' (if suppress_filters=false)
prepend sticky posts
APPLY_FILTERS_REF_ARRAY 'the_posts' (if suppress_filters=false)
return posts
DO_ACTION 'template_redirect'
if is_feed()
load the feed template
look for template file in theme based on template hierarchy
APPLY_FILTERS 'template_include'
load the template file (which usually runs a loop @TODO document a loop)
DO_ACTION 'shutdown'
Copy link

ozh commented Mar 24, 2015


Copy link

jg314 commented May 22, 2015

Great rundown. Thanks for sharing.

Copy link

Exactly what I was looking for. Thanks!

Copy link


Copy link

Awesome! Thank you sooo much! 💃

Copy link

safizn commented Aug 2, 2016


Copy link

Thanks so much! ★

Copy link

MQuigg commented Feb 15, 2020

Thanks, this is excellent! Has this changed any over the past few years?

Copy link

@MQuigg it's quite out of date, but generally still accurate

Copy link

lkraav commented Nov 25, 2021

Landed from

Very nice @johnbillion do you think we could continously auto-generate this from source code?

Copy link

To be honest I don't think so. The intention isn't to cover every action that fires and every file that loads, just the ones that are of interest to plugin and theme developers and contributors. I think that's best done with manual curation.

Something automated that describes the difference in the loading flow from one version to the next would be useful though.

Copy link

amitworx commented Dec 4, 2021

Thanks for sharing. Its really helpful.

Copy link

I've just been made aware of by Jānis Elsts which is a more comprehensive and better formatted way of viewing the load order and hooks that fire during a request to WordPress. Check it out!

Copy link

MQuigg commented Jan 8, 2024

@johnbillion Very nice! We've been using his Admin Menu Editor Pro plugin for years. Thanks to both of you for this very useful information.

Copy link

Awesome thanks for the link, it looks very useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment