Ticket #39295: 39295.diff
File 39295.diff, 1.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/l10n.php
96 96 $user = get_user_by( 'id', $user_id ); 97 97 } 98 98 99 if ( ! $user ) { 99 if ( ! $user || empty( $user->locale ) ) { 100 if ( doing_filter( 'locale' ) ) { 101 _doing_it_wrong( __FUNCTION__, __( "It can not be added as a 'locale' filter, or be called by a 'locale' filter." ), '4.7.1' ); 102 return 'en_US'; 103 } 104 100 105 return get_locale(); 101 106 } 102 107 103 $locale = $user->locale; 104 return $locale ? $locale : get_locale(); 108 return $user->locale; 105 109 } 106 110 107 111 /** -
tests/phpunit/tests/l10n/getUserLocale.php
127 127 $user_locale = get_user_locale( 'string' ); 128 128 $this->assertSame( get_locale(), $user_locale ); 129 129 } 130 131 public function test_get_user_locale_as_locale_filter_triggers_doing_it_wrong() { 132 wp_set_current_user( 0 ); 133 switch_to_locale( 'de_DE'); 134 $this->assertSame( 'de_DE', get_user_locale() ); 135 136 137 add_filter( 'locale', 'get_user_locale' ); 138 $this->setExpectedIncorrectUsage( 'get_user_locale' ); 139 $this->assertSame( 'en_US', get_user_locale() ); 140 remove_filter( 'locale', 'get_user_locale' ); 141 142 restore_current_locale(); 143 } 130 144 }