Changeset 43776
- Timestamp:
- 10/21/2018 03:02:49 PM (6 years ago)
- Location:
- branches/5.0/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/class-wp-locale-switcher.php
r41289 r43776 46 46 */ 47 47 public function __construct() { 48 $this->original_locale = is_admin() ? get_user_locale() : get_locale();48 $this->original_locale = determine_locale(); 49 49 $this->available_languages = array_merge( array( 'en_US' ), get_available_languages() ); 50 50 } … … 68 68 */ 69 69 public function switch_to_locale( $locale ) { 70 $current_locale = is_admin() ? get_user_locale() : get_locale();70 $current_locale = determine_locale(); 71 71 if ( $current_locale === $locale ) { 72 72 return false; -
branches/5.0/src/wp-includes/general-template.php
r43761 r43776 704 704 $output = __( 'html_lang_attribute' ); 705 705 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(); 707 707 $output = str_replace( '_', '-', $output ); 708 708 } -
branches/5.0/src/wp-includes/l10n.php
r43759 r43776 106 106 107 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 */ 116 function 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 155 /** 108 156 * Retrieve the translation of $text. 109 157 * … … 664 712 function load_default_textdomain( $locale = null ) { 665 713 if ( null === $locale ) { 666 $locale = is_admin() ? get_user_locale() : get_locale();714 $locale = determine_locale(); 667 715 } 668 716 … … 712 760 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 713 761 */ 714 $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );762 $locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); 715 763 716 764 $mofile = $domain . '-' . $locale . '.mo'; … … 746 794 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 747 795 /** 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 ); 749 797 750 798 $mofile = $domain . '-' . $locale . '.mo'; … … 785 833 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 786 834 */ 787 $locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain );835 $locale = apply_filters( 'theme_locale', determine_locale(), $domain ); 788 836 789 837 $mofile = $domain . '-' . $locale . '.mo'; … … 916 964 } 917 965 918 $locale = is_admin() ? get_user_locale() : get_locale();966 $locale = determine_locale(); 919 967 $mofile = "{$domain}-{$locale}.mo"; 920 968 … … 1211 1259 ); 1212 1260 1213 // List installed languages. 1261 // List installed languages. 1214 1262 foreach ( $languages as $language ) { 1215 1263 $structure[] = sprintf( … … 1348 1396 '' => array( 1349 1397 'domain' => $domain, 1350 'lang' => is_admin() ? get_user_locale() : get_locale(),1398 'lang' => determine_locale(), 1351 1399 ), 1352 1400 ); -
branches/5.0/src/wp-includes/script-loader.php
r43760 r43776 906 906 907 907 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(), '_-' ) ), 909 909 'strings' => array( 910 910 '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/' ), -
branches/5.0/src/wp-login.php
r43458 r43776 438 438 setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure ); 439 439 440 $lang = ! empty( $_GET['wp_lang'] ) ? sanitize_text_field( $_GET['wp_lang'] ) : '';441 $switched_locale = switch_to_locale( $lang );442 443 440 /** 444 441 * Fires when the login form is initialized. … … 501 498 setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure ); 502 499 503 if ( $switched_locale ) {504 restore_previous_locale();505 }506 507 500 wp_safe_redirect( wp_get_referer() ); 508 501 exit(); … … 520 513 $redirect_to = 'wp-login.php?loggedout=true'; 521 514 $requested_redirect_to = ''; 522 }523 524 if ( $switched_locale ) {525 restore_previous_locale();526 515 } 527 516 … … 618 607 <?php 619 608 login_footer('user_login'); 620 621 if ( $switched_locale ) {622 restore_previous_locale();623 }624 609 625 610 break; … … 748 733 login_footer('user_pass'); 749 734 750 if ( $switched_locale ) {751 restore_previous_locale();752 }753 754 735 break; 755 736 … … 834 815 <?php 835 816 login_footer('user_login'); 836 837 if ( $switched_locale ) {838 restore_previous_locale();839 }840 817 841 818 break; … … 1120 1097 login_footer(); 1121 1098 1122 if ( $switched_locale ) {1123 restore_previous_locale();1124 }1125 1126 1099 break; 1127 1100 } // end action switch
Note: See TracChangeset
for help on using the changeset viewer.