Make WordPress Core

Changeset 53702


Ignore:
Timestamp:
07/15/2022 01:43:51 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r53691 r53702  
    8989 * @since 4.7.0
    9090 *
    91  * @param int|WP_User $user_id User's ID or a WP_User object. Defaults to current user.
     91 * @param int|WP_User $user User's ID or a WP_User object. Defaults to current user.
    9292 * @return string The locale of the user.
    9393 */
    94 function get_user_locale( $user_id = 0 ) {
    95     $user = false;
    96     if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
    97         $user = wp_get_current_user();
    98     } elseif ( $user_id instanceof WP_User ) {
    99         $user = $user_id;
    100     } elseif ( $user_id && is_numeric( $user_id ) ) {
    101         $user = get_user_by( 'id', $user_id );
    102     }
    103 
    104     if ( ! $user ) {
     94function get_user_locale( $user = 0 ) {
     95    $user_object = false;
     96
     97    if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) {
     98        $user_object = wp_get_current_user();
     99    } elseif ( $user instanceof WP_User ) {
     100        $user_object = $user;
     101    } elseif ( $user && is_numeric( $user ) ) {
     102        $user_object = get_user_by( 'id', $user );
     103    }
     104
     105    if ( ! $user_object ) {
    105106        return get_locale();
    106107    }
    107108
    108     $locale = $user->locale;
     109    $locale = $user_object->locale;
     110
    109111    return $locale ? $locale : get_locale();
    110112}
Note: See TracChangeset for help on using the changeset viewer.