[wp-trac] [WordPress Trac] #58001: Lazy load user capabilities in WP_User object
WordPress Trac
noreply at wordpress.org
Thu Oct 9 21:06:29 UTC 2025
#58001: Lazy load user capabilities in WP_User object
----------------------------------+-------------------------------------
Reporter: spacedmonkey | Owner: flixos90
Type: enhancement | Status: reopened
Priority: normal | Milestone: 6.9
Component: Users | Version:
Severity: normal | Resolution:
Keywords: early needs-dev-note | Focuses: multisite, performance
----------------------------------+-------------------------------------
Changes (by spacedmonkey):
* keywords: has-patch has-unit-tests early => early needs-dev-note
Comment:
> Reopening because I think we must fix the WP_User::to_array() behavior.
@TimothyBlynJacobs I am not sure what you mean here. `WP_User::to_array()`
looks like this
{{{#!php
public function to_array() {
return get_object_vars( $this->data );
}
}}}
This is what that method returns before and after
Before
{{{#!php
array(12) {
["ID"]=>
string(1) "2"
["user_login"]=>
string(10) "themedemos"
["user_pass"]=>
string(34) "$P$BfSW/JC68W63cqm4GB5iv2YXDDGGAY1"
["user_nicename"]=>
string(10) "themedemos"
["user_email"]=>
string(29) "themeshaperwp+demos at gmail.com"
["user_url"]=>
string(0) ""
["user_registered"]=>
string(19) "2024-11-12 22:19:43"
["user_activation_key"]=>
string(0) ""
["user_status"]=>
string(1) "0"
["display_name"]=>
string(12) "Theme Buster"
["spam"]=>
string(1) "0"
["deleted"]=>
string(1) "0"
}
}}}
After
{{{#!php
array(12) {
["ID"]=>
string(1) "2"
["user_login"]=>
string(10) "themedemos"
["user_pass"]=>
string(34) "$P$BfSW/JC68W63cqm4GB5iv2YXDDGGAY1"
["user_nicename"]=>
string(10) "themedemos"
["user_email"]=>
string(29) "themeshaperwp+demos at gmail.com"
["user_url"]=>
string(0) ""
["user_registered"]=>
string(19) "2024-11-12 22:19:43"
["user_activation_key"]=>
string(0) ""
["user_status"]=>
string(1) "0"
["display_name"]=>
string(12) "Theme Buster"
["spam"]=>
string(1) "0"
["deleted"]=>
string(1) "0"
}
}}}
I don't see caps, roles, and allcaps keys in either array, so I don't see
the breakable here.
> I also ran into a case in our code where we were modifying keys in the
allcaps array, though that type of behavior is probably specifically what
the change is trying to gate, so no concerns on that point.
I used a magic setter, so this should work. @bradshawtm you mind testing?
As for get_object_vars, this was considered, but it feels super edge case,
that you would use that function and get those properties, I maybe wrong.
Adding needs dev note, as this change might effect third party code.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58001#comment:41>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list