WordPress.org

Make WordPress Core

Ticket #44758: 44758.5.diff

File 44758.5.diff, 8.2 KB (added by danielbachhuber, 2 years ago)
  • src/wp-includes/class-wp-locale-switcher.php

    diff --git a/src/wp-includes/class-wp-locale-switcher.php b/src/wp-includes/class-wp-locale-switcher.php
    index e111892871..aa74fb4f83 100644
    a b class WP_Locale_Switcher { 
    4545         * @since 4.7.0
    4646         */
    4747        public function __construct() {
    48                 $this->original_locale     = is_admin() ? get_user_locale() : get_locale();
     48                $this->original_locale     = determine_locale();
    4949                $this->available_languages = array_merge( array( 'en_US' ), get_available_languages() );
    5050        }
    5151
    class WP_Locale_Switcher { 
    6767         * @return bool True on success, false on failure.
    6868         */
    6969        public function switch_to_locale( $locale ) {
    70                 $current_locale = is_admin() ? get_user_locale() : get_locale();
     70                $current_locale = determine_locale();
    7171                if ( $current_locale === $locale ) {
    7272                        return false;
    7373                }
  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index 63b85378e2..c3eca6df89 100644
    a b function get_bloginfo( $show = '', $filter = 'raw' ) { 
    703703                         */
    704704                        $output = __( 'html_lang_attribute' );
    705705                        if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) {
    706                                 $output = is_admin() ? get_user_locale() : get_locale();
     706                                $output = determine_locale();
    707707                                $output = str_replace( '_', '-', $output );
    708708                        }
    709709                        break;
  • src/wp-includes/l10n.php

    diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php
    index 0ee9c46f2e..b1aa6c553c 100644
    a b function get_user_locale( $user_id = 0 ) { 
    104104        return $locale ? $locale : get_locale();
    105105}
    106106
     107/**
     108 * Determine the current locale desired for the request.
     109 *
     110 * @since 5.0.0
     111 *
     112 * @global string $pagenow
     113 *
     114 * @return string The determined locale.
     115 */
     116function determine_locale() {
     117        /**
     118         * Filters the locale for the current request prior to the default determination process.
     119         *
     120         * Using this filter allows to override the default logic, effectively short-circuiting the function.
     121         *
     122         * @since 5.0.0
     123         *
     124         * @param string|null The locale to return and short-circuit, or null as default.
     125         */
     126        $determined_locale = apply_filters( 'pre_determine_locale', null );
     127        if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
     128                return $determined_locale;
     129        }
     130
     131        $determined_locale = get_locale();
     132
     133        if ( is_admin() ) {
     134                $determined_locale = get_user_locale();
     135        }
     136
     137        if ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() && is_user_logged_in() ) {
     138                $determined_locale = get_user_locale();
     139        }
     140
     141        if ( ! empty( $_GET['wp_lang'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
     142                $determined_locale = sanitize_text_field( $_GET['wp_lang'] );
     143        }
     144
     145        /**
     146         * Filters the locale for the current request.
     147         *
     148         * @since 5.0.0
     149         *
     150         * @param string $locale The locale.
     151         */
     152        return apply_filters( 'determine_locale', $determined_locale );
     153}
     154
    107155/**
    108156 * Retrieve the translation of $text.
    109157 *
    function unload_textdomain( $domain ) { 
    663711 */
    664712function load_default_textdomain( $locale = null ) {
    665713        if ( null === $locale ) {
    666                 $locale = is_admin() ? get_user_locale() : get_locale();
     714                $locale = determine_locale();
    667715        }
    668716
    669717        // Unload previously loaded strings so we can switch translations.
    function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path 
    711759         * @param string $locale The plugin's current locale.
    712760         * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    713761         */
    714         $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
     762        $locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
    715763
    716764        $mofile = $domain . '-' . $locale . '.mo';
    717765
    function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path 
    745793 */
    746794function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
    747795        /** This filter is documented in wp-includes/l10n.php */
    748         $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
     796        $locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
    749797
    750798        $mofile = $domain . '-' . $locale . '.mo';
    751799
    function load_theme_textdomain( $domain, $path = false ) { 
    784832         * @param string $locale The theme's current locale.
    785833         * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    786834         */
    787         $locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
     835        $locale = apply_filters( 'theme_locale', determine_locale(), $domain );
    788836
    789837        $mofile = $domain . '-' . $locale . '.mo';
    790838
    function _get_path_to_translation_from_lang_dir( $domain ) { 
    915963                }
    916964        }
    917965
    918         $locale = is_admin() ? get_user_locale() : get_locale();
     966        $locale = determine_locale();
    919967        $mofile = "{$domain}-{$locale}.mo";
    920968
    921969        $path = WP_LANG_DIR . '/plugins/' . $mofile;
    function wp_dropdown_languages( $args = array() ) { 
    12101258                selected( '', $parsed_args['selected'], false )
    12111259        );
    12121260
    1213         // List installed languages. 
     1261        // List installed languages.
    12141262        foreach ( $languages as $language ) {
    12151263                $structure[] = sprintf(
    12161264                        '<option value="%s" lang="%s"%s data-installed="1">%s</option>',
    function wp_get_jed_locale_data( $domain ) { 
    13471395        $locale = array(
    13481396                '' => array(
    13491397                        'domain' => $domain,
    1350                         'lang'   => is_admin() ? get_user_locale() : get_locale(),
     1398                        'lang'   => determine_locale(),
    13511399                ),
    13521400        );
    13531401
  • src/wp-includes/script-loader.php

    diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
    index dcc167e19f..598e6dfac3 100644
    a b function wp_default_scripts( &$scripts ) { 
    905905        $scripts->add( 'mediaelement-migrate', "/wp-includes/js/mediaelement/mediaelement-migrate$suffix.js", array(), false, 1);
    906906
    907907        did_action( 'init' ) && $scripts->add_inline_script( 'mediaelement-core', sprintf( 'var mejsL10n = %s;', wp_json_encode( array(
    908                 'language' => strtolower( strtok( is_admin() ? get_user_locale() : get_locale(), '_-' ) ),
     908                'language' => strtolower( strtok( determine_locale(), '_-' ) ),
    909909                'strings'  => array(
    910910                        'mejs.install-flash'       => __( 'You are using a browser that does not have Flash player enabled or installed. Please turn on your Flash player plugin or download the latest version from https://get.adobe.com/flashplayer/' ),
    911911                        'mejs.fullscreen-off'      => __( 'Turn off Fullscreen' ),
  • src/wp-login.php

    diff --git a/src/wp-login.php b/src/wp-login.php
    index ffd86c1e20..fe9df8704b 100644
    a b setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure 
    437437if ( SITECOOKIEPATH != COOKIEPATH )
    438438        setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
    439439
    440 $lang            = ! empty( $_GET['wp_lang'] ) ? sanitize_text_field( $_GET['wp_lang'] ) : '';
    441 $switched_locale = switch_to_locale( $lang );
    442 
    443440/**
    444441 * Fires when the login form is initialized.
    445442 *
    case 'postpass' : 
    500497        }
    501498        setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
    502499
    503         if ( $switched_locale ) {
    504             restore_previous_locale();
    505         }
    506 
    507500        wp_safe_redirect( wp_get_referer() );
    508501        exit();
    509502
    case 'logout' : 
    521514                $requested_redirect_to = '';
    522515        }
    523516
    524         if ( $switched_locale ) {
    525             restore_previous_locale();
    526         }
    527 
    528517        /**
    529518         * Filters the log out redirect URL.
    530519         *
    endif; 
    618607<?php
    619608login_footer('user_login');
    620609
    621 if ( $switched_locale ) {
    622     restore_previous_locale();
    623 }
    624 
    625610break;
    626611
    627612case 'resetpass' :
    endif; 
    747732<?php
    748733login_footer('user_pass');
    749734
    750 if ( $switched_locale ) {
    751     restore_previous_locale();
    752 }
    753 
    754735break;
    755736
    756737case 'register' :
    case 'register' : 
    834815<?php
    835816login_footer('user_login');
    836817
    837 if ( $switched_locale ) {
    838     restore_previous_locale();
    839 }
    840 
    841818break;
    842819
    843820case 'confirmaction' :
    try { 
    11191096<?php
    11201097login_footer();
    11211098
    1122 if ( $switched_locale ) {
    1123     restore_previous_locale();
    1124 }
    1125 
    11261099break;
    11271100} // end action switch