Fix for wrong locale code in the admin for core/get-site-info` ability#11498
Closed
sangu310 wants to merge 2 commits intoWordPress:trunkfrom
Closed
Fix for wrong locale code in the admin for core/get-site-info` ability#11498sangu310 wants to merge 2 commits intoWordPress:trunkfrom
sangu310 wants to merge 2 commits intoWordPress:trunkfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The core/get-site-info ability should return the site locale, but currently returns the user locale in admin due to using get_bloginfo(), which relies on determine_locale().
This can vary based on context (admin, login, request params, JSON requests), making it unreliable for getting the actual site locale.
The site's language is stored directly as the WPLANG option. Reading it bypasses all the context-dependent filtering:
if ( 'language' === $field ) {
$result[ $field ] = str_replace( '', '-', get_option( 'WPLANG' ) ?: 'en_US' );
}
get_option('WPLANG') returns the raw DB value — no context influence
The ?: 'en_US' handles the default English case where WPLANG is an empty string
str_replace('', '-', ...) preserves the existing BCP 47 formatting (e.g. en-US, pt-BR)
Multisite Behavior
In multisite, get_option() already scopes to the current site (it internally routes through get_blog_option()), so no special handling is needed. Each site in the network correctly returns its own configured language. If you ever needed the network-level language, that would be get_network_option(null, 'WPLANG'), but that's not appropriate for core/get-site-info.