Changeset 38275 for trunk/src/wp-includes/class-wp-user.php
- Timestamp:
- 08/18/2016 06:20:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user.php
r37985 r38275 103 103 104 104 /** 105 * @since 4.7.0 106 * @access protected 107 * @var wpdb 108 */ 109 protected $db; 110 111 /** 105 112 * Constructor. 106 113 * … … 109 116 * @since 2.0.0 110 117 * @access public 111 *112 * @global wpdb $wpdb WordPress database abstraction object.113 118 * 114 119 * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB. … … 117 122 */ 118 123 public function __construct( $id = 0, $name = '', $blog_id = '' ) { 124 $this->db = $GLOBALS['wpdb']; 125 119 126 if ( ! isset( self::$back_compat_keys ) ) { 120 $prefix = $ GLOBALS['wpdb']->prefix;127 $prefix = $this->db->prefix; 121 128 self::$back_compat_keys = array( 122 129 'user_firstname' => 'first_name', … … 233 240 234 241 if ( !$user = $wpdb->get_row( $wpdb->prepare( 235 "SELECT * FROM $wpdb->usersWHERE $db_field = %s", $value236 ) ) ) 242 "SELECT * FROM {$wpdb->users} WHERE $db_field = %s", $value 243 ) ) ) { 237 244 return false; 238 245 } 239 246 update_user_caches( $user ); 240 247 … … 443 450 * @since 2.1.0 444 451 * 445 * @global wpdb $wpdb WordPress database abstraction object.446 *447 452 * @param string $cap_key Optional capability key 448 453 */ 449 454 protected function _init_caps( $cap_key = '' ) { 450 global $wpdb; 451 452 if ( empty($cap_key) ) 453 $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; 454 else 455 if ( empty( $cap_key ) ) { 456 $this->cap_key = $this->db->get_blog_prefix() . 'capabilities'; 457 } else { 455 458 $this->cap_key = $cap_key; 456 459 } 457 460 $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); 458 461 … … 632 635 * @since 2.0.0 633 636 * @access public 634 *635 * @global wpdb $wpdb WordPress database abstraction object.636 637 */ 637 638 public function update_user_level_from_caps() { 638 global $wpdb;639 639 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 ); 640 update_user_meta( $this->ID, $ wpdb->get_blog_prefix() . 'user_level', $this->user_level );640 update_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level', $this->user_level ); 641 641 } 642 642 … … 680 680 * @since 2.1.0 681 681 * @access public 682 *683 * @global wpdb $wpdb WordPress database abstraction object.684 682 */ 685 683 public function remove_all_caps() { 686 global $wpdb;687 684 $this->caps = array(); 688 685 delete_user_meta( $this->ID, $this->cap_key ); 689 delete_user_meta( $this->ID, $ wpdb->get_blog_prefix() . 'user_level' );686 delete_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level' ); 690 687 $this->get_role_caps(); 691 688 } … … 773 770 * @since 3.0.0 774 771 * 775 * @global wpdb $wpdb WordPress database abstraction object.776 *777 772 * @param int $blog_id Optional. Site ID, defaults to current site. 778 773 */ 779 774 public function for_blog( $blog_id = '' ) { 780 global $wpdb; 781 if ( ! empty( $blog_id ) ) 782 $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; 783 else 775 if ( ! empty( $blog_id ) ) { 776 $cap_key = $this->db->get_blog_prefix( $blog_id ) . 'capabilities'; 777 } else { 784 778 $cap_key = ''; 779 } 785 780 $this->_init_caps( $cap_key ); 786 781 }
Note: See TracChangeset
for help on using the changeset viewer.