General: Restore usage of $wpdb, instead of $this->db.

Hiding the `$wpdb` global behind a property decreases the readability of the code, as well as causing irrelevant output when dumping an object.

Reverts [38275], [38278], [38279], [38280], [38387].
See #37699.


Built from https://develop.svn.wordpress.org/trunk@38768


git-svn-id: http://core.svn.wordpress.org/trunk@38711 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast
2016-10-10 06:38:31 +00:00
parent 2064e34833
commit af69f4ab1a
13 changed files with 402 additions and 371 deletions

View File

@@ -103,13 +103,6 @@ class WP_User {
*/
private static $back_compat_keys;
/**
* @since 4.7.0
* @access protected
* @var wpdb
*/
protected $db;
/**
* Constructor.
*
@@ -118,15 +111,15 @@ class WP_User {
* @since 2.0.0
* @access public
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB.
* @param string $name Optional. User's username
* @param int $blog_id Optional Site ID, defaults to current site.
*/
public function __construct( $id = 0, $name = '', $blog_id = '' ) {
$this->db = $GLOBALS['wpdb'];
if ( ! isset( self::$back_compat_keys ) ) {
$prefix = $this->db->prefix;
$prefix = $GLOBALS['wpdb']->prefix;
self::$back_compat_keys = array(
'user_firstname' => 'first_name',
'user_lastname' => 'last_name',
@@ -241,10 +234,10 @@ class WP_User {
}
if ( !$user = $wpdb->get_row( $wpdb->prepare(
"SELECT * FROM {$wpdb->users} WHERE $db_field = %s", $value
) ) ) {
"SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
) ) )
return false;
}
update_user_caches( $user );
return $user;
@@ -451,14 +444,18 @@ class WP_User {
* @access protected
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $cap_key Optional capability key
*/
protected function _init_caps( $cap_key = '' ) {
if ( empty( $cap_key ) ) {
$this->cap_key = $this->db->get_blog_prefix() . 'capabilities';
} else {
global $wpdb;
if ( empty($cap_key) )
$this->cap_key = $wpdb->get_blog_prefix() . 'capabilities';
else
$this->cap_key = $cap_key;
}
$this->caps = get_user_meta( $this->ID, $this->cap_key, true );
if ( ! is_array( $this->caps ) )
@@ -636,10 +633,13 @@ class WP_User {
*
* @since 2.0.0
* @access public
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
public function update_user_level_from_caps() {
global $wpdb;
$this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 );
update_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level', $this->user_level );
update_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level', $this->user_level );
}
/**
@@ -681,11 +681,14 @@ class WP_User {
*
* @since 2.1.0
* @access public
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
public function remove_all_caps() {
global $wpdb;
$this->caps = array();
delete_user_meta( $this->ID, $this->cap_key );
delete_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level' );
delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' );
$this->get_role_caps();
}
@@ -771,14 +774,16 @@ class WP_User {
*
* @since 3.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $blog_id Optional. Site ID, defaults to current site.
*/
public function for_blog( $blog_id = '' ) {
if ( ! empty( $blog_id ) ) {
$cap_key = $this->db->get_blog_prefix( $blog_id ) . 'capabilities';
} else {
global $wpdb;
if ( ! empty( $blog_id ) )
$cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
else
$cap_key = '';
}
$this->_init_caps( $cap_key );
}
}