[wp-trac] [WordPress Trac] #39295: Prevent infinite loop when calling get_user_locale() in a 'locale' filter

WordPress Trac noreply at wordpress.org
Sun Sep 27 17:06:57 UTC 2020


#39295: Prevent infinite loop when calling get_user_locale() in a 'locale' filter
-------------------------+------------------------------
 Reporter:  yoavf        |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  I18N         |     Version:  4.7
 Severity:  major        |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------------

Comment (by SergeyBiryukov):

 [attachment:"39295.2.diff"] is a refresh that follows the approach of
 [attachment:"39295.2.diff"] with some improvements:
 * Simplified logic for consistency with `get_locale()`.
 * Moved the filter name out of the translatable string.
 * The test performs the assertions after restoring the current locale, to
 avoid affecting other tests in case of failure.

 [attachment:"39295.2.alt.diff"] is an alternative patch that just makes
 `add_filter( 'locale', 'get_user_locale' )` work as expected, without the
 `_doing_it_wrong()` message, by using the existing `$locale` global as a
 fallback to avoid the infinite loop. Perhaps that could be the preferred
 fix here?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/39295#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list