diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 646c143d22..23e5344dc8 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -85,6 +85,9 @@ class WP_Role { function add_cap($cap, $grant = true) { global $wp_roles; + if ( ! isset($wp_roles) ) + $wp_roles = new WP_Roles(); + $this->capabilities[$cap] = $grant; $wp_roles->add_cap($this->name, $cap, $grant); } @@ -92,6 +95,9 @@ class WP_Role { function remove_cap($cap) { global $wp_roles; + if ( ! isset($wp_roles) ) + $wp_roles = new WP_Roles(); + unset($this->capabilities[$cap]); $wp_roles->remove_cap($this->name, $cap); } @@ -115,7 +121,7 @@ class WP_User { var $allcaps = array(); function WP_User($id, $name = '') { - global $wp_roles, $table_prefix; + global $table_prefix; if ( empty($id) && empty($name) ) return; @@ -147,6 +153,10 @@ class WP_User { function get_role_caps() { 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 if(is_array($this->caps)) $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('edit_post', post_id) function has_cap($cap) { - global $wp_roles; - if ( is_numeric($cap) ) $cap = $this->translate_level_to_cap($cap); @@ -316,18 +324,27 @@ function current_user_can($capability) { function get_role($role) { global $wp_roles; + if ( ! isset($wp_roles) ) + $wp_roles = new WP_Roles(); + return $wp_roles->get_role($role); } function add_role($role, $display_name, $capabilities = '') { global $wp_roles; + if ( ! isset($wp_roles) ) + $wp_roles = new WP_Roles(); + return $wp_roles->add_role($role, $display_name, $capabilities = ''); } function remove_role($role) { global $wp_roles; + if ( ! isset($wp_roles) ) + $wp_roles = new WP_Roles(); + return $wp_roles->remove_role($role); } diff --git a/wp-settings.php b/wp-settings.php index 8ebb1f4f0d..1ecfe389c8 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -206,7 +206,6 @@ $_SERVER = add_magic_quotes($_SERVER); $wp_query = new WP_Query(); $wp_rewrite = new WP_Rewrite(); $wp = new WP(); -$wp_roles = new WP_Roles(); define('TEMPLATEPATH', get_template_directory());