@ 2023-06-23T14:33:51Z <?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.4.2 0.003 0.028 17.80 8.4.1 0.000 0.031 23.90 8.3.15 0.007 0.023 18.93 8.3.14 0.014 0.049 20.80 8.3.13 0.000 0.030 18.31 8.3.12 0.007 0.024 20.57 8.3.11 0.007 0.049 20.94 8.3.10 0.009 0.022 24.06 8.3.9 0.010 0.019 26.77 8.3.8 0.007 0.030 18.43 8.3.7 0.007 0.051 16.63 8.3.6 0.013 0.053 16.88 8.3.5 0.013 0.054 16.84 8.3.4 0.014 0.064 20.48 8.3.3 0.010 0.045 20.17 8.3.2 0.006 0.025 24.18 8.3.1 0.013 0.033 24.66 8.3.0 0.013 0.042 26.16 8.2.27 0.006 0.022 17.09 8.2.26 0.007 0.043 18.61 8.2.25 0.007 0.022 18.29 8.2.24 0.010 0.060 17.15 8.2.23 0.006 0.025 22.58 8.2.22 0.003 0.029 37.54 8.2.21 0.010 0.044 26.77 8.2.20 0.006 0.031 18.54 8.2.19 0.007 0.048 16.70 8.2.18 0.013 0.049 16.50 8.2.17 0.003 0.053 19.27 8.2.16 0.013 0.042 22.96 8.2.15 0.000 0.030 25.66 8.2.14 0.010 0.051 24.66 8.2.13 0.000 0.030 26.16 8.2.12 0.004 0.036 22.24 8.2.11 0.010 0.045 19.51 8.2.10 0.010 0.042 17.84 8.2.9 0.003 0.037 19.86 8.2.8 0.010 0.034 19.36 8.2.7 0.004 0.039 17.63 8.2.6 0.012 0.031 17.75 8.2.5 0.003 0.040 17.63 8.2.4 0.000 0.041 17.63 8.2.3 0.010 0.032 17.88 8.2.2 0.003 0.039 17.75 8.2.1 0.004 0.039 17.63 8.2.0 0.003 0.038 17.88 8.1.31 0.010 0.055 16.89 8.1.30 0.007 0.047 17.85 8.1.29 0.007 0.032 18.88 8.1.28 0.020 0.065 25.92 8.1.27 0.010 0.023 22.22 8.1.26 0.003 0.029 26.35 8.1.25 0.003 0.028 28.09 8.1.24 0.000 0.050 22.25 8.1.23 0.007 0.031 21.09 8.1.22 0.004 0.035 17.74 8.1.21 0.000 0.036 19.04 8.1.20 0.000 0.039 17.35 8.1.19 0.006 0.038 17.47 8.1.18 0.003 0.038 17.47 8.1.17 0.003 0.037 17.47 8.1.16 0.000 0.042 17.60 8.1.15 0.003 0.035 17.60 8.1.14 0.003 0.036 17.38 8.1.13 0.007 0.033 17.59 8.1.12 0.007 0.032 17.60 8.1.11 0.006 0.034 17.47 8.1.10 0.007 0.034 17.60 8.1.9 0.003 0.037 17.47 8.1.8 0.000 0.039 17.60 8.1.7 0.004 0.035 17.47 8.1.6 0.007 0.033 17.72 8.1.5 0.000 0.040 17.48 8.1.4 0.010 0.030 17.72 8.1.3 0.003 0.036 17.60 8.1.2 0.003 0.037 17.72 8.1.1 0.003 0.037 17.50 8.1.0 0.006 0.034 17.60 8.0.30 0.003 0.037 20.18 8.0.29 0.007 0.037 17.12 8.0.28 0.000 0.046 17.12 8.0.27 0.003 0.042 17.12 8.0.26 0.003 0.042 17.12 8.0.25 0.010 0.036 17.12 8.0.24 0.007 0.039 17.12 8.0.23 0.000 0.045 17.12 8.0.22 0.003 0.041 17.12 8.0.21 0.003 0.040 17.12 8.0.20 0.010 0.036 17.12 8.0.19 0.010 0.036 17.12 8.0.18 0.007 0.040 17.12 8.0.17 0.004 0.043 17.12 8.0.16 0.000 0.045 17.12 8.0.15 0.003 0.043 17.12 8.0.14 0.010 0.033 17.12 8.0.13 0.006 0.039 17.12 8.0.12 0.003 0.039 17.12 8.0.11 0.000 0.044 17.12 8.0.10 0.003 0.041 17.12 8.0.9 0.003 0.040 17.12 8.0.8 0.007 0.037 17.12 8.0.7 0.003 0.042 17.12 8.0.6 0.003 0.041 17.12 8.0.5 0.010 0.035 17.12 8.0.3 0.000 0.043 17.12 8.0.2 0.006 0.038 17.12 8.0.1 0.007 0.036 17.12
preferences:dark mode live preview
28.53 ms | 403 KiB | 5 Q