WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 7 months ago

#39295 new enhancement

Prevent infinite loop when calling get_user_locale() in a 'locale' filter

Reported by: yoavf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 4.7
Component: I18N Keywords: has-patch
Focuses: Cc:
PR Number:

Description

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
        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.

Attachments (1)

39295.diff (1.4 KB) - added by yoavf 3 years ago.

Download all attachments as: .zip

Change History (1)

@yoavf
3 years ago

Note: See TracTickets for help on using tickets.