[wp-trac] [WordPress Trac] #58001: Lazy load user capabilities in WP_User object

WordPress Trac noreply at wordpress.org
Wed Oct 15 20:36:52 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
----------------------------------+-------------------------------------

Comment (by spacedmonkey):

 I have looked into this.

 We could use the `JsonSerializable` interface and the `jsonSerialize`
 method, to make sure that json_encode continues to work.

 {{{#!php
    public function jsonSerialize() {
         $this->load_capability_data();
         return array(
             'data'    => $this->data,
             'ID'      => $this->ID,
             'caps'    => $this->caps,
             'cap_key' => $this->cap_key,
             'roles'   => $this->roles,
             'allcaps' => $this->allcaps,
             'filter'  => $this->filter,
             'site_id' => $this->site_id,
         );
     }

 }}}

 We can also add `__serialize` method, to handle the `serialize` use case
 in PHP 7.4+.

 Still working on a fix for `get_object_vars`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58001#comment:47>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list