WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/10/2016 06:37:02 AM (4 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-user.php

    r38705 r38768  
    105105
    106106    /**
    107      * @since 4.7.0
    108      * @access protected
    109      * @var wpdb
    110      */
    111     protected $db;
    112 
    113     /**
    114107     * Constructor.
    115108     *
     
    118111     * @since 2.0.0
    119112     * @access public
     113     *
     114     * @global wpdb $wpdb WordPress database abstraction object.
    120115     *
    121116     * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB.
     
    124119     */
    125120    public function __construct( $id = 0, $name = '', $blog_id = '' ) {
    126         $this->db = $GLOBALS['wpdb'];
    127 
    128121        if ( ! isset( self::$back_compat_keys ) ) {
    129             $prefix = $this->db->prefix;
     122            $prefix = $GLOBALS['wpdb']->prefix;
    130123            self::$back_compat_keys = array(
    131124                'user_firstname' => 'first_name',
     
    242235
    243236        if ( !$user = $wpdb->get_row( $wpdb->prepare(
    244             "SELECT * FROM {$wpdb->users} WHERE $db_field = %s", $value
    245         ) ) ) {
     237            "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
     238        ) ) )
    246239            return false;
    247         }
     240
    248241        update_user_caches( $user );
    249242
     
    452445     * @since 2.1.0
    453446     *
     447     * @global wpdb $wpdb WordPress database abstraction object.
     448     *
    454449     * @param string $cap_key Optional capability key
    455450     */
    456451    protected function _init_caps( $cap_key = '' ) {
    457         if ( empty( $cap_key ) ) {
    458             $this->cap_key = $this->db->get_blog_prefix() . 'capabilities';
    459         } else {
     452        global $wpdb;
     453
     454        if ( empty($cap_key) )
     455            $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities';
     456        else
    460457            $this->cap_key = $cap_key;
    461         }
     458
    462459        $this->caps = get_user_meta( $this->ID, $this->cap_key, true );
    463460
     
    637634     * @since 2.0.0
    638635     * @access public
     636     *
     637     * @global wpdb $wpdb WordPress database abstraction object.
    639638     */
    640639    public function update_user_level_from_caps() {
     640        global $wpdb;
    641641        $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 );
    642         update_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level', $this->user_level );
     642        update_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level', $this->user_level );
    643643    }
    644644
     
    682682     * @since 2.1.0
    683683     * @access public
     684     *
     685     * @global wpdb $wpdb WordPress database abstraction object.
    684686     */
    685687    public function remove_all_caps() {
     688        global $wpdb;
    686689        $this->caps = array();
    687690        delete_user_meta( $this->ID, $this->cap_key );
    688         delete_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level' );
     691        delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' );
    689692        $this->get_role_caps();
    690693    }
     
    772775     * @since 3.0.0
    773776     *
     777     * @global wpdb $wpdb WordPress database abstraction object.
     778     *
    774779     * @param int $blog_id Optional. Site ID, defaults to current site.
    775780     */
    776781    public function for_blog( $blog_id = '' ) {
    777         if ( ! empty( $blog_id ) ) {
    778             $cap_key = $this->db->get_blog_prefix( $blog_id ) . 'capabilities';
    779         } else {
     782        global $wpdb;
     783        if ( ! empty( $blog_id ) )
     784            $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
     785        else
    780786            $cap_key = '';
    781         }
    782787        $this->_init_caps( $cap_key );
    783788    }
Note: See TracChangeset for help on using the changeset viewer.