WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/26/2016 09:15:22 PM (3 years ago)
Author:
wonderboymusic
Message:

Roles: set a property, $db, on WP_Roles to reduce global imports.

See #37699.

File:
1 edited

Legend:

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

    r37431 r38387  
    7171
    7272    /**
     73     * @since 4.7.0
     74     * @access protected
     75     * @var wpdb
     76     */
     77    protected $db;
     78
     79    /**
    7380     * Constructor
    7481     *
     
    7683     */
    7784    public function __construct() {
     85        $this->db = $GLOBALS['wpdb'];
     86
    7887        $this->_init();
    7988    }
     
    106115     * @access protected
    107116     *
    108      * @global wpdb  $wpdb          WordPress database abstraction object.
    109117     * @global array $wp_user_roles Used to set the 'roles' property value.
    110118     */
    111119    protected function _init() {
    112         global $wpdb, $wp_user_roles;
    113         $this->role_key = $wpdb->get_blog_prefix() . 'user_roles';
     120        global $wp_user_roles;
     121        $this->role_key = $this->db->get_blog_prefix() . 'user_roles';
    114122        if ( ! empty( $wp_user_roles ) ) {
    115123            $this->roles = $wp_user_roles;
     
    138146     * @since 3.5.0
    139147     * @access public
    140      *
    141      * @global wpdb $wpdb WordPress database abstraction object.
    142148     */
    143149    public function reinit() {
    144150        // There is no need to reinit if using the wp_user_roles global.
    145         if ( ! $this->use_db )
    146             return;
    147 
    148         global $wpdb;
     151        if ( ! $this->use_db ) {
     152            return;
     153        }
    149154
    150155        // Duplicated from _init() to avoid an extra function call.
    151         $this->role_key = $wpdb->get_blog_prefix() . 'user_roles';
     156        $this->role_key = $this->db->get_blog_prefix() . 'user_roles';
    152157        $this->roles = get_option( $this->role_key );
    153158        if ( empty( $this->roles ) )
Note: See TracChangeset for help on using the changeset viewer.