Coding Standards: Rename the `$user_id` parameter of `get_user_locale()` to `$user` for accuracy.
Since the parameter accepts not only a user's ID, but also a `WP_User` object, `$user` is a more appropriate name, which better aligns with the `$post` parameter of functions that accept a post ID or a `WP_Post` object. The pre-existing internal `$user` variable which contained a `WP_User` object is renamed to `$user_object` for clarity. Follow-up to [38955]. Props aristath, poena, afercia, SergeyBiryukov. See #55647. Built from https://develop.svn.wordpress.org/trunk@53702 git-svn-id: http://core.svn.wordpress.org/trunk@53261 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ccba239e04
commit
0eb9abd1fe
|
@ -88,24 +88,26 @@ function get_locale() {
|
|||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param int|WP_User $user_id User's ID or a WP_User object. Defaults to current user.
|
||||
* @param int|WP_User $user User's ID or a WP_User object. Defaults to current user.
|
||||
* @return string The locale of the user.
|
||||
*/
|
||||
function get_user_locale( $user_id = 0 ) {
|
||||
$user = false;
|
||||
if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
|
||||
$user = wp_get_current_user();
|
||||
} elseif ( $user_id instanceof WP_User ) {
|
||||
$user = $user_id;
|
||||
} elseif ( $user_id && is_numeric( $user_id ) ) {
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
function get_user_locale( $user = 0 ) {
|
||||
$user_object = false;
|
||||
|
||||
if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) {
|
||||
$user_object = wp_get_current_user();
|
||||
} elseif ( $user instanceof WP_User ) {
|
||||
$user_object = $user;
|
||||
} elseif ( $user && is_numeric( $user ) ) {
|
||||
$user_object = get_user_by( 'id', $user );
|
||||
}
|
||||
|
||||
if ( ! $user ) {
|
||||
if ( ! $user_object ) {
|
||||
return get_locale();
|
||||
}
|
||||
|
||||
$locale = $user->locale;
|
||||
$locale = $user_object->locale;
|
||||
|
||||
return $locale ? $locale : get_locale();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-alpha-53701';
|
||||
$wp_version = '6.1-alpha-53702';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue