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
↓
...
ABSPATH
Path to the root folder of the WordPress installationSHORT_INIT
Short-circuit WP loading to run a minimal systemMULTISITE
Enable multisite networkIS_SUBDOMAIN_INSTALL
Whether multisite is a subdomain or subfolder networkWP_LANG_DIR
Path to translation filesDOING_AJAX
Current request is an AJAX requestIFRAME_REQUEST
Current request is an IFrame requestWP_INSTALLING
Part of the installation routine, skip plugins/themeFull reference in wp-core-bootstrap/documentation
on GitHub (WIP)
$blog_id
ID of currently active site in a network$pagenow
Currently active page$current_user
Currently active user$wpdb
Database abstraction in use$wp_object_cache
Cache abstraction in use$wp_query
Currently active database query$wp_filter
Hooks registered through the Plugin API$current_site
Currently active WP_Network
$current_blog
Currently active WP_Site
Full 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.php
Advanced caching pluginWP_CACHE=true
)db.php
Custom database classdb-error.php
Custom database error messageinstall.php
Custom install scriptmaintenance.php
Custom maintenance messageobject-cache.php
External object cachesunrise.php
Executed before Multisite is loadedSUNRISE=true
)blog-deleted.php
Custom site deleted messageblog-inactive.php
Custom site inactive messageblog-suspended.php
Custom site suspended messageWPINC/pluggable.php
wp_set_current_user
Change the current user by ID or namewp_get_current_user
Retrieve the current user objectget_userdata
Retrieve user info by user IDget_user_by
Retrieve user info by a given fieldcache_users
Retrieve info for user lists to prevent multiple queries by get_userdata()wp_mail
Send mail, similar to PHP's mailwp_authenticate
Authenticate a user, confirming the login credentials are validwp_logout
Log the current user outwp_validate_auth_cookie
Validates authentication cookiewp_generate_auth_cookie
Generate authentication cookie contentswp_parse_auth_cookie
Parse a cookie into its componentswp_set_auth_cookie
Log in a user by setting authentication cookieswp_clear_auth_cookie
Removes all of the cookies associated with authenticationis_user_logged_in
Checks if the current visitor is a logged in userauth_redirect
Checks if a user is logged in, if not it redirects them to the login pagecheck_admin_referer
Makes sure that a user was referred from another admin pagecheck_ajax_referer
Verifies the Ajax request to prevent processing requests external of the blogwp_redirect
Redirects to another pagewp_sanitize_redirect
Sanitizes a URL for use in a redirect_wp_sanitize_utf8_in_redirect
Performs a safe (local) redirect, using wp_redirect()wp_safe_redirect
Performs a safe (local) redirect, using wp_redirect()wp_validate_redirect
Validates a URL for use in a redirectwp_notify_postauthor
Notify an author (and/or others) of a comment/trackback/pingback on a postwp_notify_moderator
Notifies the moderatorabout a new comment that is awaiting approvalwp_password_change_notification
Notify the blog admin of a user changing password, normally via emailwp_new_user_notification
Email login credentials to a newly-registered userwp_nonce_tick
Get the time-dependent variable for nonce creationwp_verify_nonce
Verify that correct nonce was used with time limitwp_create_nonce
Creates a cryptographic token tied to a specific action, user, user session,
* and window of timewp_salt
Get salt to add to hasheswp_hash
Get hash of given stringwp_hash_password
Create a hash (encrypt) of a plain text passwordwp_check_password
Checks the plaintext password against the encrypted passwordwp_generate_password
Generates a random password drawn from the defined set of characterswp_rand
Generates a random numberwp_set_password
Updates the user's password with a new encrypted oneget_avatar
Retrieve the avatar <img> tag for a userwp_text_diff
Display 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