<?php
define( 'WP_ADMIN', true );
// Most likely front-end scenario.
function is_admin() {
if ( isset( $GLOBALS['current_screen'] ) ) {
return $GLOBALS['current_screen']->in_admin();
} elseif ( defined( 'WP_ADMIN' ) ) {
return WP_ADMIN;
}
return false;
}
function wp_is_json_request() {
if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) {
return true;
}
if ( isset( $_SERVER['CONTENT_TYPE'] ) && wp_is_json_media_type( $_SERVER['CONTENT_TYPE'] ) ) {
return true;
}
return false;
}
function is_multisite() {
if ( defined( 'MULTISITE' ) ) {
return MULTISITE;
}
if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
return true;
}
return false;
}
function get_option( $what ) {
switch ( $what ) :
case 'WPLANG':
return 'en_US';
endswitch;
return false;
}
function get_locale() {
global $locale, $wp_local_package;
if ( isset( $locale ) ) {
/** This filter is documented in wp-includes/l10n.php */
return apply_filters( 'locale', $locale );
}
if ( isset( $wp_local_package ) ) {
$locale = $wp_local_package;
}
// WPLANG was defined in wp-config.
if ( defined( 'WPLANG' ) ) {
$locale = WPLANG;
}
// If multisite, check options.
if ( is_multisite() ) {
// Don't check blog option when installing.
if ( wp_installing() ) {
$ms_locale = get_site_option( 'WPLANG' );
} else {
$ms_locale = get_option( 'WPLANG' );
if ( false === $ms_locale ) {
$ms_locale = get_site_option( 'WPLANG' );
}
}
if ( false !== $ms_locale ) {
$locale = $ms_locale;
}
} else {
$db_locale = get_option( 'WPLANG' );
if ( false !== $db_locale ) {
$locale = $db_locale;
}
}
if ( empty( $locale ) ) {
$locale = 'en_US';
}
/**
* Filters the locale ID of the WordPress installation.
*
* @since 1.5.0
*
* @param string $locale The locale ID.
*/
return apply_filters( 'locale', $locale );
}
function get_user_locale( $user = 0 ) {
$user_object = false;
if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) {
$user_object = wp_get_current_user();
} elseif ( $user instanceof WP_User ) {
$user_object = $user;
} elseif ( $user && is_numeric( $user ) ) {
$user_object = get_user_by( 'id', $user );
}
if ( ! $user_object ) {
return get_locale();
}
$locale = $user_object->locale;
return $locale ? $locale : get_locale();
}
function apply_filters( $a, $b ) {
return $b;
}
function sanitize_locale_name( $a ) {
// Limit to A-Z, a-z, 0-9, '_', '-'.
$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $locale_name );
/**
* Filters a sanitized locale name string.
*
* @since 6.2.1
*
* @param string $sanitized The sanitized locale name.
* @param string $locale_name The locale name before sanitization.
*/
return apply_filters( 'sanitize_locale_name', $sanitized, $locale_name );
}
function determine_locale_actual() {
/**
* Filters the locale for the current request prior to the default determination process.
*
* Using this filter allows to override the default logic, effectively short-circuiting the function.
*
* @since 5.0.0
*
* @param string|null $locale The locale to return and short-circuit. Default null.
*/
$determined_locale = apply_filters( 'pre_determine_locale', null );
if ( $determined_locale && is_string( $determined_locale ) ) {
return $determined_locale;
}
if (
isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] &&
( ! empty( $_GET['wp_lang'] ) || ! empty( $_COOKIE['wp_lang'] ) )
) {
if ( ! empty( $_GET['wp_lang'] ) ) {
$determined_locale = sanitize_locale_name( $_GET['wp_lang'] );
} else {
$determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] );
}
} else if (
( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) || is_admin()
) {
$determined_locale = get_user_locale();
} else {
$determined_locale = get_locale();
}
/**
* Filters the locale for the current request.
*
* @since 5.0.0
*
* @param string $locale The locale.
*/
return apply_filters( 'determine_locale', $determined_locale );
}
function determine_locale_proposed() {
/**
* Filters the locale for the current request prior to the default determination process.
*
* Using this filter allows to override the default logic, effectively short-circuiting the function.
*
* @since 5.0.0
*
* @param string|null $locale The locale to return and short-circuit. Default null.
*/
$determined_locale = apply_filters( 'pre_determine_locale', null );
if ( $determined_locale && is_string( $determined_locale ) ) {
return $determined_locale;
}
if (
is_admin()
|| ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() )
) {
$determined_locale = get_user_locale();
} else {
$determined_locale = get_locale();
}
if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
if ( ! empty( $_GET['wp_lang'] ) ) {
$determined_locale = sanitize_locale_name( $_GET['wp_lang'] ) ?: $determined_locale;
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
$determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] ) ?: $determined_locale;
}
}
/**
* Filters the locale for the current request.
*
* @since 5.0.0
*
* @param string $locale The locale.
*/
return apply_filters( 'determine_locale', $determined_locale );
}
determine_locale_actual();
determine_locale_proposed();
$its = 1e5;
$t = hrtime(true);
for ( $i = 0; $i++ < $its; )
determine_locale_actual();
echo 'current: ', $old = ( hrtime(true)-$t ) / 1e9, "s\n";
$t = hrtime(true);
for ( $i = 0; $i++ < $its; )
determine_locale_proposed();
echo 'proposed: ', $new = ( hrtime(true)-$t ) / 1e9, "s\n\n";
printf( 'Proposed is %sx faster', number_format( $old / $new, 2 ) );
- Output for 8.4.2
- current: 0.015490014s
proposed: 0.013108617s
Proposed is 1.18x faster
- Output for 8.4.1
- current: 0.03866335s
proposed: 0.024536395s
Proposed is 1.58x faster
- Output for 8.3.14
- current: 0.039176825s
proposed: 0.030767797s
Proposed is 1.27x faster
- Output for 8.3.13
- current: 0.015675571s
proposed: 0.013260295s
Proposed is 1.18x faster
- Output for 8.3.12
- current: 0.018099901s
proposed: 0.013596279s
Proposed is 1.33x faster
- Output for 8.3.11
- current: 0.029103491s
proposed: 0.01296455s
Proposed is 2.24x faster
- Output for 8.3.10
- current: 0.016370655s
proposed: 0.013878295s
Proposed is 1.18x faster
- Output for 8.3.9
- current: 0.015076635s
proposed: 0.013122524s
Proposed is 1.15x faster
- Output for 8.3.8
- current: 0.019476806s
proposed: 0.017715917s
Proposed is 1.10x faster
- Output for 8.3.7
- current: 0.030023606s
proposed: 0.024292283s
Proposed is 1.24x faster
- Output for 8.3.6
- current: 0.029666971s
proposed: 0.025918321s
Proposed is 1.14x faster
- Output for 8.3.5
- current: 0.035749484s
proposed: 0.024052023s
Proposed is 1.49x faster
- Output for 8.3.4
- current: 0.029433591s
proposed: 0.02576321s
Proposed is 1.14x faster
- Output for 8.3.3
- current: 0.028479564s
proposed: 0.02474312s
Proposed is 1.15x faster
- Output for 8.3.2
- current: 0.015585414s
proposed: 0.013180969s
Proposed is 1.18x faster
- Output for 8.3.1
- current: 0.015266458s
proposed: 0.013337524s
Proposed is 1.14x faster
- Output for 8.3.0
- current: 0.027411304s
proposed: 0.013392039s
Proposed is 2.05x faster
- Output for 8.2.26
- current: 0.037614005s
proposed: 0.016699919s
Proposed is 2.25x faster
- Output for 8.2.25
- current: 0.015173389s
proposed: 0.012992726s
Proposed is 1.17x faster
- Output for 8.2.24
- current: 0.015379939s
proposed: 0.013220354s
Proposed is 1.16x faster
- Output for 8.2.23
- current: 0.039086873s
proposed: 0.01975432s
Proposed is 1.98x faster
- Output for 8.2.22
- current: 0.016155632s
proposed: 0.014409037s
Proposed is 1.12x faster
- Output for 8.2.21
- current: 0.01571256s
proposed: 0.013356068s
Proposed is 1.18x faster
- Output for 8.2.20
- current: 0.02271459s
proposed: 0.021351798s
Proposed is 1.06x faster
- Output for 8.2.19
- current: 0.033859147s
proposed: 0.026705148s
Proposed is 1.27x faster
- Output for 8.2.18
- current: 0.030952455s
proposed: 0.025656645s
Proposed is 1.21x faster
- Output for 8.2.17
- current: 0.029119617s
proposed: 0.0247856s
Proposed is 1.17x faster
- Output for 8.2.16
- current: 0.028242064s
proposed: 0.02462249s
Proposed is 1.15x faster
- Output for 8.2.15
- current: 0.015198965s
proposed: 0.013291014s
Proposed is 1.14x faster
- Output for 8.2.14
- current: 0.015175235s
proposed: 0.01357701s
Proposed is 1.12x faster
- Output for 8.2.13
- current: 0.036715764s
proposed: 0.016363378s
Proposed is 2.24x faster
- Output for 8.2.12
- current: 0.015346679s
proposed: 0.013383993s
Proposed is 1.15x faster
- Output for 8.2.11
- current: 0.027352762s
proposed: 0.022799585s
Proposed is 1.20x faster
- Output for 8.2.10
- current: 0.033127769s
proposed: 0.027929459s
Proposed is 1.19x faster
- Output for 8.2.9
- current: 0.0251528s
proposed: 0.022084669s
Proposed is 1.14x faster
- Output for 8.2.8
- current: 0.02875543s
proposed: 0.026941213s
Proposed is 1.07x faster
- Output for 8.2.7
- current: 0.02486957s
proposed: 0.022006465s
Proposed is 1.13x faster
- Output for 8.2.6
- current: 0.025276679s
proposed: 0.021660694s
Proposed is 1.17x faster
- Output for 8.2.5
- current: 0.025124091s
proposed: 0.02147299s
Proposed is 1.17x faster
- Output for 8.2.4
- current: 0.024800641s
proposed: 0.021046547s
Proposed is 1.18x faster
- Output for 8.2.3
- current: 0.025109582s
proposed: 0.021190449s
Proposed is 1.18x faster
- Output for 8.2.2
- current: 0.024669224s
proposed: 0.021819123s
Proposed is 1.13x faster
- Output for 8.2.1
- current: 0.024815439s
proposed: 0.022519823s
Proposed is 1.10x faster
- Output for 8.2.0
- current: 0.025554913s
proposed: 0.023920302s
Proposed is 1.07x faster
- Output for 8.1.31
- current: 0.038716582s
proposed: 0.022055482s
Proposed is 1.76x faster
- Output for 8.1.30
- current: 0.015506152s
proposed: 0.013493683s
Proposed is 1.15x faster
- Output for 8.1.29
- current: 0.023525318s
proposed: 0.031121463s
Proposed is 0.76x faster
- Output for 8.1.28
- current: 0.030085358s
proposed: 0.025871972s
Proposed is 1.16x faster
- Output for 8.1.27
- current: 0.031081255s
proposed: 0.013983904s
Proposed is 2.22x faster
- Output for 8.1.26
- current: 0.029187221s
proposed: 0.013890777s
Proposed is 2.10x faster
- Output for 8.1.25
- current: 0.015380594s
proposed: 0.013626111s
Proposed is 1.13x faster
- Output for 8.1.24
- current: 0.027447427s
proposed: 0.023081783s
Proposed is 1.19x faster
- Output for 8.1.23
- current: 0.027918431s
proposed: 0.021235457s
Proposed is 1.31x faster
- Output for 8.1.22
- current: 0.024990524s
proposed: 0.022828791s
Proposed is 1.09x faster
- Output for 8.1.21
- current: 0.023514428s
proposed: 0.019685467s
Proposed is 1.19x faster
- Output for 8.1.20
- current: 0.025526338s
proposed: 0.020067784s
Proposed is 1.27x faster
- Output for 8.1.19
- current: 0.023073347s
proposed: 0.0193602s
Proposed is 1.19x faster
- Output for 8.1.18
- current: 0.024987544s
proposed: 0.021838639s
Proposed is 1.14x faster
- Output for 8.1.17
- current: 0.024433438s
proposed: 0.021626881s
Proposed is 1.13x faster
- Output for 8.1.16
- current: 0.024812293s
proposed: 0.02214643s
Proposed is 1.12x faster
- Output for 8.1.15
- current: 0.025116516s
proposed: 0.021867846s
Proposed is 1.15x faster
- Output for 8.1.14
- current: 0.023899363s
proposed: 0.020975063s
Proposed is 1.14x faster
- Output for 8.1.13
- current: 0.024439601s
proposed: 0.020815742s
Proposed is 1.17x faster
- Output for 8.1.12
- current: 0.024166646s
proposed: 0.020427441s
Proposed is 1.18x faster
- Output for 8.1.11
- current: 0.024106854s
proposed: 0.020744118s
Proposed is 1.16x faster
- Output for 8.1.10
- current: 0.023015748s
proposed: 0.020032137s
Proposed is 1.15x faster
- Output for 8.1.9
- current: 0.023830914s
proposed: 0.021132209s
Proposed is 1.13x faster
- Output for 8.1.8
- current: 0.024138995s
proposed: 0.021606312s
Proposed is 1.12x faster
- Output for 8.1.7
- current: 0.024544649s
proposed: 0.021350801s
Proposed is 1.15x faster
- Output for 8.1.6
- current: 0.023549814s
proposed: 0.020195575s
Proposed is 1.17x faster
- Output for 8.1.5
- current: 0.0241793s
proposed: 0.021056466s
Proposed is 1.15x faster
- Output for 8.1.4
- current: 0.024646391s
proposed: 0.021578469s
Proposed is 1.14x faster
- Output for 8.1.3
- current: 0.023891007s
proposed: 0.020653667s
Proposed is 1.16x faster
- Output for 8.1.2
- current: 0.024371863s
proposed: 0.02210926s
Proposed is 1.10x faster
- Output for 8.1.1
- current: 0.024846377s
proposed: 0.021357944s
Proposed is 1.16x faster
- Output for 8.1.0
- current: 0.025210062s
proposed: 0.021964809s
Proposed is 1.15x faster
- Output for 8.0.30
- current: 0.024273778s
proposed: 0.021447083s
Proposed is 1.13x faster
- Output for 8.0.29
- current: 0.026134705s
proposed: 0.024694752s
Proposed is 1.06x faster
- Output for 8.0.28
- current: 0.025965546s
proposed: 0.024890701s
Proposed is 1.04x faster
- Output for 8.0.27
- current: 0.026269309s
proposed: 0.024891342s
Proposed is 1.06x faster
- Output for 8.0.26
- current: 0.026805248s
proposed: 0.025720995s
Proposed is 1.04x faster
- Output for 8.0.25
- current: 0.02682206s
proposed: 0.024571319s
Proposed is 1.09x faster
- Output for 8.0.24
- current: 0.025900814s
proposed: 0.02339887s
Proposed is 1.11x faster
- Output for 8.0.23
- current: 0.025286527s
proposed: 0.023260318s
Proposed is 1.09x faster
- Output for 8.0.22
- current: 0.025905262s
proposed: 0.024087949s
Proposed is 1.08x faster
- Output for 8.0.21
- current: 0.025431179s
proposed: 0.023590091s
Proposed is 1.08x faster
- Output for 8.0.20
- current: 0.026677687s
proposed: 0.025051264s
Proposed is 1.06x faster
- Output for 8.0.19
- current: 0.026808034s
proposed: 0.024484175s
Proposed is 1.09x faster
- Output for 8.0.18
- current: 0.026518158s
proposed: 0.026862266s
Proposed is 0.99x faster
- Output for 8.0.17
- current: 0.02542009s
proposed: 0.026243219s
Proposed is 0.97x faster
- Output for 8.0.16
- current: 0.02862107s
proposed: 0.025865538s
Proposed is 1.11x faster
- Output for 8.0.15
- current: 0.028712883s
proposed: 0.027003601s
Proposed is 1.06x faster
- Output for 8.0.14
- current: 0.026469415s
proposed: 0.02492205s
Proposed is 1.06x faster
- Output for 8.0.13
- current: 0.029988005s
proposed: 0.023432914s
Proposed is 1.28x faster
- Output for 8.0.12
- current: 0.026573091s
proposed: 0.023369094s
Proposed is 1.14x faster
- Output for 8.0.11
- current: 0.027303598s
proposed: 0.024897865s
Proposed is 1.10x faster
- Output for 8.0.10
- current: 0.032588425s
proposed: 0.027787079s
Proposed is 1.17x faster
- Output for 8.0.9
- current: 0.029024361s
proposed: 0.025575672s
Proposed is 1.13x faster
- Output for 8.0.8
- current: 0.026846566s
proposed: 0.025004837s
Proposed is 1.07x faster
- Output for 8.0.7
- current: 0.028128513s
proposed: 0.026431093s
Proposed is 1.06x faster
- Output for 8.0.6
- current: 0.027452177s
proposed: 0.024029358s
Proposed is 1.14x faster
- Output for 8.0.5
- current: 0.03081747s
proposed: 0.024774031s
Proposed is 1.24x faster
- Output for 8.0.3
- current: 0.034280894s
proposed: 0.027361086s
Proposed is 1.25x faster
- Output for 8.0.2
- current: 0.030836243s
proposed: 0.028692323s
Proposed is 1.07x faster
- Output for 8.0.1
- current: 0.028181061s
proposed: 0.025733188s
Proposed is 1.10x faster
preferences:
93.95 ms | 554 KiB | 5 Q