Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#45235 closed defect (bug) (fixed)

REST API: Setting _locale can cause fatal errors

Reported by: pento Owned by: danielbachhuber
Priority: high Milestone: 5.0
Component: I18N Version: 5.0
Severity: major Keywords:
Cc: Focuses: rest-api

Description

determine_locale() calls is_user_logged_in() when the _locale parameter is set in a REST API request.

However, is_user_logged_in() is a pluggable function, which loads after plugins do, so if any plugins call __() as soon as they're loaded, it will cause a fatal error.

Related: #44758, [43776].

Attachments (2)

45235.1.diff​ (583 bytes ) - added by danielbachhuber 8 years ago.
Check function_exists( 'is_user_logged_in' ) in case called before pluggable functions are loaded
45235.2.diff​ (518 bytes ) - added by danielbachhuber 8 years ago.
Avoid calling is_user_logged_in() entirely, as get_user_locale() handles the scenario

Download all attachments as: .zip

Change History (11)

#1 @matt
8 years ago

This plugin with 200k active sites triggers this bug: ​https://wordpress.org/plugins/ga-google-analytics/

(I ran into it on ma.tt today.)

#3 @danielbachhuber
8 years ago

#45227 was marked as a duplicate.

@danielbachhuber
8 years ago

Check function_exists( 'is_user_logged_in' ) in case called before pluggable functions are loaded

@danielbachhuber
8 years ago

Avoid calling is_user_logged_in() entirely, as get_user_locale() handles the scenario

#4 @danielbachhuber
8 years ago

  • Owner set to danielbachhuber
  • Resolution → fixed
  • Status new → closed

In 43846:

l10n: Avoid calling is_user_logged_in() in determine_locale().

is_user_logged_in() is a pluggable function, and loaded after plugins are loaded. If a plugin calls __() too early, is_user_logged_in() is missing and WordPress will fatal. get_user_locale() already handles this scenario for us, so it's safe to rely on exclusively.

See #44758.
Fixes #45235.

#5 @pento
8 years ago

I've rebuilt the 5.0 nightly to include this fix, anyone using the Beta Tester plugin to test 5.0 can just click the update button. 🙂

#6 @SergeyBiryukov
8 years ago

  • Keywords fixed-5.0 added; needs-patch removed
  • Resolution fixed
  • Status closed → reopened

Reopening for trunk.

#7 @danielbachhuber
8 years ago

@SergeyBiryukov FYI - the original ticket is still open, so I was planning to use that as the point of reference for backporting. We can keep this open too though, no worries.

#8 @SergeyBiryukov
8 years ago

  • Keywords fixed-5.0 removed
  • Resolution → fixed
  • Status reopened → closed

Ah, I missed that #44758 is still open.

Last edited 8 years ago by SergeyBiryukov (previous) (diff)

#9 @atimmer
8 years ago

In 44181:

l10n: Avoid calling is_user_logged_in() in determine_locale().

is_user_logged_in() is a pluggable function, and loaded after plugins are loaded. If a plugin calls () too early, is_user_logged_in() is missing and WordPress will fatal. get_user_locale() already handles this scenario for us, so it's safe to rely on exclusively.

Props danielbachhuber.
Merges [43846] to trunk.
See #44758.
Fixes #45235.

Note: See TracTickets for help on using tickets.