[wp-trac] [WordPress Trac] #39295: Prevent infinite loop when calling get_user_locale() in a 'locale' filter
WordPress Trac
noreply at wordpress.org
Thu Dec 15 11:12:41 UTC 2016
#39295: Prevent infinite loop when calling get_user_locale() in a 'locale' filter
-------------------------+-----------------------------
Reporter: yoavf | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: 4.7
Severity: major | Keywords: has-patch
Focuses: |
-------------------------+-----------------------------
Using `get_user_locale()` in a `locale` filter (for `get_locale()`) might
sound like a good idea, for example to change the site locale depending on
our user.
{{{#!php
<?php
if ( $condition) {
add_filter( 'locale', 'get_user_locale' );
}
}}}
However, if one does that and a non-logged in user (or a user without a
`locale` value) visits the site, a infinite loop will be triggered, since
`get_user_locale()` will itself call `get_locale()` when no `user->locale`
value exists.
Since this only affects logged out users, it feels like an easy trap to
miss, and we should prevent that.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39295>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list