Allow use of global roles array instead of options db. Useful for multi-blog setups.
git-svn-id: http://svn.automattic.com/wordpress/trunk@4113 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
207d876c81
commit
182bc141e2
|
@ -6,6 +6,7 @@ class WP_Roles {
|
||||||
var $role_objects = array();
|
var $role_objects = array();
|
||||||
var $role_names = array();
|
var $role_names = array();
|
||||||
var $role_key;
|
var $role_key;
|
||||||
|
var $use_db = true;
|
||||||
|
|
||||||
function WP_Roles() {
|
function WP_Roles() {
|
||||||
$this->_init();
|
$this->_init();
|
||||||
|
@ -13,9 +14,14 @@ class WP_Roles {
|
||||||
|
|
||||||
function _init () {
|
function _init () {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
global $wp_user_roles;
|
||||||
$this->role_key = $wpdb->prefix . 'user_roles';
|
$this->role_key = $wpdb->prefix . 'user_roles';
|
||||||
|
if ( ! empty($wp_user_roles) ) {
|
||||||
|
$this->roles = $wp_user_roles;
|
||||||
|
$this->use_db = false;
|
||||||
|
} else {
|
||||||
$this->roles = get_option($this->role_key);
|
$this->roles = get_option($this->role_key);
|
||||||
|
}
|
||||||
|
|
||||||
if ( empty($this->roles) )
|
if ( empty($this->roles) )
|
||||||
return;
|
return;
|
||||||
|
@ -35,6 +41,7 @@ class WP_Roles {
|
||||||
$this->roles[$role] = array(
|
$this->roles[$role] = array(
|
||||||
'name' => $display_name,
|
'name' => $display_name,
|
||||||
'capabilities' => $capabilities);
|
'capabilities' => $capabilities);
|
||||||
|
if ( $this->use_db )
|
||||||
update_option($this->role_key, $this->roles);
|
update_option($this->role_key, $this->roles);
|
||||||
$this->role_objects[$role] = new WP_Role($role, $capabilities);
|
$this->role_objects[$role] = new WP_Role($role, $capabilities);
|
||||||
$this->role_names[$role] = $display_name;
|
$this->role_names[$role] = $display_name;
|
||||||
|
@ -49,16 +56,19 @@ class WP_Roles {
|
||||||
unset($this->role_names[$role]);
|
unset($this->role_names[$role]);
|
||||||
unset($this->roles[$role]);
|
unset($this->roles[$role]);
|
||||||
|
|
||||||
|
if ( $this->use_db )
|
||||||
update_option($this->role_key, $this->roles);
|
update_option($this->role_key, $this->roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_cap($role, $cap, $grant = true) {
|
function add_cap($role, $cap, $grant = true) {
|
||||||
$this->roles[$role]['capabilities'][$cap] = $grant;
|
$this->roles[$role]['capabilities'][$cap] = $grant;
|
||||||
|
if ( $this->use_db )
|
||||||
update_option($this->role_key, $this->roles);
|
update_option($this->role_key, $this->roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_cap($role, $cap) {
|
function remove_cap($role, $cap) {
|
||||||
unset($this->roles[$role]['capabilities'][$cap]);
|
unset($this->roles[$role]['capabilities'][$cap]);
|
||||||
|
if ( $this->use_db )
|
||||||
update_option($this->role_key, $this->roles);
|
update_option($this->role_key, $this->roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue