As of WordPress 4.7, users are now able to define a custom language (i.e., locale). One immediate effect of this is that the WordPress back end is localized according to the user’s language.

Cool! So How Can I Disable That?

What if , for some irrelevant reason, you don’t like this new feature? Can this new User Admin Language feature be disabled?

Yes. Even though there is no setting for this, nor a dedicated filter switch, you can pretty much render the user admin language ineffective. And here’s how.

Overwrite the User Language With the Site Language

The user language is stored in a dedicated user meta (with locale being the according key). The default way of accessing a specific user’s locale, however, is either by using the new get_user_locale( $user_id ) function, or the locale property on a WP_User object.

The function simply looks up the locale property of the according user. And the property is initialized with the value of the user meta. So, all we have to do, is to manipulate the user meta value. 🙂

This can easily be done with the following code:

add_filter( 'get_user_metadata', function ( $value, $user_id, $meta_key ) {

    return ( 'locale' === $meta_key ) ? get_locale() : $value;
}, 10, 3 );

Whenever a user meta value is to be read—this shouldn’t happen too often, because these values are cached (when you don’t use a proper object cache, then at least for the current request)—we interfere only in case of the user locale, and simply return the site locale instead.

Remove the User Interface

Now that we disabled using the user language, we only have to disable setting it. We do this by removing the according field (or rather: the whole table row) on the Profile page.

Since there is no hook that we can leverage, we have to use JavaScript (which isn’t a problem in the WordPress back end).

This should do the trick:

add_action( 'admin_footer-profile.php', function () {

    document.addEventListener( 'DOMContentLoaded', () => {
        document.querySelector( 'tr.user-language-wrap' ).remove();
    } );
} );

We inject some (vanilla) JavaScript code to the footer of the Profile page, and only this page, and that’s it already.

What About Caching Then?

As mentioned before, a user’s locale is stored as meta value, but it is also cached inside the WP_User object. If you happen to use some sort of object cache, then this might result in several of your users still having a custom user language.

Since WordPress’s object cache interface class doesn’t allow for deleting individual groups, all you can do, if you really want to undo this, is flush the whole cache. 😐

Anything to Add?

Let me know in the comments. 🙂

One response to “Disable User Admin Language in WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *