@ 2023-06-23T14:33:30Z <?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 ) );
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.11 0.006 0.029 20.94 8.3.10 0.006 0.029 16.50 8.3.9 0.006 0.051 26.77 8.3.8 0.003 0.051 17.97 8.3.7 0.020 0.069 16.50 8.3.6 0.016 0.062 17.00 8.3.5 0.013 0.059 18.40 8.3.4 0.010 0.057 20.46 8.3.3 0.010 0.057 20.34 8.3.2 0.006 0.064 24.18 8.3.1 0.007 0.049 24.66 8.3.0 0.013 0.049 26.16 8.2.23 0.000 0.038 22.58 8.2.22 0.003 0.034 24.06 8.2.21 0.007 0.030 26.77 8.2.20 0.003 0.041 16.75 8.2.19 0.007 0.069 16.74 8.2.18 0.010 0.071 16.50 8.2.17 0.010 0.061 19.04 8.2.16 0.007 0.060 22.96 8.2.15 0.004 0.032 25.66 8.2.14 0.006 0.032 24.66 8.2.13 0.004 0.033 26.16 8.2.12 0.007 0.030 22.32 8.2.11 0.010 0.047 19.41 8.2.10 0.014 0.057 17.81 8.2.9 0.003 0.057 18.22 8.2.8 0.000 0.052 19.16 8.2.7 0.003 0.053 19.35 8.2.6 0.010 0.051 19.22 8.2.5 0.003 0.051 19.37 8.2.4 0.000 0.057 19.48 8.2.3 0.007 0.050 19.28 8.2.2 0.006 0.048 17.47 8.2.1 0.003 0.050 17.63 8.2.0 0.010 0.046 17.88 8.1.29 0.003 0.043 30.84 8.1.28 0.003 0.068 25.92 8.1.27 0.003 0.045 24.66 8.1.26 0.000 0.038 26.35 8.1.25 0.013 0.048 28.09 8.1.24 0.007 0.049 22.31 8.1.23 0.007 0.040 21.07 8.1.22 0.000 0.051 17.91 8.1.21 0.006 0.042 19.14 8.1.20 0.007 0.044 17.35 8.1.19 0.003 0.046 17.35 8.1.18 0.003 0.051 17.48 8.1.17 0.003 0.049 17.47 8.1.16 0.000 0.053 17.34 8.1.15 0.000 0.053 17.60 8.1.14 0.000 0.051 17.47 8.1.13 0.013 0.043 17.38 8.1.12 0.007 0.044 17.59 8.1.11 0.006 0.045 17.60 8.1.10 0.010 0.040 17.60 8.1.9 0.003 0.049 17.47 8.1.8 0.000 0.053 17.60 8.1.7 0.007 0.046 17.59 8.1.6 0.007 0.046 17.72 8.1.5 0.003 0.048 17.60 8.1.4 0.003 0.052 17.59 8.1.3 0.010 0.042 17.72 8.1.2 0.007 0.045 17.72 8.1.1 0.000 0.054 17.59 8.1.0 0.003 0.048 17.47 8.0.30 0.006 0.045 20.39 8.0.29 0.007 0.051 17.12 8.0.28 0.010 0.050 17.12 8.0.27 0.007 0.052 17.12 8.0.26 0.003 0.057 17.12 8.0.25 0.010 0.049 17.12 8.0.24 0.000 0.055 17.12 8.0.23 0.003 0.052 17.12 8.0.22 0.003 0.053 17.12 8.0.21 0.003 0.053 17.12 8.0.20 0.007 0.056 17.12 8.0.19 0.003 0.055 17.12 8.0.18 0.000 0.060 17.12 8.0.17 0.007 0.052 17.12 8.0.16 0.007 0.052 17.12 8.0.15 0.003 0.054 17.12 8.0.14 0.003 0.053 18.61 8.0.13 0.000 0.057 18.61 8.0.12 0.007 0.049 18.61 8.0.11 0.003 0.053 18.74 8.0.10 0.000 0.058 18.49 8.0.9 0.003 0.058 18.62 8.0.8 0.007 0.056 18.62 8.0.7 0.000 0.063 17.12 8.0.6 0.007 0.053 17.12 8.0.5 0.007 0.051 17.12 8.0.3 0.006 0.051 17.12 8.0.2 0.010 0.053 17.12 8.0.1 0.000 0.060 17.12
preferences:dark mode live preview
28.41 ms | 403 KiB | 5 Q