Ticket #39295: 39295.2.diff
File 39295.2.diff, 1.7 KB (added by , 4 years ago) |
---|
-
src/wp-includes/l10n.php
101 101 $user = get_user_by( 'id', $user_id ); 102 102 } 103 103 104 if ( ! $user ) { 105 return get_locale(); 104 if ( $user && $user->locale ) { 105 $locale = $user->locale; 106 } elseif ( doing_filter( 'locale' ) ) { 107 _doing_it_wrong( 108 __FUNCTION__, 109 /* translators: %s: 'locale' filter name. */ 110 sprintf( __( 'It cannot be used on the %s filter.' ), '<code>locale</code>' ), 111 '5.6.0' 112 ); 113 } else { 114 $locale = get_locale(); 106 115 } 107 116 108 $locale = $user->locale; 109 return $locale ? $locale : get_locale(); 117 if ( empty( $locale ) ) { 118 $locale = 'en_US'; 119 } 120 121 return $locale; 110 122 } 111 123 112 124 /** -
tests/phpunit/tests/l10n/getUserLocale.php
136 136 $user_locale = get_user_locale( 'string' ); 137 137 $this->assertSame( get_locale(), $user_locale ); 138 138 } 139 140 /** 141 * @ticket 39295 142 */ 143 public function test_get_user_locale_as_locale_filter_triggers_doing_it_wrong() { 144 wp_set_current_user( 0 ); 145 switch_to_locale( 'de_DE'); 146 147 $user_locale1 = get_user_locale(); 148 149 add_filter( 'locale', 'get_user_locale' ); 150 151 $this->setExpectedIncorrectUsage( 'get_user_locale' ); 152 $user_locale2 = get_user_locale(); 153 154 remove_filter( 'locale', 'get_user_locale' ); 155 156 restore_current_locale(); 157 158 $this->assertSame( 'de_DE', $user_locale1 ); 159 $this->assertSame( 'en_US', $user_locale2 ); 160 } 139 161 }