diff --git a/src/wp-includes/class-wp-user.php b/src/wp-includes/class-wp-user.php
index 6c2f3c1..a9d7f21 100644
|
a
|
b
|
class WP_User implements JsonSerializable {
|
| 64 | 64 | public $filter = null; |
| 65 | 65 | public $site_id = 0; |
| 66 | 66 | |
| | 67 | /** |
| | 68 | * Whether the user object was initialized in short mode. |
| | 69 | * |
| | 70 | * @since 7.0.0 |
| | 71 | * @var bool |
| | 72 | */ |
| | 73 | protected $short_init = false; |
| | 74 | |
| 67 | 75 | /** |
| 68 | 76 | * Constructor. |
| 69 | 77 | */ |
| … |
… |
class WP_User implements JsonSerializable { (this hunk was shorter than expected)
|
| 82 | 90 | |
| 83 | 91 | if ( is_array( $args ) && ! empty( $args['short_init'] ) ) { |
| 84 | 92 | $this->short_init = true; |
| | 93 | $this->roles = array(); |
| | 94 | $this->caps = array(); |
| | 95 | $this->allcaps = array(); |
| 85 | 96 | } |
| 86 | 97 | |
| 87 | 98 | if ( is_object( $id ) ) { |
| … |
… |
class WP_User implements JsonSerializable { (this hunk was shorter than expected)
|
| 135 | 147 | $this->ID = (int) $this->data->ID; |
| 136 | 148 | |
| 137 | 149 | if ( $this->short_init ) { |
| | 150 | // Defer loading of caps and roles. |
| 138 | 151 | return; |
| 139 | 152 | } |
| 140 | 153 | |
| 141 | 154 | $this->for_site(); |
| … |
… |
class WP_User implements JsonSerializable { (this hunk was shorter than expected)
|
| 159 | 175 | |
| 160 | 176 | public function for_site( $site_id = '' ) { |
| | 177 | if ( $this->short_init ) { |
| | 178 | return; |
| | 179 | } |
| | 180 | |
| 161 | 181 | if ( empty( $site_id ) ) { |
| 162 | 182 | $site_id = get_current_blog_id(); |
| 163 | 183 | } |
| … |
… |
class WP_User implements JsonSerializable { (this hunk was shorter than expected)
|
| 214 | 234 | } |
| 215 | 235 | |
| | 236 | /** |
| | 237 | * Lazily load capability data when accessed. |
| | 238 | */ |
| | 239 | protected function load_capability_data() { |
| | 240 | if ( ! empty( $this->allcaps ) ) { |
| | 241 | return; |
| | 242 | } |
| | 243 | |
| | 244 | $this->short_init = false; |
| | 245 | $this->for_site(); |
| | 246 | } |
| | 247 | |
| 216 | 248 | public function get_role_caps() { |
| 217 | 249 | global $wp_roles; |
| 218 | 250 | |
| … |
… |
class WP_User implements JsonSerializable { (this hunk was shorter than expected)
|
| 356 | 388 | */ |
| 357 | 389 | public function has_cap( $cap ) { |
| | 390 | $this->load_capability_data(); |
| 358 | 391 | $cap = map_meta_cap( $cap, $this->ID ); |
| 359 | 392 | $capabilities = apply_filters( 'user_has_cap', $this->allcaps, $cap, array() ); |
| … |
… |
class WP_User implements JsonSerializable {
|
| 553 | 586 | return $this->data; |
| 554 | 587 | } |
| 555 | 588 | |
| | 589 | /** |
| | 590 | * Ensure caps are available during JSON encoding. |
| | 591 | */ |
| | 592 | public function jsonSerialize() { |
| | 593 | $this->load_capability_data(); |
| | 594 | |
| | 595 | return array( |
| | 596 | 'ID' => $this->ID, |
| | 597 | 'roles' => $this->roles, |
| | 598 | 'caps' => $this->caps, |
| | 599 | 'allcaps' => $this->allcaps, |
| | 600 | 'data' => $this->data, |
| | 601 | ); |
| | 602 | } |
| | 603 | |
| | 604 | public function __serialize() { |
| | 605 | $this->load_capability_data(); |
| | 606 | return get_object_vars( $this ); |
| | 607 | } |
| 556 | 608 | } |