- }
-
- function add_role($role, $display_name, $capabilities = array()) {
- if ( isset($this->roles[$role]) )
- return;
-
- $this->roles[$role] = array(
- 'name' => $display_name,
- 'capabilities' => $capabilities);
- if ( $this->use_db )
- update_option($this->role_key, $this->roles);
- $this->role_objects[$role] = new WP_Role($role, $capabilities);
- $this->role_names[$role] = $display_name;
- return $this->role_objects[$role];
- }
-
- function remove_role($role) {
- if ( ! isset($this->role_objects[$role]) )
- return;
-
- unset($this->role_objects[$role]);
- unset($this->role_names[$role]);
- unset($this->roles[$role]);
-
- if ( $this->use_db )
- update_option($this->role_key, $this->roles);
- }
-
- function add_cap($role, $cap, $grant = true) {
- $this->roles[$role]['capabilities'][$cap] = $grant;
- if ( $this->use_db )
- update_option($this->role_key, $this->roles);
- }
-
- function remove_cap($role, $cap) {
- unset($this->roles[$role]['capabilities'][$cap]);
- if ( $this->use_db )
- update_option($this->role_key, $this->roles);
- }
-
- function &get_role($role) {
- if ( isset($this->role_objects[$role]) )
- return $this->role_objects[$role];
- else
- return null;
- }
-
- function get_names() {
- return $this->role_names;
- }
-
- function is_role($role)
- {
- return isset($this->role_names[$role]);
- }
-}
-
-class WP_Role {
- var $name;
- var $capabilities;
-
- function WP_Role($role, $capabilities) {
- $this->name = $role;
- $this->capabilities = $capabilities;
- }
-
- 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);
- }
-
- 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);
- }
-
- function has_cap($cap) {
- $capabilities = apply_filters('role_has_cap', $this->capabilities, $cap, $this->name);
- if ( !empty($capabilities[$cap]) )
- return $capabilities[$cap];
- else
- return false;
- }
-
-}
-
-class WP_User {
- var $data;
- var $ID = 0;
- var $id = 0; // Deprecated, use $ID instead.
- var $caps = array();
- var $cap_key;
- var $roles = array();
- var $allcaps = array();
-
- function WP_User($id, $name = '') {