wp_load_translations_early()
- Since
- 3.4.0
- Source
wp-includes/load.php:1524
Description
Used for errors encountered during the initial loading process, before the locale has been properly detected and loaded.
Designed for unusual load sequences (like setup-config.php) or for when the script will then terminate with an error, otherwise there is a risk that a file can be double-included.
Compatibility
- WordPress
- since 3.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to wp_load_translations_early() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 5–195
- Plugin surface
- None
- Called by
- 16
Reads or writes the filesystem via is_dir().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 199.
Nothing here hands control to plugin code.
16 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- filesystemfilesystem access
is_dir()called directly - hookthird-party callbacks
apply_filters()one call below wp_load_translations_early()
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 33 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_load_translations_early() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5 | none |
function_exists() | 14–97 | function_exists(), did_action() |
!function_exists() | 82–93 | function_exists() |
!function_exists() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') | 105–126 | function_exists(), is_dir(), is_dir() |
function_exists() && !did_action() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') | 109–130 | function_exists(), did_action(), is_dir(), is_dir() |
!function_exists() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') | 111–133 | function_exists(), is_dir(), is_dir(), array_unique() |
!function_exists() | 112–138 | function_exists(), is_dir(), is_dir(), is_dir() |
function_exists() && !did_action() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') | 115–137 | function_exists(), did_action(), is_dir(), is_dir(), array_unique() |
function_exists() && !did_action() | 116–142 | function_exists(), did_action(), is_dir(), is_dir(), is_dir() |
!function_exists() | 118–145 | function_exists(), is_dir(), is_dir(), is_dir(), array_unique() |
!function_exists() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') | 120–148 | function_exists(), is_dir(), is_dir(), is_dir(), is_dir() |
function_exists() && !did_action() | 122–149 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), array_unique() |
21 further outcomes, up to 195 instructions
function_exists() && !did_action() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') | 124–152 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), is_dir() |
!function_exists() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') | 126–155 | function_exists(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique() |
function_exists() && !did_action() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') | 130–159 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique() |
!function_exists() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && !defined('WP_SETUP_CONFIG') | 133–154 | function_exists(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain() |
function_exists() && !did_action() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && !defined('WP_SETUP_CONFIG') | 137–158 | function_exists(), did_action(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain() |
!function_exists() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') && !$locales && !$locations && defined('WP_SETUP_CONFIG') | 140–161 | function_exists(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists() |
!function_exists() && !$locales && !$locations && file_exists() && !defined('WP_SETUP_CONFIG') | 140–166 | function_exists(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain() |
function_exists() && !did_action() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') && !$locales && !$locations && defined('WP_SETUP_CONFIG') | 144–165 | function_exists(), did_action(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists() |
function_exists() && !did_action() && !$locales && !$locations && file_exists() && !defined('WP_SETUP_CONFIG') | 144–170 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain() |
!function_exists() && !$locales && !$locations && defined('WP_SETUP_CONFIG') | 147–173 | function_exists(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists() |
!function_exists() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && defined('WP_SETUP_CONFIG') | 148–169 | function_exists(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists(), load_textdomain() |
!function_exists() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && !defined('WP_SETUP_CONFIG') | 148–176 | function_exists(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain() |
function_exists() && !did_action() && !$locales && !$locations && defined('WP_SETUP_CONFIG') | 151–177 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists() |
function_exists() && !did_action() && !defined('WP_LANG_DIR') && !defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && defined('WP_SETUP_CONFIG') | 152–173 | function_exists(), did_action(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists(), load_textdomain() |
function_exists() && !did_action() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && !defined('WP_SETUP_CONFIG') | 152–180 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain() |
!function_exists() && !$locales && !$locations && file_exists() && defined('WP_SETUP_CONFIG') | 155–181 | function_exists(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists(), load_textdomain() |
!function_exists() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') && !$locales && !$locations && defined('WP_SETUP_CONFIG') | 155–183 | function_exists(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists() |
function_exists() && !did_action() && !$locales && !$locations && file_exists() && defined('WP_SETUP_CONFIG') | 159–185 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists(), load_textdomain() |
function_exists() && !did_action() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') && !$locales && !$locations && defined('WP_SETUP_CONFIG') | 159–187 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists() |
!function_exists() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && defined('WP_SETUP_CONFIG') | 163–191 | function_exists(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists(), load_textdomain() |
function_exists() && !did_action() && defined('WP_LANG_DIR') && defined('WP_CONTENT_DIR') && !$locales && !$locations && file_exists() && defined('WP_SETUP_CONFIG') | 167–195 | function_exists(), did_action(), is_dir(), is_dir(), is_dir(), is_dir(), array_unique(), file_exists(), load_textdomain(), file_exists(), load_textdomain() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 199 instructions, 5–195 executed per call, 22 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 4
- did_action()Retrieves the number of times an action has been fired during the current request.
- load_textdomain()Loads a .mo file into the text domain $domain.
- WP_Textdomain_Registry::__construct()
- WP_Locale::__construct()Constructor which calls helper methods to set up object variables.
Used by · 16
- WP_Fatal_Error_Handler::display_default_error_template()Displays the default PHP error template.
- WP_Object_Cache::is_valid_key()Serves as a utility function to determine whether a key is valid.
- dead_db()Loads custom DB error or display WordPress DB error.
- is_blog_installed()Determines whether WordPress is already installed.
- ms_not_installed()Displays a failure message.
- wp_check_php_mysql_versions()Checks the server requirements.
- wp_maintenance()Dies with a maintenance message when conditions are met.
- wp_set_wpdb_vars()Sets the database table prefix and the format specifiers for database table columns.
- wpdb::_real_escape()Real escape using mysqli_real_escape_string().
- wpdb::check_connection()Checks that the connection to the database is still up. If not, try to reconnect.
- wpdb::db_connect()Connects to and selects database.
- wpdb::prepare()Prepares a SQL query for safe execution.
Show all 16
- wpdb::print_error()Prints SQL/DB error.
- wpdb::process_fields()Processes arrays of field/value pairs and field formats.
- wpdb::query()Performs a database query, using current database connection.
- wpdb::select()Selects a database using the current or provided database connection.
Source code
function wp_load_translations_early() { global $wp_textdomain_registry, $wp_locale; static $loaded = false; if ( $loaded ) { return; } $loaded = true; if ( function_exists( 'did_action' ) && did_action( 'init' ) ) { return; } // We need $wp_local_package. require ABSPATH . WPINC . '/version.php'; // Translation and localization. require_once ABSPATH . WPINC . '/pomo/mo.php'; require_once ABSPATH . WPINC . '/l10n/class-wp-translation-controller.php'; require_once ABSPATH . WPINC . '/l10n/class-wp-translations.php'; require_once ABSPATH . WPINC . '/l10n/class-wp-translation-file.php'; require_once ABSPATH . WPINC . '/l10n/class-wp-translation-file-mo.php'; require_once ABSPATH . WPINC . '/l10n/class-wp-translation-file-php.php'; require_once ABSPATH . WPINC . '/l10n.php'; require_once ABSPATH . WPINC . '/class-wp-textdomain-registry.php'; require_once ABSPATH . WPINC . '/class-wp-locale.php'; require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; // General libraries. require_once ABSPATH . WPINC . '/plugin.php'; $locales = array(); $locations = array(); if ( ! $wp_textdomain_registry instanceof WP_Textdomain_Registry ) { $wp_textdomain_registry = new WP_Textdomain_Registry(); } while ( true ) { if ( defined( 'WPLANG' ) ) { if ( '' === WPLANG ) { break; } $locales[] = WPLANG; } if ( isset( $wp_local_package ) ) { $locales[] = $wp_local_package; } if ( ! $locales ) { break; } if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) { $locations[] = WP_LANG_DIR; } if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) { $locations[] = WP_CONTENT_DIR . '/languages'; } if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) { $locations[] = ABSPATH . 'wp-content/languages'; } if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) { $locations[] = ABSPATH . WPINC . '/languages'; } if ( ! $locations ) { break; } $locations = array_unique( $locations ); foreach ( $locales as $locale ) { foreach ( $locations as $location ) { if ( file_exists( $location . '/' . $locale . '.mo' ) ) {Changelog
Introduced in 3.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/load.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.