Changeset 39169
- Timestamp:
- 11/08/2016 11:00:38 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/user.php
r38705 r39169 99 99 if ( isset( $_POST['locale'] ) ) { 100 100 $locale = sanitize_text_field( $_POST['locale'] ); 101 if ( ! in_array( $locale, get_available_languages(), true )) {101 if ( 'site-default' === $locale ) { 102 102 $locale = ''; 103 } elseif ( ! in_array( $locale, get_available_languages(), true ) ) { 104 $locale = 'en_US'; 103 105 } 104 106 105 $user->locale = ( '' === $locale ) ? 'en_US' :$locale;107 $user->locale = $locale; 106 108 } 107 109 } -
trunk/src/wp-admin/user-edit.php
r39040 r39169 285 285 286 286 if ( 'en_US' === $user_locale ) { 287 $user_locale = false;288 } elseif ( ! in_array( $user_locale, $languages, true ) ) {289 $user_locale = get_locale();287 $user_locale = ''; 288 } elseif ( '' === $user_locale || ! in_array( $user_locale, $languages, true ) ) { 289 $user_locale = 'site-default'; 290 290 } 291 291 … … 295 295 'selected' => $user_locale, 296 296 'languages' => $languages, 297 'show_available_translations' => false 297 'show_available_translations' => false, 298 'show_site_locale_default' => true 298 299 ) ); 299 300 ?> -
trunk/src/wp-includes/l10n.php
r39134 r39169 1049 1049 * @since 4.0.0 1050 1050 * @since 4.3.0 Introduced the `echo` argument. 1051 * @since 4.7.0 Introduced the `show_site_locale_default` argument. 1051 1052 * 1052 1053 * @see get_available_languages() … … 1066 1067 * boolean equivalents. Default 1. 1067 1068 * @type bool $show_available_translations Whether to show available translations. Default true. 1069 * @type bool $show_site_locale_default Whether to show an option to fall back to the site's locale. Default false. 1068 1070 * } 1069 1071 * @return string HTML content … … 1079 1081 'echo' => 1, 1080 1082 'show_available_translations' => true, 1083 'show_site_locale_default' => false, 1081 1084 ) ); 1085 1086 // English (United States) uses an empty string for the value attribute. 1087 if ( 'en_US' === $args['selected'] ) { 1088 $args['selected'] = ''; 1089 } 1082 1090 1083 1091 $translations = $args['translations']; … … 1123 1131 $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">'; 1124 1132 } 1125 $structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>'; 1133 1134 if ( $args['show_site_locale_default'] ) { 1135 $structure[] = sprintf( 1136 '<option value="site-default" data-installed="1"%s>%s</option>', 1137 selected( 'site-default', $args['selected'], false ), 1138 _x( 'Site Default', 'default site language' ) 1139 ); 1140 } 1141 1142 $structure[] = sprintf( 1143 '<option value="" lang="en" data-installed="1"%s>English (United States)</option>', 1144 selected( '', $args['selected'], false ) 1145 ); 1146 1126 1147 foreach ( $languages as $language ) { 1127 1148 $structure[] = sprintf( -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r39126 r39169 1075 1075 'description' => __( 'Locale for the resource.' ), 1076 1076 'type' => 'string', 1077 'enum' => array_merge( array( ' en_US' ), get_available_languages() ),1077 'enum' => array_merge( array( '', 'en_US' ), get_available_languages() ), 1078 1078 'context' => array( 'edit' ), 1079 1079 ), -
trunk/tests/phpunit/tests/l10n.php
r39125 r39169 101 101 102 102 /** 103 * @ticket 38632 104 */ 105 function test_wp_dropdown_languages_site_default() { 106 $args = array( 107 'id' => 'foo', 108 'name' => 'bar', 109 'languages' => array( 'de_DE' ), 110 'translations' => $this->wp_dropdown_languages_filter(), 111 'selected' => 'de_DE', 112 'echo' => false, 113 'show_site_locale_default' => true, 114 ); 115 $actual = wp_dropdown_languages( $args ); 116 117 $this->assertContains( 'id="foo"', $actual ); 118 $this->assertContains( 'name="bar"', $actual ); 119 $this->assertContains( '<option value="site-default" data-installed="1">Site Default</option>', $actual ); 120 $this->assertContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual ); 121 $this->assertContains( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual ); 122 $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual ); 123 } 124 125 /** 126 * @ticket 38632 127 */ 128 function test_wp_dropdown_languages_en_US_selected() { 129 $args = array( 130 'id' => 'foo', 131 'name' => 'bar', 132 'languages' => array( 'de_DE' ), 133 'translations' => $this->wp_dropdown_languages_filter(), 134 'selected' => 'en_US', 135 'echo' => false, 136 ); 137 $actual = wp_dropdown_languages( $args ); 138 139 $this->assertContains( 'id="foo"', $actual ); 140 $this->assertContains( 'name="bar"', $actual ); 141 $this->assertContains( '<option value="" lang="en" data-installed="1" selected=\'selected\'>English (United States)</option>', $actual ); 142 $this->assertContains( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual ); 143 $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual ); 144 } 145 146 /** 103 147 * We don't want to call the API when testing. 104 148 * -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r39126 r39169 878 878 $user = get_userdata( $user_id ); 879 879 $this->assertEquals( 'en_US', $user->locale ); 880 } 881 882 /** 883 * @ticket 38632 884 */ 885 public function test_update_item_empty_locale() { 886 $user_id = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', 'locale' => 'de_DE' ) ); 887 $this->allow_user_to_manage_multisite(); 888 wp_set_current_user( self::$user ); 889 890 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user_id ); 891 $request->set_param( 'locale', '' ); 892 $response = $this->server->dispatch( $request ); 893 $this->check_add_edit_user_response( $response, true ); 894 895 $data = $response->get_data(); 896 $this->assertEquals( get_locale(), $data['locale'] ); 897 $user = get_userdata( $user_id ); 898 $this->assertEquals( '', $user->locale ); 880 899 } 881 900
Note: See TracChangeset
for help on using the changeset viewer.