Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sawwd/2d2ad51eb4075d2335ed7573f0be2e53 to your computer and use it in GitHub Desktop.
Save sawwd/2d2ad51eb4075d2335ed7573f0be2e53 to your computer and use it in GitHub Desktop.
WordPress Flow
INITIALISATION
==============
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())
REQUEST
=======
$wp->parse_request()
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.
THE MAIN QUERY
==============
$wp->query_posts()
goto ANY QUERY
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
ANY QUERY
=========
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)
WP_Query->get_posts()
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
TEMPLATE
========
DO_ACTION 'template_redirect'
if is_feed()
load the feed template
else
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment