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:
Scott Taylor 2016-08-26 21:16:59 +00:00
parent b9f516e55e
commit 35bdc07eac
2 changed files with 15 additions and 10 deletions

View File

@ -69,12 +69,21 @@ class WP_Roles {
*/ */
public $use_db = true; public $use_db = true;
/**
* @since 4.7.0
* @access protected
* @var wpdb
*/
protected $db;
/** /**
* Constructor * Constructor
* *
* @since 2.0.0 * @since 2.0.0
*/ */
public function __construct() { public function __construct() {
$this->db = $GLOBALS['wpdb'];
$this->_init(); $this->_init();
} }
@ -105,12 +114,11 @@ class WP_Roles {
* @since 2.1.0 * @since 2.1.0
* @access protected * @access protected
* *
* @global wpdb $wpdb WordPress database abstraction object.
* @global array $wp_user_roles Used to set the 'roles' property value. * @global array $wp_user_roles Used to set the 'roles' property value.
*/ */
protected function _init() { protected function _init() {
global $wpdb, $wp_user_roles; global $wp_user_roles;
$this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; $this->role_key = $this->db->get_blog_prefix() . 'user_roles';
if ( ! empty( $wp_user_roles ) ) { if ( ! empty( $wp_user_roles ) ) {
$this->roles = $wp_user_roles; $this->roles = $wp_user_roles;
$this->use_db = false; $this->use_db = false;
@ -137,18 +145,15 @@ class WP_Roles {
* *
* @since 3.5.0 * @since 3.5.0
* @access public * @access public
*
* @global wpdb $wpdb WordPress database abstraction object.
*/ */
public function reinit() { public function reinit() {
// There is no need to reinit if using the wp_user_roles global. // There is no need to reinit if using the wp_user_roles global.
if ( ! $this->use_db ) if ( ! $this->use_db ) {
return; return;
}
global $wpdb;
// Duplicated from _init() to avoid an extra function call. // 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 ); $this->roles = get_option( $this->role_key );
if ( empty( $this->roles ) ) if ( empty( $this->roles ) )
return; return;

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.