@ 2023-06-23T14:35:38Z <?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 ) );
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.4.2 0.000 0.038 17.99 8.4.1 0.007 0.074 24.05 8.3.14 0.010 0.078 16.56 8.3.13 0.009 0.028 16.68 8.3.12 0.010 0.032 19.09 8.3.11 0.010 0.050 20.94 8.3.10 0.007 0.033 24.06 8.3.9 0.003 0.033 26.77 8.3.8 0.003 0.044 18.30 8.3.7 0.013 0.056 18.55 8.3.6 0.007 0.064 16.88 8.3.5 0.013 0.067 18.34 8.3.4 0.010 0.060 20.46 8.3.3 0.013 0.055 20.30 8.3.2 0.007 0.030 24.18 8.3.1 0.003 0.033 24.66 8.3.0 0.016 0.041 26.16 8.2.26 0.016 0.056 16.71 8.2.25 0.003 0.034 18.51 8.2.24 0.007 0.031 19.10 8.2.23 0.007 0.070 22.58 8.2.22 0.000 0.041 37.54 8.2.21 0.000 0.037 26.77 8.2.20 0.007 0.052 16.25 8.2.19 0.013 0.065 16.70 8.2.18 0.010 0.063 16.63 8.2.17 0.003 0.065 18.88 8.2.16 0.007 0.060 22.96 8.2.15 0.007 0.030 25.66 8.2.14 0.006 0.031 24.66 8.2.13 0.017 0.053 26.16 8.2.12 0.007 0.031 22.26 8.2.11 0.010 0.051 19.39 8.2.10 0.007 0.066 18.03 8.2.9 0.007 0.050 18.41 8.2.8 0.009 0.057 19.41 8.2.7 0.010 0.046 17.63 8.2.6 0.003 0.052 17.75 8.2.5 0.007 0.049 17.75 8.2.4 0.003 0.051 17.75 8.2.3 0.006 0.049 17.75 8.2.2 0.003 0.051 17.63 8.2.1 0.010 0.047 17.75 8.2.0 0.007 0.052 17.63 8.1.31 0.013 0.065 18.63 8.1.30 0.004 0.035 18.34 8.1.29 0.000 0.066 18.88 8.1.28 0.007 0.064 25.92 8.1.27 0.010 0.052 24.66 8.1.26 0.010 0.050 26.35 8.1.25 0.000 0.037 28.09 8.1.24 0.003 0.058 22.44 8.1.23 0.007 0.054 20.97 8.1.22 0.007 0.050 17.91 8.1.21 0.000 0.051 19.10 8.1.20 0.000 0.052 17.47 8.1.19 0.006 0.046 17.35 8.1.18 0.000 0.055 17.35 8.1.17 0.003 0.051 17.35 8.1.16 0.003 0.052 17.35 8.1.15 0.007 0.049 17.59 8.1.14 0.007 0.047 17.47 8.1.13 0.000 0.054 17.60 8.1.12 0.007 0.047 17.60 8.1.11 0.000 0.053 17.73 8.1.10 0.006 0.045 17.60 8.1.9 0.000 0.053 17.60 8.1.8 0.003 0.051 17.60 8.1.7 0.006 0.048 17.47 8.1.6 0.010 0.042 17.60 8.1.5 0.003 0.050 17.72 8.1.4 0.003 0.051 17.50 8.1.3 0.000 0.053 17.72 8.1.2 0.003 0.052 17.73 8.1.1 0.003 0.052 17.60 8.1.0 0.003 0.053 17.47 8.0.30 0.000 0.053 20.21 8.0.29 0.007 0.052 17.12 8.0.28 0.000 0.060 17.12 8.0.27 0.007 0.052 17.12 8.0.26 0.003 0.057 17.12 8.0.25 0.006 0.054 17.12 8.0.24 0.000 0.057 17.12 8.0.23 0.003 0.053 17.12 8.0.22 0.010 0.048 17.12 8.0.21 0.000 0.057 17.12 8.0.20 0.003 0.056 17.12 8.0.19 0.007 0.053 17.12 8.0.18 0.003 0.058 17.12 8.0.17 0.003 0.057 17.13 8.0.16 0.003 0.060 17.12 8.0.15 0.003 0.061 17.12 8.0.14 0.000 0.058 17.12 8.0.13 0.006 0.055 17.12 8.0.12 0.000 0.058 17.12 8.0.11 0.003 0.057 17.12 8.0.10 0.010 0.060 17.12 8.0.9 0.003 0.060 17.12 8.0.8 0.000 0.060 17.12 8.0.7 0.003 0.059 17.12 8.0.6 0.007 0.053 17.12 8.0.5 0.007 0.059 17.12 8.0.3 0.003 0.068 17.12 8.0.2 0.003 0.064 17.12 8.0.1 0.013 0.051 17.12
preferences:dark mode live preview
22.45 ms | 403 KiB | 5 Q