Changeset 61037 for trunk/src/wp-includes/class-wp-user.php
- Timestamp:
- 10/21/2025 03:23:43 PM (3 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-user.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user.php
r60915 r61037 38 38 * @property string $syntax_highlighting 39 39 * @property string $use_ssl 40 * @property array<string, bool> $caps41 * @property string[] $roles42 * @property array<string, bool> $allcaps43 40 */ 44 41 #[AllowDynamicProperties] … … 64 61 * 65 62 * @since 2.0.0 66 * @var array<string, bool>|nullArray of key/value pairs where keys represent a capability name67 * and boolean values represent whether the user has that capability.68 */ 69 p rotected $caps = null;63 * @var bool[] Array of key/value pairs where keys represent a capability name 64 * and boolean values represent whether the user has that capability. 65 */ 66 public $caps = array(); 70 67 71 68 /** … … 83 80 * @var string[] 84 81 */ 85 p rotected$roles = array();82 public $roles = array(); 86 83 87 84 /** … … 89 86 * 90 87 * @since 2.0.0 91 * @var array<string, bool>Array of key/value pairs where keys represent a capability name92 * and boolean values represent whether the user has that capability.93 */ 94 p rotected$allcaps = array();88 * @var bool[] Array of key/value pairs where keys represent a capability name 89 * and boolean values represent whether the user has that capability. 90 */ 91 public $allcaps = array(); 95 92 96 93 /** … … 292 289 } 293 290 294 if ( in_array( $key, array( 'caps', 'allcaps', 'roles' ), true ) ) {295 return true;296 }297 298 291 if ( isset( $this->data->$key ) ) { 299 292 return true; … … 327 320 ); 328 321 return $this->ID; 329 }330 331 if ( in_array( $key, array( 'caps', 'allcaps', 'roles' ), true ) ) {332 $this->load_capability_data();333 return $this->$key;334 322 } 335 323 … … 376 364 } 377 365 378 // Ensure capability data is loaded before setting related properties.379 if ( in_array( $key, array( 'caps', 'allcaps', 'roles' ), true ) ) {380 $this->load_capability_data();381 $this->$key = $value;382 return;383 }384 385 366 $this->data->$key = $value; 386 367 } … … 406 387 } 407 388 408 if ( in_array( $key, array( 'caps', 'allcaps', 'roles' ), true ) ) {409 $this->$key = null;410 }411 412 389 if ( isset( $this->data->$key ) ) { 413 390 unset( $this->data->$key ); … … 538 515 539 516 $wp_roles = wp_roles(); 540 541 // Edge case: In case someone calls this method before lazy initialization, we need to initialize on demand.542 if ( ! isset( $this->caps ) ) {543 $this->caps = $this->get_caps_data();544 }545 517 546 518 // Filter out caps that are not role names and assign to $this->roles. … … 577 549 return; 578 550 } 579 $this->load_capability_data();580 551 581 552 if ( in_array( $role, $this->roles, true ) ) { … … 607 578 */ 608 579 public function remove_role( $role ) { 609 $this->load_capability_data();610 580 if ( ! in_array( $role, $this->roles, true ) ) { 611 581 return; … … 640 610 */ 641 611 public function set_role( $role ) { 642 $this->load_capability_data();643 612 if ( 1 === count( $this->roles ) && current( $this->roles ) === $role ) { 644 613 return; … … 742 711 */ 743 712 public function add_cap( $cap, $grant = true ) { 744 $this->load_capability_data();745 713 $this->caps[ $cap ] = $grant; 746 714 update_user_meta( $this->ID, $this->cap_key, $this->caps ); … … 757 725 */ 758 726 public function remove_cap( $cap ) { 759 $this->load_capability_data();760 727 if ( ! isset( $this->caps[ $cap ] ) ) { 761 728 return; … … 776 743 public function remove_all_caps() { 777 744 global $wpdb; 778 $this->caps = null;745 $this->caps = array(); 779 746 delete_user_meta( $this->ID, $this->cap_key ); 780 747 delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' ); 781 $this-> load_capability_data();748 $this->get_role_caps(); 782 749 } 783 750 … … 810 777 */ 811 778 public function has_cap( $cap, ...$args ) { 812 $this->load_capability_data();813 814 779 if ( is_numeric( $cap ) ) { 815 780 _deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) ); … … 913 878 914 879 $this->cap_key = $wpdb->get_blog_prefix( $this->site_id ) . 'capabilities'; 915 $this->caps = null; 880 881 $this->caps = $this->get_caps_data(); 882 883 $this->get_role_caps(); 916 884 } 917 885 … … 944 912 return $caps; 945 913 } 946 947 /**948 * Loads capability data if it has not been loaded yet.949 *950 * @since 6.9.0951 */952 private function load_capability_data() {953 if ( isset( $this->caps ) ) {954 return;955 }956 $this->caps = $this->get_caps_data();957 $this->get_role_caps();958 }959 914 }
Note: See TracChangeset
for help on using the changeset viewer.