Fix for wrong locale code in the admin for core/get-site-info` ability#11492
Fix for wrong locale code in the admin for core/get-site-info` ability#11492sangu310 wants to merge 2 commits intoWordPress:trunkfrom
Conversation
|
Hi @sangu310! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
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.