[wp-trac] [WordPress Trac] #63427: User roles property should always be an array, but they sometimes become an object in localized data
WordPress Trac
noreply at wordpress.org
Tue Nov 11 12:51:18 UTC 2025
#63427: User roles property should always be an array, but they sometimes become an
object in localized data
-------------------------------------------------+-------------------------
Reporter: haruncpi | Owner:
| SergeyBiryukov
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 6.9
Component: Users | Version: 2.0
Severity: normal | Resolution: fixed
Keywords: has-patch has-test-info has-unit- | Focuses:
tests commit |
-------------------------------------------------+-------------------------
Changes (by SergeyBiryukov):
* status: reviewing => closed
* resolution: => fixed
Comment:
In [changeset:"61210" 61210]:
{{{
#!CommitTicketReference repository="" revision="61210"
Users: Initialize the `WP_User::$roles` property as a sequential array.
Previously, if any roles were filtered out via `array_filter()` when
assigning the `WP_User::$roles` property in `WP_User::get_role_caps()`,
the resulting array could contain non-sequential numeric keys, which would
then cause it to be treated as an object when JSON-encoded, e.g. in
`wp_localize_script()`, instead of a proper array, breaking client-side
expectations.
This commit ensures that the `WP_User::$roles` property is always treated
as an array.
Follow-up to [2703], [2793], [22118].
Props haruncpi, peterwilsoncc, SirLouen, getsyash, wildworks,
johnjamesjacoby, SergeyBiryukov.
Fixes #63427.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63427#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list