[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 14:28:25 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 SirLouen):
Replying to [comment:12 haruncpi]:
> 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.
I understand your concern which from my point of view is valid
I think that for this reason, its required to use the `maybe_unserialize`
WP function.
{{{
$current_user = wp_get_current_user();
$local_data = array(
'current_user' => array(
'id' => $current_user->ID,
'roles' => maybe_unserialize( $current_user->roles ),
),
);
wp_localize_script( 'myplugin-frontend', '_myplugin_object', $local_data
);
}}}
Probably due to this kind of issues all over the code.
Still I agree with you that this could/should be fixed to provide a more
consistent data and also now I feel that with a simplified complexity (not
from cubic, but cuadratic because original there were only two
iterations), now becomes linear so it also provides some performance
improvement.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63427#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list