[wp-trac] [WordPress Trac] #64977: The `core/get-site-info` ability returns wrong locale code in the admin
WordPress Trac
noreply at wordpress.org
Sun Mar 29 15:17:44 UTC 2026
#64977: The `core/get-site-info` ability returns wrong locale code in the admin
--------------------------+------------------------------
Reporter: afercia | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: AI | Version: 6.9
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Description changed by afercia:
Old description:
> Besides other site data, the `core/get-site-info` ability is supposed to
> return `The site language locale code`.
>
> I would expect that to be the site language locale.
> However, in the admin it returns the _user_locale which may not the same
> of the site locale.
>
> Under the hood, the ability callback uses `get_bloginfo()`.
>
> That doesn't seem to be the right tool to retrieve the _site_ language
> locale code. In fact, `get_bloginfo()`:
> - can be passed a different language code by translators
> - internally uses `determine_locale()` which uses some logic that may
> return different results depending on (roughly):
> - whether the page is the login page
> - whether is an admin or whether there are some get parameters related
> to user and locale _and_ it's a json request: in this case it returns the
> _user_locale
> - other logic based on whether there is a 'language' request parameter
> or is installing
> - finally fallbacks to `get_locale()` which returns the _site_ locale
>
> It is also worth considering what the ability should return in a
> multisite installation.
>
> To reproduce:
> - In WP Admin > Settings > General, set the Site Language to a language
> other than english e.g. Italian.
> - In WP Admin > Users > Profile, set the Language to a different language
> e.g. Spanish.
> - Place the following snippet in a template that outputs on the front
> end:
>
> {{{
> $ability = wp_get_ability( 'core/get-site-info' );
> $result = $ability->execute();
> var_dump( $result['language'] );
> }}}
>
> - Observe it returns `string(5) "it-IT"`, which is the expected site
> locale.
> - Place the same snippet into some admin page for example in `options-
> general.php`.
> - Observe it returns `string(2) "es"` which is not the expected locale.
> Actually, this is the _user_ locale.
> - Worth checking what is returned in a REST API call. As far as I see the
> returned language is correct. Tested with:
>
> {{{
> curl -X GET "http://localhost:8889/wp-json/wp-abilities/v1/abilities/core
> /get-site-info/run" \
> -u "your-username:your-generated-application-password" \
> -H "Content-Type: application/json"
> }}}
New description:
Besides other site data, the `core/get-site-info` ability is supposed to
return `The site language locale code`.
I would expect that to be the site language locale.
However, in the admin it returns the _user_locale which may not the same
of the site locale.
Under the hood, the ability callback uses `get_bloginfo()`.
That doesn't seem to be the right tool to retrieve the _site_ language
locale code. In fact, `get_bloginfo()`:
- can be passed a different language code by translators
- internally uses `determine_locale()` which uses some logic that may
return different results depending on (roughly):
- whether the page is the login page
- whether is an admin or whether there are some get parameters related
to user and locale _and_ it's a json request: in this case it returns the
_user_locale
- other logic based on whether there is a 'language' request parameter
or is installing
- finally fallbacks to `get_locale()` which returns the _site_ locale
It is also worth considering what the ability should return in a multisite
installation.
To reproduce:
- In WP Admin > Settings > General, set the Site Language to a language
other than english e.g. Italian.
- In WP Admin > Users > Profile, set the Language to a different language
e.g. Spanish.
- Place the following snippet in a template that outputs on the front end:
{{{
$ability = wp_get_ability( 'core/get-site-info' );
$result = $ability->execute();
var_dump( $result['language'] );
}}}
- Observe it returns `string(5) "it-IT"`, which is the expected site
locale.
- Place the same snippet into some admin page for example in `options-
general.php`.
- Observe it returns `string(2) "es"` which is not the expected locale.
Actually, this is the _user_ locale.
- Worth checking what is returned in a REST API call. As far as I see the
returned language is correct. Tested with:
{{{
curl -X GET "http://localhost:8889/wp-json/wp-abilities/v1/abilities/core
/get-site-info/run" \
-u "your-username:your-generated-application-password" \
-H "Content-Type: application/json"
}}}
Introduced in https://core.trac.wordpress.org/changeset/61063/
See https://core.trac.wordpress.org/ticket/64146
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64977#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list