[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
Sun Jun 15 13:30:06 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: reviewing
Priority: normal | Milestone: 6.9
Component: Users | Version: 2.0
Severity: normal | Resolution:
Keywords: has-patch has-test-info has-unit- | Focuses:
tests 2nd-opinion |
-------------------------------------------------+-------------------------
Comment (by haruncpi):
Replying to [comment:11 SirLouen]:
> Still I have the question:
>
> @haruncpi why you don't simply preprocess the resulting json into an
array, before delivering it to `wp_localize_script`?
>
> This not sequential order has been for ages, and I'm not sure if it's a
bug or just something expected. After checking the history of this
function, this has been there for easily 15+ years (since WP 1.6 when they
introduced `array_keys`). Not saying that everything old is correct, but
I'm still trying to find an useful reason.
Thanks for the question!
The issue isn’t really about whether this behavior has existed since early
WordPress versions. It likely wasn’t noticed, triggered, or was often
preprocessed by developers before reaching wp_localize_script.
However, delivering correct, consistent data directly from core is always
the better approach. It ensures data integrity at the source and removes
the need for extra preprocessing by developers. This makes the data safer
and more predictable for all use cases.
Additionally, the process is now optimized to linear time, preventing
potential cubic complexity.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63427#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list