wp_roles cleanup.
git-svn-id: http://svn.automattic.com/wordpress/trunk@3452 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2514ca2bc7
commit
515892d7ab
|
@ -85,6 +85,9 @@ class WP_Role {
|
||||||
function add_cap($cap, $grant = true) {
|
function add_cap($cap, $grant = true) {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
|
|
||||||
|
if ( ! isset($wp_roles) )
|
||||||
|
$wp_roles = new WP_Roles();
|
||||||
|
|
||||||
$this->capabilities[$cap] = $grant;
|
$this->capabilities[$cap] = $grant;
|
||||||
$wp_roles->add_cap($this->name, $cap, $grant);
|
$wp_roles->add_cap($this->name, $cap, $grant);
|
||||||
}
|
}
|
||||||
|
@ -92,6 +95,9 @@ class WP_Role {
|
||||||
function remove_cap($cap) {
|
function remove_cap($cap) {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
|
|
||||||
|
if ( ! isset($wp_roles) )
|
||||||
|
$wp_roles = new WP_Roles();
|
||||||
|
|
||||||
unset($this->capabilities[$cap]);
|
unset($this->capabilities[$cap]);
|
||||||
$wp_roles->remove_cap($this->name, $cap);
|
$wp_roles->remove_cap($this->name, $cap);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +121,7 @@ class WP_User {
|
||||||
var $allcaps = array();
|
var $allcaps = array();
|
||||||
|
|
||||||
function WP_User($id, $name = '') {
|
function WP_User($id, $name = '') {
|
||||||
global $wp_roles, $table_prefix;
|
global $table_prefix;
|
||||||
|
|
||||||
if ( empty($id) && empty($name) )
|
if ( empty($id) && empty($name) )
|
||||||
return;
|
return;
|
||||||
|
@ -147,6 +153,10 @@ class WP_User {
|
||||||
|
|
||||||
function get_role_caps() {
|
function get_role_caps() {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
|
|
||||||
|
if ( ! isset($wp_roles) )
|
||||||
|
$wp_roles = new WP_Roles();
|
||||||
|
|
||||||
//Filter out caps that are not role names and assign to $this->roles
|
//Filter out caps that are not role names and assign to $this->roles
|
||||||
if(is_array($this->caps))
|
if(is_array($this->caps))
|
||||||
$this->roles = array_filter(array_keys($this->caps), array(&$wp_roles, 'is_role'));
|
$this->roles = array_filter(array_keys($this->caps), array(&$wp_roles, 'is_role'));
|
||||||
|
@ -214,8 +224,6 @@ class WP_User {
|
||||||
//has_cap(capability_or_role_name) or
|
//has_cap(capability_or_role_name) or
|
||||||
//has_cap('edit_post', post_id)
|
//has_cap('edit_post', post_id)
|
||||||
function has_cap($cap) {
|
function has_cap($cap) {
|
||||||
global $wp_roles;
|
|
||||||
|
|
||||||
if ( is_numeric($cap) )
|
if ( is_numeric($cap) )
|
||||||
$cap = $this->translate_level_to_cap($cap);
|
$cap = $this->translate_level_to_cap($cap);
|
||||||
|
|
||||||
|
@ -316,18 +324,27 @@ function current_user_can($capability) {
|
||||||
function get_role($role) {
|
function get_role($role) {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
|
|
||||||
|
if ( ! isset($wp_roles) )
|
||||||
|
$wp_roles = new WP_Roles();
|
||||||
|
|
||||||
return $wp_roles->get_role($role);
|
return $wp_roles->get_role($role);
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_role($role, $display_name, $capabilities = '') {
|
function add_role($role, $display_name, $capabilities = '') {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
|
|
||||||
|
if ( ! isset($wp_roles) )
|
||||||
|
$wp_roles = new WP_Roles();
|
||||||
|
|
||||||
return $wp_roles->add_role($role, $display_name, $capabilities = '');
|
return $wp_roles->add_role($role, $display_name, $capabilities = '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_role($role) {
|
function remove_role($role) {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
|
|
||||||
|
if ( ! isset($wp_roles) )
|
||||||
|
$wp_roles = new WP_Roles();
|
||||||
|
|
||||||
return $wp_roles->remove_role($role);
|
return $wp_roles->remove_role($role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,6 @@ $_SERVER = add_magic_quotes($_SERVER);
|
||||||
$wp_query = new WP_Query();
|
$wp_query = new WP_Query();
|
||||||
$wp_rewrite = new WP_Rewrite();
|
$wp_rewrite = new WP_Rewrite();
|
||||||
$wp = new WP();
|
$wp = new WP();
|
||||||
$wp_roles = new WP_Roles();
|
|
||||||
|
|
||||||
define('TEMPLATEPATH', get_template_directory());
|
define('TEMPLATEPATH', get_template_directory());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue