<?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'] );
}
} elseif (
is_admin() ||
( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() )
) {
$determined_locale = get_user_locale();
}
if ( ! $determined_locale ) {
$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.011380248s
proposed: 0.010215055s
Proposed is 1.11x faster
- Output for 8.4.1
- current: 0.011416567s
proposed: 0.010436567s
Proposed is 1.09x faster
- Output for 8.3.15
- current: 0.011153621s
proposed: 0.010384558s
Proposed is 1.07x faster
- Output for 8.3.14
- current: 0.027628256s
proposed: 0.018691284s
Proposed is 1.48x faster
- Output for 8.3.13
- current: 0.010838031s
proposed: 0.010241588s
Proposed is 1.06x faster
- Output for 8.3.12
- current: 0.01085881s
proposed: 0.010210572s
Proposed is 1.06x faster
- Output for 8.3.11
- current: 0.022402774s
proposed: 0.018908744s
Proposed is 1.18x faster
- Output for 8.3.10
- current: 0.010990289s
proposed: 0.010211956s
Proposed is 1.08x faster
- Output for 8.3.9
- current: 0.010838082s
proposed: 0.010146652s
Proposed is 1.07x faster
- Output for 8.3.8
- current: 0.014649576s
proposed: 0.01353642s
Proposed is 1.08x faster
- Output for 8.3.7
- current: 0.021952533s
proposed: 0.019794652s
Proposed is 1.11x faster
- Output for 8.3.6
- current: 0.025706502s
proposed: 0.019287868s
Proposed is 1.33x faster
- Output for 8.3.5
- current: 0.02550544s
proposed: 0.023777287s
Proposed is 1.07x faster
- Output for 8.3.4
- current: 0.031671405s
proposed: 0.025859435s
Proposed is 1.22x faster
- Output for 8.3.3
- current: 0.021047158s
proposed: 0.01948743s
Proposed is 1.08x faster
- Output for 8.3.2
- current: 0.011224185s
proposed: 0.011050543s
Proposed is 1.02x faster
- Output for 8.3.1
- current: 0.021107013s
proposed: 0.010763428s
Proposed is 1.96x faster
- Output for 8.3.0
- current: 0.026375693s
proposed: 0.011164524s
Proposed is 2.36x faster
- Output for 8.2.27
- current: 0.01102003s
proposed: 0.010074808s
Proposed is 1.09x faster
- Output for 8.2.26
- current: 0.021658673s
proposed: 0.014040852s
Proposed is 1.54x faster
- Output for 8.2.25
- current: 0.010854864s
proposed: 0.010375954s
Proposed is 1.05x faster
- Output for 8.2.24
- current: 0.025323785s
proposed: 0.025533031s
Proposed is 0.99x faster
- Output for 8.2.23
- current: 0.010795555s
proposed: 0.010130711s
Proposed is 1.07x faster
- Output for 8.2.22
- current: 0.01132503s
proposed: 0.010689648s
Proposed is 1.06x faster
- Output for 8.2.21
- current: 0.02145917s
proposed: 0.019439583s
Proposed is 1.10x faster
- Output for 8.2.20
- current: 0.01480448s
proposed: 0.013825205s
Proposed is 1.07x faster
- Output for 8.2.19
- current: 0.020480438s
proposed: 0.018707265s
Proposed is 1.09x faster
- Output for 8.2.18
- current: 0.025080512s
proposed: 0.019444526s
Proposed is 1.29x faster
- Output for 8.2.17
- current: 0.021531747s
proposed: 0.020131472s
Proposed is 1.07x faster
- Output for 8.2.16
- current: 0.021223529s
proposed: 0.019350951s
Proposed is 1.10x faster
- Output for 8.2.15
- current: 0.011259096s
proposed: 0.010552723s
Proposed is 1.07x faster
- Output for 8.2.14
- current: 0.023353718s
proposed: 0.01996727s
Proposed is 1.17x faster
- Output for 8.2.13
- current: 0.011177617s
proposed: 0.010690693s
Proposed is 1.05x faster
- Output for 8.2.12
- current: 0.014828829s
proposed: 0.015682575s
Proposed is 0.95x faster
- Output for 8.2.11
- current: 0.020216079s
proposed: 0.019006291s
Proposed is 1.06x faster
- Output for 8.2.10
- current: 0.020922105s
proposed: 0.016584563s
Proposed is 1.26x faster
- Output for 8.2.9
- current: 0.016688182s
proposed: 0.015679131s
Proposed is 1.06x faster
- Output for 8.2.8
- current: 0.019113053s
proposed: 0.015774843s
Proposed is 1.21x faster
- Output for 8.2.7
- current: 0.01704093s
proposed: 0.015622527s
Proposed is 1.09x faster
- Output for 8.2.6
- current: 0.017364199s
proposed: 0.016144721s
Proposed is 1.08x faster
- Output for 8.2.5
- current: 0.016860269s
proposed: 0.015945876s
Proposed is 1.06x faster
- Output for 8.2.4
- current: 0.016218671s
proposed: 0.015446875s
Proposed is 1.05x faster
- Output for 8.2.3
- current: 0.016362321s
proposed: 0.015573836s
Proposed is 1.05x faster
- Output for 8.2.2
- current: 0.016477008s
proposed: 0.015702087s
Proposed is 1.05x faster
- Output for 8.2.1
- current: 0.016683647s
proposed: 0.01616009s
Proposed is 1.03x faster
- Output for 8.2.0
- current: 0.016951892s
proposed: 0.015808938s
Proposed is 1.07x faster
- Output for 8.1.31
- current: 0.026646784s
proposed: 0.020091564s
Proposed is 1.33x faster
- Output for 8.1.30
- current: 0.022338313s
proposed: 0.016544034s
Proposed is 1.35x faster
- Output for 8.1.29
- current: 0.014607455s
proposed: 0.014432709s
Proposed is 1.01x faster
- Output for 8.1.28
- current: 0.031878992s
proposed: 0.030667757s
Proposed is 1.04x faster
- Output for 8.1.27
- current: 0.012195456s
proposed: 0.011483664s
Proposed is 1.06x faster
- Output for 8.1.26
- current: 0.011287297s
proposed: 0.011589331s
Proposed is 0.97x faster
- Output for 8.1.25
- current: 0.011531124s
proposed: 0.010961524s
Proposed is 1.05x faster
- Output for 8.1.24
- current: 0.020713813s
proposed: 0.019582812s
Proposed is 1.06x faster
- Output for 8.1.23
- current: 0.013859128s
proposed: 0.012779015s
Proposed is 1.08x faster
- Output for 8.1.22
- current: 0.015749252s
proposed: 0.015073549s
Proposed is 1.04x faster
- Output for 8.1.21
- current: 0.014628873s
proposed: 0.013509144s
Proposed is 1.08x faster
- Output for 8.1.20
- current: 0.015692549s
proposed: 0.014823102s
Proposed is 1.06x faster
- Output for 8.1.19
- current: 0.018473799s
proposed: 0.014432946s
Proposed is 1.28x faster
- Output for 8.1.18
- current: 0.016569192s
proposed: 0.015758393s
Proposed is 1.05x faster
- Output for 8.1.17
- current: 0.016587245s
proposed: 0.015452167s
Proposed is 1.07x faster
- Output for 8.1.16
- current: 0.017091576s
proposed: 0.016687122s
Proposed is 1.02x faster
- Output for 8.1.15
- current: 0.015460202s
proposed: 0.014399763s
Proposed is 1.07x faster
- Output for 8.1.14
- current: 0.015805702s
proposed: 0.014954689s
Proposed is 1.06x faster
- Output for 8.1.13
- current: 0.016065081s
proposed: 0.014996376s
Proposed is 1.07x faster
- Output for 8.1.12
- current: 0.015277196s
proposed: 0.01481208s
Proposed is 1.03x faster
- Output for 8.1.11
- current: 0.015738776s
proposed: 0.014953808s
Proposed is 1.05x faster
- Output for 8.1.10
- current: 0.015943291s
proposed: 0.015053665s
Proposed is 1.06x faster
- Output for 8.1.9
- current: 0.015388486s
proposed: 0.015320928s
Proposed is 1.00x faster
- Output for 8.1.8
- current: 0.015562846s
proposed: 0.014774961s
Proposed is 1.05x faster
- Output for 8.1.7
- current: 0.0155972s
proposed: 0.014793255s
Proposed is 1.05x faster
- Output for 8.1.6
- current: 0.015637346s
proposed: 0.014579732s
Proposed is 1.07x faster
- Output for 8.1.5
- current: 0.015764154s
proposed: 0.014857065s
Proposed is 1.06x faster
- Output for 8.1.4
- current: 0.015887026s
proposed: 0.014340581s
Proposed is 1.11x faster
- Output for 8.1.3
- current: 0.015431658s
proposed: 0.014539385s
Proposed is 1.06x faster
- Output for 8.1.2
- current: 0.01630866s
proposed: 0.015617218s
Proposed is 1.04x faster
- Output for 8.1.1
- current: 0.016018053s
proposed: 0.015117887s
Proposed is 1.06x faster
- Output for 8.1.0
- current: 0.015809249s
proposed: 0.01571954s
Proposed is 1.01x faster
- Output for 8.0.30
- current: 0.01655803s
proposed: 0.015175334s
Proposed is 1.09x faster
- Output for 8.0.29
- current: 0.017517388s
proposed: 0.017393915s
Proposed is 1.01x faster
- Output for 8.0.28
- current: 0.018525567s
proposed: 0.01828883s
Proposed is 1.01x faster
- Output for 8.0.27
- current: 0.017658453s
proposed: 0.017747852s
Proposed is 0.99x faster
- Output for 8.0.26
- current: 0.018624754s
proposed: 0.018164778s
Proposed is 1.03x faster
- Output for 8.0.25
- current: 0.01776762s
proposed: 0.017882626s
Proposed is 0.99x faster
- Output for 8.0.24
- current: 0.017692217s
proposed: 0.018337564s
Proposed is 0.96x faster
- Output for 8.0.23
- current: 0.018400762s
proposed: 0.018222577s
Proposed is 1.01x faster
- Output for 8.0.22
- current: 0.018329297s
proposed: 0.017844924s
Proposed is 1.03x faster
- Output for 8.0.21
- current: 0.017984278s
proposed: 0.01750823s
Proposed is 1.03x faster
- Output for 8.0.20
- current: 0.018960347s
proposed: 0.018091188s
Proposed is 1.05x faster
- Output for 8.0.19
- current: 0.018759458s
proposed: 0.018283912s
Proposed is 1.03x faster
- Output for 8.0.18
- current: 0.019211359s
proposed: 0.019053292s
Proposed is 1.01x faster
- Output for 8.0.17
- current: 0.018265867s
proposed: 0.018715065s
Proposed is 0.98x faster
- Output for 8.0.16
- current: 0.018221665s
proposed: 0.017731591s
Proposed is 1.03x faster
- Output for 8.0.15
- current: 0.018683345s
proposed: 0.018084677s
Proposed is 1.03x faster
- Output for 8.0.14
- current: 0.017291873s
proposed: 0.016975968s
Proposed is 1.02x faster
- Output for 8.0.13
- current: 0.018569661s
proposed: 0.017286212s
Proposed is 1.07x faster
- Output for 8.0.12
- current: 0.017742532s
proposed: 0.016588708s
Proposed is 1.07x faster
- Output for 8.0.11
- current: 0.018554081s
proposed: 0.017224936s
Proposed is 1.08x faster
- Output for 8.0.10
- current: 0.018649701s
proposed: 0.017531073s
Proposed is 1.06x faster
- Output for 8.0.9
- current: 0.017996852s
proposed: 0.017420966s
Proposed is 1.03x faster
- Output for 8.0.8
- current: 0.017915909s
proposed: 0.017277035s
Proposed is 1.04x faster
- Output for 8.0.7
- current: 0.018170929s
proposed: 0.018985344s
Proposed is 0.96x faster
- Output for 8.0.6
- current: 0.017538307s
proposed: 0.017405306s
Proposed is 1.01x faster
- Output for 8.0.5
- current: 0.018177452s
proposed: 0.017368747s
Proposed is 1.05x faster
- Output for 8.0.3
- current: 0.017876053s
proposed: 0.01707291s
Proposed is 1.05x faster
- Output for 8.0.2
- current: 0.018634432s
proposed: 0.017662071s
Proposed is 1.06x faster
- Output for 8.0.1
- current: 0.017471221s
proposed: 0.016788624s
Proposed is 1.04x faster
preferences:
80.43 ms | 557 KiB | 5 Q