Code to prepare the environment
Not part of the actual logic that solves a problem
Often used to abstract away differences between platforms
Entry point
index.php
↓
Load WordPress environment and template
wp-blog-header.php
↓
Load the WordPress library
wp-load.php
↓
Set up the WordPress query
wp()
↓
Load the theme template
WPINC/template-loader.php
Entry point
wp-admin/index.php
↓
Load WordPress environment and template
wp-admin/admin.php
↓
Load the WordPress library
wp-load.php
↓
Set up the WordPress query
wp_dashboard()
Load configuration
↓
Set up the environment
↓
Load Plugin API
↓
Set up database
↓
Set up cache
↓
Load multisite
↓
Load localization
↓
[Run 5-minute-installation if needed]
↓
Load rest of WordPress
↓
...
wp-config.php
↓
wp-settings.php
↓
plugin.php
↓
wp-db.php [ && db.php ]
↓
cache.php [ || object-cache.php ]
↓
ms-blogs.php & ms-settings.php
↓
l10n.php & class-wp-locale.php
↓
wp_not_installed()
↓
Long list of require calls
↓
...
ABSPATHPath to the root folder of the WordPress installationSHORT_INITShort-circuit WP loading to run a minimal systemMULTISITEEnable multisite networkIS_SUBDOMAIN_INSTALLWhether multisite is a subdomain or subfolder networkWP_LANG_DIRPath to translation filesDOING_AJAXCurrent request is an AJAX requestIFRAME_REQUESTCurrent request is an IFrame requestWP_INSTALLINGPart of the installation routine, skip plugins/themeFull reference in wp-core-bootstrap/documentation on GitHub (WIP)
$blog_idID of currently active site in a network$pagenowCurrently active page$current_userCurrently active user$wpdbDatabase abstraction in use$wp_object_cacheCache abstraction in use$wp_queryCurrently active database query$wp_filterHooks registered through the Plugin API$current_siteCurrently active WP_Network$current_blogCurrently active WP_SiteFull reference in wp-core-bootstrap/documentation on GitHub (WIP)
Class declaration for WP_Hook is loaded early in wp-settings.php
Fetches existing hooks from global $wp_filter, in case drop-ins have added filter manually before the Plugin API was ready
Some hooks run before plugins, so can only be used by non-web runtimes:
enable_loading_advanced_cache_dropin
enable_maintenance_mode
enable_wp_debug_mode_checks
Huge list of hooks * preloaded through WPINC/default-filters.php
* (447 @ v4.8)
WP_CONTENT_DIR ("drop-ins")advanced-cache.phpAdvanced caching pluginWP_CACHE=true)db.phpCustom database classdb-error.phpCustom database error messageinstall.phpCustom install scriptmaintenance.phpCustom maintenance messageobject-cache.phpExternal object cachesunrise.phpExecuted before Multisite is loadedSUNRISE=true)blog-deleted.phpCustom site deleted messageblog-inactive.phpCustom site inactive messageblog-suspended.phpCustom site suspended messageWPINC/pluggable.php wp_set_current_userChange the current user by ID or namewp_get_current_userRetrieve the current user objectget_userdataRetrieve user info by user IDget_user_byRetrieve user info by a given fieldcache_usersRetrieve info for user lists to prevent multiple queries by get_userdata()wp_mailSend mail, similar to PHP's mailwp_authenticateAuthenticate a user, confirming the login credentials are validwp_logoutLog the current user outwp_validate_auth_cookieValidates authentication cookiewp_generate_auth_cookieGenerate authentication cookie contentswp_parse_auth_cookieParse a cookie into its componentswp_set_auth_cookieLog in a user by setting authentication cookieswp_clear_auth_cookieRemoves all of the cookies associated with authenticationis_user_logged_inChecks if the current visitor is a logged in userauth_redirectChecks if a user is logged in, if not it redirects them to the login pagecheck_admin_refererMakes sure that a user was referred from another admin pagecheck_ajax_refererVerifies the Ajax request to prevent processing requests external of the blogwp_redirectRedirects to another pagewp_sanitize_redirectSanitizes a URL for use in a redirect_wp_sanitize_utf8_in_redirectPerforms a safe (local) redirect, using wp_redirect()wp_safe_redirectPerforms a safe (local) redirect, using wp_redirect()wp_validate_redirectValidates a URL for use in a redirectwp_notify_postauthorNotify an author (and/or others) of a comment/trackback/pingback on a postwp_notify_moderatorNotifies the moderatorabout a new comment that is awaiting approvalwp_password_change_notificationNotify the blog admin of a user changing password, normally via emailwp_new_user_notificationEmail login credentials to a newly-registered userwp_nonce_tickGet the time-dependent variable for nonce creationwp_verify_nonceVerify that correct nonce was used with time limitwp_create_nonceCreates a cryptographic token tied to a specific action, user, user session,
* and window of timewp_saltGet salt to add to hasheswp_hashGet hash of given stringwp_hash_passwordCreate a hash (encrypt) of a plain text passwordwp_check_passwordChecks the plaintext password against the encrypted passwordwp_generate_passwordGenerates a random password drawn from the defined set of characterswp_randGenerates a random numberwp_set_passwordUpdates the user's password with a new encrypted oneget_avatarRetrieve the avatar <img> tag for a userwp_text_diffDisplay a human readable difference between two stringsDirect dependence on MySQL *
Abstracted through wpdb (leaky)
Pluggable through WP_CONTENT_DIR/db.php
* this includes MariaDB, a MySQL fork
Provide WP_CONTENT_DIR/db.php that sets the global $wpdb to a custom instance
Skips compatbility checks unless $wpdb->is_mysql returns true
Class wpdb is already loaded, so custom implementation can extend if needed
File WP_CONTENT_DIR/db.php:
global $wpdb;
class AwesomeDB extends wpdb {
const ANSWER = 42;
function db_version() { return 'AwesomeDB 1.0'; }
function db_connect() { return true; }
function query( $query ) { return static::ANSWER; }
}
$wpdb = new AwesomeDB();
Abstracted through wp_cache_* functions
Used transparently for most queries
Pluggable through WP_CONTENT_DIR/object-cache.php
and WP_CONTENT_DIR/advanced-cache.php
Provide WP_CONTENT_DIR/object-cache.php that sets the global $wp_object_cache to a custom instance and provides wp_cache_* functions
Provide WP_CONTENT_DIR/advanced-cache.php if you need to proactively fiddle with the loading process
Loading of the WP_CONTENT_DIR/advanced-cache.php file can be controlled through the 'enable_loading_advanced_cache_dropin' filter
File WP_CONTENT_DIR/object-cache.php:
// Override Cache API functions.
function wp_cache_get( ...$args ) {
$wp_object_cache->get( ...$args );
}
function wp_cache_set( ...$args ) {
$wp_object_cache->set( ...$args );
}
function wp_cache_delete( ...$args ) {
$wp_object_cache->delete( ...$args );
}
function wp_cache_flush() {
$wp_object_cache->flush();
}
...
function wp_cache_init() {
$wp_object_cache = new AwesomeCache();
}
File WP_CONTENT_DIR/my-plugin/src/AwesomeCache.php:
// Provide actual implementation class.
// This can't extend WP_Object_Cache, as it won't
// have been declared.
class AwesomeCache {
// This is where we hold the awesomeness.
private $cache;
public function __construct() {
// Initialize awesomeness here.
}
public function get( ...$args ) {...}
public function set( ...$args ) {...}
public function delete( ...$args ) {...}
public function flush() {...}
...
}
Set WP_LANG_DIR to either WP_CONTENT_DIR/languages or WPINC/languages
↓
Load MO class for reading GetText translation files
↓
Load 'default' translated strings based on locale
↓
Set up $wp_locale global
↓
Initialize $wp_locale_switcher
Stored in global array $l10n with the key being the text domain
If a text domain was not found, it is loaded on demand (looking in WP_LANG_DIR first)
If a text domain could not be loaded, an instance of NOOP_Translations is returned
Declare functions to work with multisite tables and data
WPINC/ms-blogs.php
↓
Set up multisite environment
WPINC/ms-settings.php
↓
Declare functions to load multisite into memory
WPINC/ms-load.php
↓
Load default multisite constants
WPINC/ms-default-constants.php
↓
Load sunrise drop-in if it exists and SUNRISE has been defined
WP_CONTENT_DIR/sunrise.php
↓
If either $current_site or $current_blog are not set yet...
↓
Extract domain from $_SERVER['HTTP_HOST']
↓
Extract path from $_SERVER['REQUEST_URI']
↓
If DOMAIN_CURRENT_SITE and PATH_CURRENT_SITE are defined, use these
↓
If we're dealing with a subfolder install, identify network first, then query network for site path
↓
If we're dealing with a subdomain install, identify site by exact domain and at most first segment of path
↓
In case of failure, trigger actions ms_network_not_found or ms_site_not_found
Loaded if the constant SUNRISE is set and the file WP_CONTENT_DIR/sunrise.php exists
Allows control over multisite setup mechanism
Deactivates the entirety of the detection on the previous slide if it sets $current_site and $current_blog
Entry point for domain mapping
File wp-config.php:
// This is your customized wp-config.php file
// that contains your install configuration.
// [ ... ]
// Activate sunrise mechanism.
define( 'SUNRISE', true );
// [ ... ]
File WP_CONTENT_DIR/sunrise.php:
// This file is responsible for detecting what
// network and site to use for a given request.
global $current_site, $current_blog;
// This is actually the current WP_Network.
$current_site = WP_Network::get_instance(
custom_logic_to_detect_network_id()
);
// This is the current WP_Site.
$current_blog = WP_Site::get_instance(
custom_logic_to_detect_site_id()
);
WordPress 4.8 Front-end request, no plugins, twentyseventeen theme
Blackfire profile
Goal 1 — Documentation
- Detailed docs for old and new code
- Include characterization tests to detect breaking changes
Goal 2 — Modernized Flow
- Subsystems should be cleanly swappable/extensible
Goal 3 — Contextual Optimization
- Only load what is effectively needed to produce the desired output
Goal 4 — Unified Structure
- Reduce idiosyncrasies to provide a consistent user/dev experience
Goal 5 — Compatibility
- Don't break existing sites
- Grow with future requirements
Phase 1 — Discovery
- Be clear about the status quo
- Identify issues
Phase 2 — Design
- Plan a coherent architecture that meets all requirements
- Get rid of idiosyncrasies
Phase 3 — Execution
- Build with backward compatibility as requirement
- Build with future compatibility as target
Phase 4 — Merge Proposal
- Ship it!
1. Join make.wordpress.org Slack team:
https://make.wordpress.org/chat/
2. Join the #core-bootstrap channel
I'm Alain Schlesser.
Follow me on Twitter:
@schlesseraOr visit my Personal Blog:
www.alainschlesser.com