<?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.3.11
- current: 0.013400761s
proposed: 0.012522298s
Proposed is 1.07x faster
- Output for 8.3.10
- current: 0.013911074s
proposed: 0.013360092s
Proposed is 1.04x faster
- Output for 8.3.9
- current: 0.027979969s
proposed: 0.014211178s
Proposed is 1.97x faster
- Output for 8.3.8
- current: 0.021942147s
proposed: 0.018305825s
Proposed is 1.20x faster
- Output for 8.3.7
- current: 0.039334143s
proposed: 0.027523937s
Proposed is 1.43x faster
- Output for 8.3.6
- current: 0.030772777s
proposed: 0.027272463s
Proposed is 1.13x faster
- Output for 8.3.5
- current: 0.029809981s
proposed: 0.023779627s
Proposed is 1.25x faster
- Output for 8.3.4
- current: 0.027215945s
proposed: 0.025387015s
Proposed is 1.07x faster
- Output for 8.3.3
- current: 0.026900708s
proposed: 0.025037624s
Proposed is 1.07x faster
- Output for 8.3.2
- current: 0.030451458s
proposed: 0.02362552s
Proposed is 1.29x faster
- Output for 8.3.1
- current: 0.028977032s
proposed: 0.013216852s
Proposed is 2.19x faster
- Output for 8.3.0
- current: 0.032636037s
proposed: 0.013284958s
Proposed is 2.46x faster
- Output for 8.2.23
- current: 0.014327901s
proposed: 0.013719995s
Proposed is 1.04x faster
- Output for 8.2.22
- current: 0.014452431s
proposed: 0.012970777s
Proposed is 1.11x faster
- Output for 8.2.21
- current: 0.014890951s
proposed: 0.01339584s
Proposed is 1.11x faster
- Output for 8.2.20
- current: 0.018915011s
proposed: 0.016800099s
Proposed is 1.13x faster
- Output for 8.2.19
- current: 0.032427434s
proposed: 0.025333863s
Proposed is 1.28x faster
- Output for 8.2.18
- current: 0.033996814s
proposed: 0.028263454s
Proposed is 1.20x faster
- Output for 8.2.17
- current: 0.028829571s
proposed: 0.026419087s
Proposed is 1.09x faster
- Output for 8.2.16
- current: 0.026793634s
proposed: 0.024647738s
Proposed is 1.09x faster
- Output for 8.2.15
- current: 0.014422456s
proposed: 0.013513718s
Proposed is 1.07x faster
- Output for 8.2.14
- current: 0.015832646s
proposed: 0.013785753s
Proposed is 1.15x faster
- Output for 8.2.13
- current: 0.015152322s
proposed: 0.013445824s
Proposed is 1.13x faster
- Output for 8.2.12
- current: 0.015521242s
proposed: 0.013410473s
Proposed is 1.16x faster
- Output for 8.2.11
- current: 0.024039961s
proposed: 0.022654377s
Proposed is 1.06x faster
- Output for 8.2.10
- current: 0.027587785s
proposed: 0.024949152s
Proposed is 1.11x faster
- Output for 8.2.9
- current: 0.02493492s
proposed: 0.025064304s
Proposed is 0.99x faster
- Output for 8.2.8
- current: 0.022728885s
proposed: 0.021543141s
Proposed is 1.06x faster
- Output for 8.2.7
- current: 0.024229065s
proposed: 0.022167389s
Proposed is 1.09x faster
- Output for 8.2.6
- current: 0.024623166s
proposed: 0.026250794s
Proposed is 0.94x faster
- Output for 8.2.5
- current: 0.023252233s
proposed: 0.022094982s
Proposed is 1.05x faster
- Output for 8.2.4
- current: 0.022629451s
proposed: 0.0237175s
Proposed is 0.95x faster
- Output for 8.2.3
- current: 0.023972031s
proposed: 0.022811353s
Proposed is 1.05x faster
- Output for 8.2.2
- current: 0.022989217s
proposed: 0.021301127s
Proposed is 1.08x faster
- Output for 8.2.1
- current: 0.022703119s
proposed: 0.021652659s
Proposed is 1.05x faster
- Output for 8.2.0
- current: 0.022811092s
proposed: 0.021917278s
Proposed is 1.04x faster
- Output for 8.1.29
- current: 0.018938248s
proposed: 0.017647631s
Proposed is 1.07x faster
- Output for 8.1.28
- current: 0.027410508s
proposed: 0.025250135s
Proposed is 1.09x faster
- Output for 8.1.27
- current: 0.018979721s
proposed: 0.020000679s
Proposed is 0.95x faster
- Output for 8.1.26
- current: 0.015460651s
proposed: 0.013976647s
Proposed is 1.11x faster
- Output for 8.1.25
- current: 0.031077243s
proposed: 0.013545999s
Proposed is 2.29x faster
- Output for 8.1.24
- current: 0.02421742s
proposed: 0.023067561s
Proposed is 1.05x faster
- Output for 8.1.23
- current: 0.018423715s
proposed: 0.017311053s
Proposed is 1.06x faster
- Output for 8.1.22
- current: 0.021829737s
proposed: 0.021543109s
Proposed is 1.01x faster
- Output for 8.1.21
- current: 0.020996596s
proposed: 0.019732846s
Proposed is 1.06x faster
- Output for 8.1.20
- current: 0.02105855s
proposed: 0.019853059s
Proposed is 1.06x faster
- Output for 8.1.19
- current: 0.021062117s
proposed: 0.01918995s
Proposed is 1.10x faster
- Output for 8.1.18
- current: 0.022806765s
proposed: 0.022175133s
Proposed is 1.03x faster
- Output for 8.1.17
- current: 0.022440454s
proposed: 0.021838751s
Proposed is 1.03x faster
- Output for 8.1.16
- current: 0.022203186s
proposed: 0.02187602s
Proposed is 1.01x faster
- Output for 8.1.15
- current: 0.022727786s
proposed: 0.021595181s
Proposed is 1.05x faster
- Output for 8.1.14
- current: 0.021569202s
proposed: 0.021072647s
Proposed is 1.02x faster
- Output for 8.1.13
- current: 0.021539124s
proposed: 0.020855408s
Proposed is 1.03x faster
- Output for 8.1.12
- current: 0.021274367s
proposed: 0.020759076s
Proposed is 1.02x faster
- Output for 8.1.11
- current: 0.021781262s
proposed: 0.020913757s
Proposed is 1.04x faster
- Output for 8.1.10
- current: 0.020933434s
proposed: 0.019670565s
Proposed is 1.06x faster
- Output for 8.1.9
- current: 0.021834632s
proposed: 0.021259649s
Proposed is 1.03x faster
- Output for 8.1.8
- current: 0.02146712s
proposed: 0.021991237s
Proposed is 0.98x faster
- Output for 8.1.7
- current: 0.022509814s
proposed: 0.021305356s
Proposed is 1.06x faster
- Output for 8.1.6
- current: 0.021848428s
proposed: 0.02149955s
Proposed is 1.02x faster
- Output for 8.1.5
- current: 0.021734344s
proposed: 0.020916232s
Proposed is 1.04x faster
- Output for 8.1.4
- current: 0.022377215s
proposed: 0.022428561s
Proposed is 1.00x faster
- Output for 8.1.3
- current: 0.021445309s
proposed: 0.020192378s
Proposed is 1.06x faster
- Output for 8.1.2
- current: 0.021732941s
proposed: 0.020908116s
Proposed is 1.04x faster
- Output for 8.1.1
- current: 0.022472605s
proposed: 0.021378593s
Proposed is 1.05x faster
- Output for 8.1.0
- current: 0.022292325s
proposed: 0.020774555s
Proposed is 1.07x faster
- Output for 8.0.30
- current: 0.021878514s
proposed: 0.021434218s
Proposed is 1.02x faster
- Output for 8.0.29
- current: 0.025151372s
proposed: 0.024710403s
Proposed is 1.02x faster
- Output for 8.0.28
- current: 0.025592183s
proposed: 0.025385673s
Proposed is 1.01x faster
- Output for 8.0.27
- current: 0.025088254s
proposed: 0.02494312s
Proposed is 1.01x faster
- Output for 8.0.26
- current: 0.025886598s
proposed: 0.025820112s
Proposed is 1.00x faster
- Output for 8.0.25
- current: 0.025991536s
proposed: 0.024682289s
Proposed is 1.05x faster
- Output for 8.0.24
- current: 0.023415161s
proposed: 0.023632379s
Proposed is 0.99x faster
- Output for 8.0.23
- current: 0.024393876s
proposed: 0.023442131s
Proposed is 1.04x faster
- Output for 8.0.22
- current: 0.024819728s
proposed: 0.024017606s
Proposed is 1.03x faster
- Output for 8.0.21
- current: 0.024702445s
proposed: 0.023495292s
Proposed is 1.05x faster
- Output for 8.0.20
- current: 0.025498335s
proposed: 0.024212123s
Proposed is 1.05x faster
- Output for 8.0.19
- current: 0.025071861s
proposed: 0.024320517s
Proposed is 1.03x faster
- Output for 8.0.18
- current: 0.026633655s
proposed: 0.025818159s
Proposed is 1.03x faster
- Output for 8.0.17
- current: 0.024663311s
proposed: 0.024395599s
Proposed is 1.01x faster
- Output for 8.0.16
- current: 0.026173087s
proposed: 0.024306731s
Proposed is 1.08x faster
- Output for 8.0.15
- current: 0.025041696s
proposed: 0.024479717s
Proposed is 1.02x faster
- Output for 8.0.14
- current: 0.024348919s
proposed: 0.023497575s
Proposed is 1.04x faster
- Output for 8.0.13
- current: 0.025024513s
proposed: 0.02318601s
Proposed is 1.08x faster
- Output for 8.0.12
- current: 0.023969596s
proposed: 0.023786039s
Proposed is 1.01x faster
- Output for 8.0.11
- current: 0.023944598s
proposed: 0.023752407s
Proposed is 1.01x faster
- Output for 8.0.10
- current: 0.025528564s
proposed: 0.024487421s
Proposed is 1.04x faster
- Output for 8.0.9
- current: 0.025237966s
proposed: 0.026141458s
Proposed is 0.97x faster
- Output for 8.0.8
- current: 0.028736156s
proposed: 0.025614615s
Proposed is 1.12x faster
- Output for 8.0.7
- current: 0.027996834s
proposed: 0.026865732s
Proposed is 1.04x faster
- Output for 8.0.6
- current: 0.027040162s
proposed: 0.025199964s
Proposed is 1.07x faster
- Output for 8.0.5
- current: 0.025747365s
proposed: 0.024339493s
Proposed is 1.06x faster
- Output for 8.0.3
- current: 0.025448391s
proposed: 0.024204869s
Proposed is 1.05x faster
- Output for 8.0.2
- current: 0.028626149s
proposed: 0.026378013s
Proposed is 1.09x faster
- Output for 8.0.1
- current: 0.024081326s
proposed: 0.025323296s
Proposed is 0.95x faster
preferences:
61.24 ms | 541 KiB | 5 Q