Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#38578 closed defect (bug) (fixed)

`locale` is not a per-site user-option, but rather a global user attribute

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by: ocean90's profile ocean90
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.7
Component: I18N Keywords: has-patch
Focuses: Cc:

Description

In user-edit.php we're using get_user_option() to get a user's locale. This seems incorrect.

  • It's the only user setting doing this in this file.
  • User locale's are not per-site (get_user_option() isn't specific for this, but it's *mostly* implied IMO.)
  • We already have $profileuser which is a WP_User object, so we can rely on the magic getter to gather this meta.
  • We could also use get_user_locale(), but since user-edit.php does it's own juggle against the results of get_available_languages() I think get_user_locale() includes unnecessary overhead.
  • _get_additional_user_keys() includes locale as a global piece of meta (not as a per-site option) which I think confirms my thoughts.

See: #29783.

Attachments (1)

38578.diff (380 bytes) - added by johnjamesjacoby 8 years ago.

Download all attachments as: .zip

Change History (5)

#1 @johnjamesjacoby
8 years ago

Also, wp_insert_user() sets the locale user meta using update_user_meta(). It's never saved as a per-site user option, so I don't think get_user_option() is the correct approach in this instance.

The bug here, to be clear, is if there was somehow a wp_2_locale key in wp_usermeta (maybe from a plugin?) it would be what appears as selected in the dropdown... but when the user is updated, it would update the locale key, which is what everything else uses.

#2 @ocean90
8 years ago

Looks like a leftover from my initial patch.

Note that get_user_option() checks first if a site specific meta exists and then falls back to the global attribute.

#3 @ocean90
8 years ago

  • Owner set to ocean90
  • Resolution set to fixed
  • Status changed from new to closed

In 39040:

I18N: Don't use get_user_option() for retrieving user's language.

get_user_option() checks for both option types, site and network. Since locale is only a network option we can directly access the field via WP_Users magic getter.

Props johnjamesjacoby.
Fixes #38578.

#4 @johnjamesjacoby
8 years ago

Thanks again @ocean90. ✌️

Note: See TracTickets for help on using tickets.