Ticket #26511: 26511.13.diff
File 26511.13.diff, 30.8 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/ms.php
diff --git src/wp-admin/includes/ms.php src/wp-admin/includes/ms.php index 7e08e6f..48dbf55 100644
function update_option_new_admin_email( $old_value, $value ) { 272 272 ); 273 273 update_option( 'adminhash', $new_admin_email ); 274 274 275 $switched_locale = switch_to_locale( get_user_locale() ); 276 275 277 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ 276 278 $email_text = __( 'Howdy ###USERNAME###, 277 279 … … All at ###SITENAME### 315 317 $content = str_replace( '###SITEURL###', network_home_url(), $content ); 316 318 317 319 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); 320 321 if ( $switched_locale ) { 322 restore_previous_locale(); 323 } 318 324 } 319 325 320 326 /** … … function send_confirmation_on_profile_email() { 353 359 ); 354 360 update_user_meta( $current_user->ID, '_new_email', $new_user_email ); 355 361 362 $switched_locale = switch_to_locale( get_user_locale() ); 363 356 364 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ 357 365 $email_text = __( 'Howdy ###USERNAME###, 358 366 … … All at ###SITENAME### 395 403 396 404 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); 397 405 $_POST['email'] = $current_user->user_email; 406 407 if ( $switched_locale ) { 408 restore_previous_locale(); 409 } 398 410 } 399 411 } 400 412 -
src/wp-admin/includes/upgrade.php
diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php index 8699a08..e8cc993 100644
function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) { 373 373 $email = $user->user_email; 374 374 $name = $user->user_login; 375 375 $login_url = wp_login_url(); 376 377 $switched_locale = switch_to_locale( $user->locale ); 378 376 379 $message = sprintf( __( "Your new WordPress site has been successfully set up at: 377 380 378 381 %1\$s … … https://wordpress.org/ 390 393 "), $blog_url, $name, $password, $login_url ); 391 394 392 395 @wp_mail($email, __('New WordPress Site'), $message); 396 397 if ( $switched_locale ) { 398 restore_previous_locale(); 399 } 393 400 } 394 401 endif; 395 402 -
src/wp-admin/ms-delete-site.php
diff --git src/wp-admin/ms-delete-site.php src/wp-admin/ms-delete-site.php index 9192509..6bc3cfc 100644
if ( isset( $_POST['action'] ) && $_POST['action'] == 'deleteblog' && isset( $_P 42 42 43 43 $url_delete = esc_url( admin_url( 'ms-delete-site.php?h=' . $hash ) ); 44 44 45 $switched_locale = switch_to_locale( get_locale() ); 46 45 47 /* translators: Do not translate USERNAME, URL_DELETE, SITE_NAME: those are placeholders. */ 46 48 $content = __( "Howdy ###USERNAME###, 47 49 … … Webmaster 73 75 $content = str_replace( '###SITE_NAME###', get_network()->site_name, $content ); 74 76 75 77 wp_mail( get_option( 'admin_email' ), "[ " . wp_specialchars_decode( get_option( 'blogname' ) ) . " ] ".__( 'Delete My Site' ), $content ); 78 79 if ( $switched_locale ) { 80 restore_previous_locale(); 81 } 76 82 ?> 77 83 78 84 <p><?php _e( 'Thank you. Please check your email for a link to confirm your action. Your site will not be deleted until this link is clicked.' ) ?></p> -
src/wp-admin/user-new.php
diff --git src/wp-admin/user-new.php src/wp-admin/user-new.php index 38b78dd..13d753d 100644
if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) { 87 87 */ 88 88 do_action( 'invite_user', $user_id, $role, $newuser_key ); 89 89 90 $switched_locale = switch_to_locale( $user_details->locale ); 91 90 92 /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */ 91 93 $message = __( 'Hi, 92 94 … … You\'ve been invited to join \'%1$s\' at 96 98 Please click the following link to confirm the invite: 97 99 %4$s' ); 98 100 wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), sprintf( $message, get_option( 'blogname' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ), home_url( "/newbloguser/$newuser_key/" ) ) ); 101 102 if ( $switched_locale ) { 103 restore_previous_locale(); 104 } 105 99 106 $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' ); 100 107 } 101 108 } -
new file src/wp-includes/class-wp-locale-switcher.php
diff --git src/wp-includes/class-wp-locale-switcher.php src/wp-includes/class-wp-locale-switcher.php new file mode 100644 index 0000000..0dd3f36
- + 1 <?php 2 /** 3 * Locale API: WP_Locale_Switcher class 4 * 5 * @package WordPress 6 * @subpackage i18n 7 * @since 4.7.0 8 */ 9 10 /** 11 * Core class used for switching locales. 12 * 13 * @since 4.7.0 14 */ 15 class WP_Locale_Switcher { 16 /** 17 * Locale stack. 18 * 19 * @since 4.7.0 20 * @access private 21 * @var string[] 22 */ 23 private $locales = array(); 24 25 /** 26 * Original locale. 27 * 28 * @since 4.7.0 29 * @access private 30 * @var string 31 */ 32 private $original_locale; 33 34 /** 35 * Holds all available languages. 36 * 37 * @since 4.7.0 38 * @access private 39 * @var array An array of language codes (file names without the .mo extension). 40 */ 41 private $available_languages = array(); 42 43 /** 44 * Constructor. 45 * 46 * Stores the original locale as well as a list of all available languages. 47 * 48 * @since 4.7.0 49 */ 50 public function __construct() { 51 $this->original_locale = get_locale(); 52 $this->available_languages = get_available_languages(); 53 } 54 55 /** 56 * Initializes the locale switcher. 57 * 58 * Hooks into the {@see 'locale'} filter to change the locale on the fly. 59 */ 60 public function init() { 61 add_filter( 'locale', array( $this, 'filter_locale' ) ); 62 } 63 64 /** 65 * Switches the translations according to the given locale. 66 * 67 * @since 4.7.0 68 * 69 * @param string $locale The locale to switch to. 70 * @return bool True on success, false on failure. 71 */ 72 public function switch_to_locale( $locale ) { 73 if ( $locale === get_locale() ) { 74 return false; 75 } 76 77 if ( ! in_array( $locale, $this->available_languages, true ) ) { 78 return false; 79 } 80 81 $this->locales[] = $locale; 82 83 $this->change_locale( $locale ); 84 85 /** 86 * Fires when the locale is switched. 87 * 88 * @since 4.7.0 89 * 90 * @param string $locale The new locale. 91 */ 92 do_action( 'switch_locale', $locale ); 93 94 return true; 95 } 96 97 /** 98 * Restores the translations according to the previous locale. 99 * 100 * @since 4.7.0 101 * 102 * @return string|false Locale on success, false on failure. 103 */ 104 public function restore_previous_locale() { 105 $previous_locale = array_pop( $this->locales ); 106 107 if ( null === $previous_locale ) { 108 // The stack is empty, bail. 109 return false; 110 } 111 112 $locale = end( $this->locales ); 113 114 if ( ! $locale ) { 115 // There's nothing left in the stack: go back to the original locale. 116 $locale = $this->original_locale; 117 } 118 119 $this->change_locale( $locale ); 120 121 /** 122 * Fires when the locale is restored to the previous one. 123 * 124 * @since 4.7.0 125 * 126 * @param string $locale The new locale. 127 * @param string $previous_locale The previous locale. 128 */ 129 do_action( 'restore_previous_locale', $locale, $previous_locale ); 130 131 return $locale; 132 } 133 134 /** 135 * Restores the translations according to the original locale. 136 * 137 * @since 4.7.0 138 * 139 * @return string|false Locale on success, false on failure. 140 */ 141 public function restore_current_locale() { 142 if ( empty( $this->locales ) ) { 143 return false; 144 } 145 146 $this->locales = array( $this->original_locale ); 147 148 return $this->restore_previous_locale(); 149 } 150 151 /** 152 * Whether switch_to_locale() is in effect. 153 * 154 * @since 4.7.0 155 * 156 * @return bool True if the locale has been switched, false otherwise. 157 */ 158 public function is_switched() { 159 return ! empty( $this->locales ); 160 } 161 162 /** 163 * Filters the WordPress install's locale. 164 * 165 * @since 4.7.0 166 * 167 * @param string $locale The WordPress install's locale. 168 * @return string The locale currently being switched to. 169 */ 170 public function filter_locale( $locale ) { 171 $switched_locale = end( $this->locales ); 172 173 if ( $switched_locale ) { 174 return $switched_locale; 175 } 176 177 return $locale; 178 } 179 180 /** 181 * Load translations for a given locale. 182 * 183 * When switching to a locale, translations for this locale must be loaded from scratch. 184 * 185 * @since 4.7.0 186 * @access private 187 * 188 * @global Mo[] $l10n An array of all currently loaded text domains. 189 * 190 * @param string $locale The locale to load translations for. 191 */ 192 private function load_translations( $locale ) { 193 global $l10n; 194 195 $l10n_copy = $l10n ? $l10n : array(); 196 197 load_default_textdomain( $locale ); 198 199 /* @var MO $mo */ 200 foreach ( $l10n_copy as $domain => $mo ) { 201 if ( 'default' === $domain ) { 202 continue; 203 } 204 205 unload_textdomain( $domain ); 206 207 if ( $mo->get_filename() ) { 208 load_textdomain( $domain, $mo->get_filename() ); 209 } 210 211 get_translations_for_domain( $domain ); 212 } 213 } 214 215 /** 216 * Changes the site's locale to the given one. 217 * 218 * Loads the translations, changes the global `$wp_locale` object and updates 219 * all post type labels. 220 * 221 * @since 4.7.0 222 * @access private 223 * 224 * @global WP_Locale $wp_locale The WordPress date and time locale object. 225 * 226 * @param string $locale The locale to change to. 227 */ 228 private function change_locale( $locale ) { 229 $this->load_translations( $locale ); 230 231 $GLOBALS['wp_locale'] = new WP_Locale(); 232 233 /** 234 * Fires when the locale is switched to or restored. 235 * 236 * @since 4.7.0 237 * 238 * @param string $locale The new locale. 239 */ 240 do_action( 'change_locale', $locale ); 241 } 242 } -
src/wp-includes/default-filters.php
diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php index 71255c3..e38d3f5 100644
add_action( 'init', 'create_initial_post_types', 0 ); // highest priority 404 404 add_action( 'admin_menu', '_add_post_type_submenus' ); 405 405 add_action( 'before_delete_post', '_reset_front_page_settings_for_post' ); 406 406 add_action( 'wp_trash_post', '_reset_front_page_settings_for_post' ); 407 add_action( 'change_locale', 'create_initial_post_types' ); 407 408 408 409 // Post Formats 409 410 add_filter( 'request', '_post_format_request' ); … … add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); 429 430 430 431 // Taxonomy 431 432 add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority 433 add_action( 'change_locale', 'create_initial_taxonomies' ); 432 434 433 435 // Canonical 434 436 add_action( 'template_redirect', 'redirect_canonical' ); -
src/wp-includes/l10n.php
diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php index 03a7a11..902a978 100644
function is_rtl() { 1166 1166 } 1167 1167 return $wp_locale->is_rtl(); 1168 1168 } 1169 1170 /** 1171 * Switches the translations according to the given locale. 1172 * 1173 * @since 4.7.0 1174 * 1175 * @global WP_Locale_Switcher $wp_locale_switcher 1176 * 1177 * @param string $locale The locale. 1178 * @return bool True on success, false on failure. 1179 */ 1180 function switch_to_locale( $locale ) { 1181 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1182 global $wp_locale_switcher; 1183 1184 return $wp_locale_switcher->switch_to_locale( $locale ); 1185 } 1186 1187 /** 1188 * Restores the translations according to the previous locale. 1189 * 1190 * @since 4.7.0 1191 * 1192 * @global WP_Locale_Switcher $wp_locale_switcher 1193 * 1194 * @return string|false Locale on success, false on error. 1195 */ 1196 function restore_previous_locale() { 1197 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1198 global $wp_locale_switcher; 1199 1200 return $wp_locale_switcher->restore_previous_locale(); 1201 } 1202 1203 /** 1204 * Restores the translations according to the original locale. 1205 * 1206 * @since 4.7.0 1207 * 1208 * @global WP_Locale_Switcher $wp_locale_switcher 1209 * 1210 * @return string|false Locale on success, false on error. 1211 */ 1212 function restore_current_locale() { 1213 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1214 global $wp_locale_switcher; 1215 1216 return $wp_locale_switcher->restore_current_locale(); 1217 } 1218 1219 /** 1220 * Whether switch_to_locale() is in effect. 1221 * 1222 * @since 4.7.0 1223 * 1224 * @global WP_Locale_Switcher $wp_locale_switcher 1225 * 1226 * @return bool True if the locale has been switched, false otherwise. 1227 */ 1228 function is_locale_switched() { 1229 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1230 global $wp_locale_switcher; 1231 1232 return $wp_locale_switcher->is_switched(); 1233 } -
src/wp-includes/load.php
diff --git src/wp-includes/load.php src/wp-includes/load.php index 4a3e1c3..523960f 100644
function get_current_network_id() { 841 841 * @since 3.4.0 842 842 * @access private 843 843 * 844 * @global string $text_direction 845 * @global WP_Locale $wp_locale The WordPress date and time locale object. 844 * @global string $text_direction 845 * @global WP_Locale $wp_locale The WordPress date and time locale object. 846 * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. 846 847 * 847 848 * @staticvar bool $loaded 848 849 */ 849 850 function wp_load_translations_early() { 850 global $text_direction, $wp_locale ;851 global $text_direction, $wp_locale, $wp_locale_switcher; 851 852 852 853 static $loaded = false; 853 854 if ( $loaded ) … … function wp_load_translations_early() { 864 865 require_once ABSPATH . WPINC . '/pomo/mo.php'; 865 866 require_once ABSPATH . WPINC . '/l10n.php'; 866 867 require_once ABSPATH . WPINC . '/class-wp-locale.php'; 868 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; 867 869 868 870 // General libraries 869 871 require_once ABSPATH . WPINC . '/plugin.php'; … … function wp_load_translations_early() { 915 917 } 916 918 917 919 $wp_locale = new WP_Locale(); 920 $wp_locale_switcher = new WP_Locale_Switcher(); 921 $wp_locale_switcher->init(); 918 922 } 919 923 920 924 /** -
src/wp-includes/ms-functions.php
diff --git src/wp-includes/ms-functions.php src/wp-includes/ms-functions.php index 3c1911a..58c0536 100644
function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_ema 800 800 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 801 801 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 802 802 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 803 804 $user = get_user_by( 'login', $user ); 805 $switched_locale = switch_to_locale( $user && $user->locale ? $user->locale : get_locale() ); 806 803 807 $message = sprintf( 804 808 /** 805 809 * Filters the message content of the new blog notification email. … … function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_ema 849 853 esc_url( 'http://' . $domain . $path ) 850 854 ); 851 855 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 856 857 if ( $switched_locale ) { 858 restore_previous_locale(); 859 } 860 852 861 return true; 853 862 } 854 863 … … function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array( 887 896 if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) ) 888 897 return false; 889 898 899 $user = get_user_by( 'login', $user ); 900 $switched_locale = switch_to_locale( $user && $user->locale ? $user->locale : get_locale() ); 901 890 902 // Send email with activation link. 891 903 $admin_email = get_site_option( 'admin_email' ); 892 904 if ( $admin_email == '' ) … … function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array( 934 946 $user 935 947 ); 936 948 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 949 950 if ( $switched_locale ) { 951 restore_previous_locale(); 952 } 953 937 954 return true; 938 955 } 939 956 … … function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta 1448 1465 if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) 1449 1466 return false; 1450 1467 1468 $user = get_userdata( $user_id ); 1469 1470 $switched_locale = switch_to_locale( $user->locale ); 1471 1451 1472 $welcome_email = get_site_option( 'welcome_email' ); 1452 1473 if ( $welcome_email == false ) { 1453 1474 /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ … … We hope you enjoy your new site. Thanks! 1468 1489 } 1469 1490 1470 1491 $url = get_blogaddress_by_id($blog_id); 1471 $user = get_userdata( $user_id );1472 1492 1473 1493 $welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email ); 1474 1494 $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email ); … … We hope you enjoy your new site. Thanks! 1512 1532 */ 1513 1533 $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_network->site_name, wp_unslash( $title ) ) ); 1514 1534 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 1535 1536 if ( $switched_locale ) { 1537 restore_previous_locale(); 1538 } 1539 1515 1540 return true; 1516 1541 } 1517 1542 … … function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) 1551 1576 1552 1577 $user = get_userdata( $user_id ); 1553 1578 1579 $switched_locale = switch_to_locale( $user->locale ); 1580 1554 1581 /** 1555 1582 * Filters the content of the welcome email after user activation. 1556 1583 * … … function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) 1590 1617 */ 1591 1618 $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_network->site_name, $user->user_login) ); 1592 1619 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 1620 1621 if ( $switched_locale ) { 1622 restore_previous_locale(); 1623 } 1624 1593 1625 return true; 1594 1626 } 1595 1627 -
src/wp-includes/pluggable.php
diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php index d7713b7..2982a3d 100644
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() 211 211 // (Re)create it, if it's gone missing 212 212 if ( ! ( $phpmailer instanceof PHPMailer ) ) { 213 213 require_once ABSPATH . WPINC . '/class-phpmailer.php'; 214 require_once ABSPATH . WPINC . '/class-smtp.php'; 214 require_once ABSPATH . WPINC . '/class-smtp.php'; 215 215 $phpmailer = new PHPMailer( true ); 216 216 } 217 217 … … function wp_notify_moderator($comment_id) { 1569 1569 $emails[] = $user->user_email; 1570 1570 } 1571 1571 1572 $switched_locale = switch_to_locale( get_locale() ); 1573 1572 1574 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 1573 1575 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); 1574 1576 … … function wp_notify_moderator($comment_id) { 1664 1666 @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); 1665 1667 } 1666 1668 1669 if ( $switched_locale ) { 1670 restore_previous_locale(); 1671 } 1672 1667 1673 return true; 1668 1674 } 1669 1675 endif; … … function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) 1723 1729 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 1724 1730 1725 1731 if ( 'user' !== $notify ) { 1732 $switched_locale = switch_to_locale( get_locale() ); 1726 1733 $message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n"; 1727 1734 $message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n"; 1728 1735 $message .= sprintf( __( 'Email: %s' ), $user->user_email ) . "\r\n"; 1729 1736 1730 1737 @wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New User Registration' ), $blogname ), $message ); 1738 1739 if ( $switched_locale ) { 1740 restore_previous_locale(); 1741 } 1731 1742 } 1732 1743 1733 1744 // `$deprecated was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notifcation. … … function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) 1748 1759 $hashed = time() . ':' . $wp_hasher->HashPassword( $key ); 1749 1760 $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); 1750 1761 1762 $switched_locale = switch_to_locale( $user->locale ); 1763 1751 1764 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n"; 1752 1765 $message .= __('To set your password, visit the following address:') . "\r\n\r\n"; 1753 1766 $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n"; … … function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) 1755 1768 $message .= wp_login_url() . "\r\n"; 1756 1769 1757 1770 wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message); 1771 1772 if ( $switched_locale ) { 1773 restore_previous_locale(); 1774 } 1758 1775 } 1759 1776 endif; 1760 1777 -
src/wp-includes/pomo/mo.php
diff --git src/wp-includes/pomo/mo.php src/wp-includes/pomo/mo.php index 6bc44d6..47e9b6a 100644
class MO extends Gettext_Translations { 16 16 var $_nplurals = 2; 17 17 18 18 /** 19 * Loaded MO file. 20 * 21 * @var string 22 */ 23 private $filename = ''; 24 25 /** 26 * Returns the loaded MO file. 27 * 28 * @return string The loaded MO file. 29 */ 30 public function get_filename() { 31 return $this->filename; 32 } 33 34 /** 19 35 * Fills up with the entries from MO file $filename 20 36 * 21 37 * @param string $filename MO file to load 22 38 */ 23 39 function import_from_file($filename) { 24 $reader = new POMO_FileReader($filename); 25 if (!$reader->is_resource()) 40 $reader = new POMO_FileReader( $filename ); 41 42 if ( ! $reader->is_resource() ) { 26 43 return false; 27 return $this->import_from_reader($reader); 44 } 45 46 $this->filename = (string) $filename; 47 48 return $this->import_from_reader( $reader ); 28 49 } 29 50 30 51 /** … … class MO extends Gettext_Translations { 299 320 return $this->_nplurals; 300 321 } 301 322 } 302 endif; 303 No newline at end of file 323 endif; -
src/wp-includes/user.php
diff --git src/wp-includes/user.php src/wp-includes/user.php index 734d26e..a673b92 100644
function wp_update_user($userdata) { 1801 1801 1802 1802 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1803 1803 1804 if ( ! empty( $send_password_change_email ) ) { 1804 $switched_locale = false; 1805 if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) { 1806 $switched_locale = switch_to_locale( isset( $user['locale'] ) ? $user['locale'] : get_locale() ); 1807 } 1805 1808 1809 if ( ! empty( $send_password_change_email ) ) { 1806 1810 /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ 1807 1811 $pass_change_text = __( 'Hi ###USERNAME###, 1808 1812 … … All at ###SITENAME### 1910 1914 1911 1915 wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); 1912 1916 } 1917 1918 if ( $switched_locale ) { 1919 restore_previous_locale(); 1920 } 1913 1921 } 1914 1922 1915 1923 // Update the cookies if the password changed. -
src/wp-settings.php
diff --git src/wp-settings.php src/wp-settings.php index 3347cc9..4aac905 100644
if ( SHORTINIT ) 129 129 // Load the L10n library. 130 130 require_once( ABSPATH . WPINC . '/l10n.php' ); 131 131 require_once( ABSPATH . WPINC . '/class-wp-locale.php' ); 132 require_once( ABSPATH . WPINC . '/class-wp-locale-switcher.php' ); 132 133 133 134 // Run the installer if WordPress is not installed. 134 135 wp_not_installed(); … … unset( $locale_file ); 399 400 */ 400 401 $GLOBALS['wp_locale'] = new WP_Locale(); 401 402 403 /** 404 * WordPress Locale Switcher object for switching locales. 405 * 406 * @since 4.7.0 407 * 408 * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. 409 */ 410 $GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher(); 411 $GLOBALS['wp_locale_switcher']->init(); 412 402 413 // Load the functions for the active theme, for both parent and child theme if applicable. 403 414 if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) { 404 415 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) ) -
tests/phpunit/tests/l10n.php
diff --git tests/phpunit/tests/l10n.php tests/phpunit/tests/l10n.php index f1048aa..d7fe894 100644
class Tests_L10n extends WP_UnitTestCase { 85 85 $this->assertEmpty( $array ); 86 86 87 87 $array = get_available_languages( DIR_TESTDATA . '/languages/' ); 88 $this->assertEquals( array( ' en_GB', 'es_ES' ), $array );88 $this->assertEquals( array( 'de_DE', 'en_GB', 'es_ES' ), $array ); 89 89 } 90 90 91 91 /** -
tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
diff --git tests/phpunit/tests/l10n/loadTextdomainJustInTime.php tests/phpunit/tests/l10n/loadTextdomainJustInTime.php index f73cfd5..549d1a3 100644
class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 141 141 $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_final ); 142 142 $this->assertTrue( $is_textdomain_loaded_final ); 143 143 } 144 145 /** 146 * @ticket 26511 147 * @group debug 148 */ 149 public function test_plugin_translation_after_switching_locale() { 150 require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; 151 152 switch_to_locale( 'de_DE' ); 153 $expected = i18n_plugin_test(); 154 restore_previous_locale(); 155 156 $this->assertSame( 'Das ist ein Dummy Plugin', $expected ); 157 } 158 159 /** 160 * @ticket 26511 161 * @group debug 162 */ 163 public function test_theme_translation_after_switching_locale() { 164 switch_theme( 'internationalized-theme' ); 165 166 require_once get_stylesheet_directory() . '/functions.php'; 167 168 switch_to_locale( 'de_DE' ); 169 $expected = i18n_theme_test(); 170 restore_previous_locale(); 171 172 switch_theme( WP_DEFAULT_THEME ); 173 174 $this->assertSame( 'Das ist ein Dummy Theme', $expected ); 175 } 144 176 } -
new file tests/phpunit/tests/l10n/localeSwitcher.php
diff --git tests/phpunit/tests/l10n/localeSwitcher.php tests/phpunit/tests/l10n/localeSwitcher.php new file mode 100644 index 0000000..d882df2
- + 1 <?php 2 3 /** 4 * @group l10n 5 * @group i18n 6 * @group 26511 7 */ 8 class Tests_Locale_Switcher extends WP_UnitTestCase { 9 /** 10 * @var string 11 */ 12 protected $locale = ''; 13 14 /** 15 * @var string 16 */ 17 protected $previous_locale = ''; 18 19 public function setUp() { 20 $this->locale = ''; 21 $this->previous_locale = ''; 22 } 23 24 public function test_switch_to_non_existent_locale_returns_false() { 25 $this->assertTrue( ! switch_to_locale( 'foo_BAR' ) ); 26 } 27 28 public function test_switch_to_non_existent_locale_does_not_change_locale() { 29 switch_to_locale( 'foo_BAR' ); 30 31 $this->assertSame( 'en_US', get_locale() ); 32 } 33 34 public function test_switch_to_locale_returns_true() { 35 $expected = switch_to_locale( 'en_GB' ); 36 37 // Cleanup. 38 restore_previous_locale(); 39 40 $this->assertTrue( $expected ); 41 } 42 43 public function test_switch_to_locale_changes_the_locale() { 44 switch_to_locale( 'en_GB' ); 45 46 $locale = get_locale(); 47 48 // Cleanup. 49 restore_previous_locale(); 50 51 $this->assertSame( 'en_GB', $locale ); 52 } 53 54 public function test_switch_to_locale_loads_translation() { 55 switch_to_locale( 'es_ES' ); 56 57 $actual = __( 'Invalid parameter.' ); 58 59 // Cleanup. 60 restore_previous_locale(); 61 62 $this->assertSame( 'Parámetro no válido. ', $actual ); 63 } 64 65 public function test_switch_to_locale_changes_wp_locale_global() { 66 global $wp_locale; 67 68 $expected = array( 69 'thousands_sep' => '.', 70 'decimal_point' => ',', 71 ); 72 73 switch_to_locale( 'de_DE' ); 74 75 $wp_locale_de_DE = clone $wp_locale; 76 77 // Cleanup. 78 restore_previous_locale(); 79 80 $this->assertEqualSetsWithIndex( $expected, $wp_locale_de_DE->number_format ); 81 } 82 83 public function test_switch_to_locale_multiple_times() { 84 switch_to_locale( 'en_GB' ); 85 switch_to_locale( 'es_ES' ); 86 $locale = get_locale(); 87 88 // Cleanup. 89 restore_previous_locale(); 90 restore_previous_locale(); 91 92 $this->assertSame( 'es_ES', $locale ); 93 } 94 95 public function test_switch_to_locale_multiple_times_loads_translation() { 96 switch_to_locale( 'en_GB' ); 97 switch_to_locale( 'de_DE' ); 98 switch_to_locale( 'es_ES' ); 99 100 $actual = __( 'Invalid parameter.' ); 101 102 // Cleanup. 103 restore_previous_locale(); 104 restore_previous_locale(); 105 restore_previous_locale(); 106 107 $this->assertSame( 'Parámetro no válido. ', $actual ); 108 } 109 110 public function test_restore_previous_locale_without_switching() { 111 $this->assertTrue( ! restore_previous_locale() ); 112 } 113 114 public function test_restore_previous_locale_changes_the_locale_back() { 115 switch_to_locale( 'en_GB' ); 116 117 // Cleanup. 118 restore_previous_locale(); 119 120 $this->assertSame( 'en_US', get_locale() ); 121 } 122 123 public function test_restore_previous_locale_after_switching_multiple_times() { 124 switch_to_locale( 'en_GB' ); 125 switch_to_locale( 'es_ES' ); 126 restore_previous_locale(); 127 128 $locale = get_locale(); 129 130 // Cleanup. 131 restore_previous_locale(); 132 133 $this->assertSame( 'en_GB', $locale ); 134 } 135 136 public function test_restore_previous_locale_restores_translation() { 137 switch_to_locale( 'es_ES' ); 138 restore_previous_locale(); 139 140 $actual = __( 'Invalid parameter.' ); 141 142 $this->assertSame( 'Invalid parameter.', $actual ); 143 } 144 145 public function test_restore_previous_locale_action_passes_previous_locale() { 146 switch_to_locale( 'en_GB' ); 147 switch_to_locale( 'es_ES' ); 148 149 add_action( 'restore_previous_locale', array( $this, 'store_locale' ), 10, 2 ); 150 151 restore_previous_locale(); 152 153 $previous_locale = $this->previous_locale; 154 155 // Cleanup. 156 restore_previous_locale(); 157 158 $this->assertSame( 'es_ES', $previous_locale ); 159 } 160 161 public function test_restore_previous_locale_restores_wp_locale_global() { 162 global $wp_locale; 163 164 $expected = array( 165 'thousands_sep' => ',', 166 'decimal_point' => '.', 167 ); 168 169 switch_to_locale( 'de_DE' ); 170 restore_previous_locale(); 171 172 $this->assertEqualSetsWithIndex( $expected, $wp_locale->number_format ); 173 } 174 175 public function test_restore_current_locale_without_switching() { 176 $this->assertTrue( ! restore_current_locale() ); 177 } 178 179 public function test_restore_current_locale_after_switching_multiple_times() { 180 switch_to_locale( 'en_GB' ); 181 switch_to_locale( 'nl_NL' ); 182 switch_to_locale( 'es_ES' ); 183 184 restore_current_locale(); 185 186 $this->assertSame( 'en_US', get_locale() ); 187 } 188 189 public function store_locale( $locale, $previous_locale ) { 190 $this->locale = $locale; 191 $this->previous_locale = $previous_locale; 192 } 193 194 public function test_is_locale_switched_if_not_switched() { 195 $this->assertTrue( ! is_locale_switched() ); 196 } 197 198 public function test_is_locale_switched_original_locale() { 199 $original_locale = get_locale(); 200 201 switch_to_locale( 'en_GB' ); 202 switch_to_locale( $original_locale ); 203 204 $is_locale_switched = is_locale_switched(); 205 206 restore_current_locale(); 207 208 $this->assertTrue( $is_locale_switched ); 209 } 210 211 public function test_is_locale_switched() { 212 switch_to_locale( 'en_GB' ); 213 switch_to_locale( 'nl_NL' ); 214 215 $is_locale_switched = is_locale_switched(); 216 217 restore_current_locale(); 218 219 $this->assertTrue( $is_locale_switched ); 220 } 221 } -
tests/phpunit/tests/locale.php
diff --git tests/phpunit/tests/locale.php tests/phpunit/tests/locale.php index 1c335f4..79372d6 100644
1 1 <?php 2 2 3 3 /** 4 * @group l ocale4 * @group l10n 5 5 * @group i18n 6 6 */ 7 7 class Tests_Locale extends WP_UnitTestCase {