Roles: set a property, `$db`, on `WP_Roles` to reduce global imports.
See #37699. Built from https://develop.svn.wordpress.org/trunk@38387 git-svn-id: http://core.svn.wordpress.org/trunk@38328 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b9f516e55e
commit
35bdc07eac
|
@ -69,12 +69,21 @@ class WP_Roles {
|
|||
*/
|
||||
public $use_db = true;
|
||||
|
||||
/**
|
||||
* @since 4.7.0
|
||||
* @access protected
|
||||
* @var wpdb
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->db = $GLOBALS['wpdb'];
|
||||
|
||||
$this->_init();
|
||||
}
|
||||
|
||||
|
@ -105,12 +114,11 @@ class WP_Roles {
|
|||
* @since 2.1.0
|
||||
* @access protected
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
* @global array $wp_user_roles Used to set the 'roles' property value.
|
||||
*/
|
||||
protected function _init() {
|
||||
global $wpdb, $wp_user_roles;
|
||||
$this->role_key = $wpdb->get_blog_prefix() . 'user_roles';
|
||||
global $wp_user_roles;
|
||||
$this->role_key = $this->db->get_blog_prefix() . 'user_roles';
|
||||
if ( ! empty( $wp_user_roles ) ) {
|
||||
$this->roles = $wp_user_roles;
|
||||
$this->use_db = false;
|
||||
|
@ -137,18 +145,15 @@ class WP_Roles {
|
|||
*
|
||||
* @since 3.5.0
|
||||
* @access public
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*/
|
||||
public function reinit() {
|
||||
// There is no need to reinit if using the wp_user_roles global.
|
||||
if ( ! $this->use_db )
|
||||
if ( ! $this->use_db ) {
|
||||
return;
|
||||
|
||||
global $wpdb;
|
||||
}
|
||||
|
||||
// Duplicated from _init() to avoid an extra function call.
|
||||
$this->role_key = $wpdb->get_blog_prefix() . 'user_roles';
|
||||
$this->role_key = $this->db->get_blog_prefix() . 'user_roles';
|
||||
$this->roles = get_option( $this->role_key );
|
||||
if ( empty( $this->roles ) )
|
||||
return;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.7-alpha-38386';
|
||||
$wp_version = '4.7-alpha-38387';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue