Spiffier role creation code.
git-svn-id: http://svn.automattic.com/wordpress/trunk@2898 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
196c1920ed
commit
22fb57c5c6
|
@ -237,99 +237,91 @@ function populate_options() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function populate_roles() {
|
function populate_roles() {
|
||||||
global $table_prefix;
|
global $wp_roles;
|
||||||
|
|
||||||
$roles = array ('administrator' =>
|
// Add roles
|
||||||
array('name' => __('Administrator'),
|
$wp_roles->add_role('administrator', __('Administrator'));
|
||||||
'capabilities' => array(
|
$wp_roles->add_role('editor', __('Editor'));
|
||||||
'edit_posts' => true,
|
$wp_roles->add_role('author', __('Author'));
|
||||||
'edit_others_posts' => true,
|
$wp_roles->add_role('contributor', __('Contributor'));
|
||||||
'edit_published_posts' => true,
|
$wp_roles->add_role('subscriber', __('Subscriber'));
|
||||||
'publish_posts' => true,
|
|
||||||
'edit_pages' => true,
|
// Add caps for Administrator role
|
||||||
'moderate_comments' => true,
|
$role = $wp_roles->get_role('administrator');
|
||||||
'manage_categories' => true,
|
$role->add_cap('switch_themes');
|
||||||
'manage_links' => true,
|
$role->add_cap('edit_themes');
|
||||||
'upload_files' => true,
|
$role->add_cap('activate_plugins');
|
||||||
'manage_options' => true,
|
$role->add_cap('edit_plugins');
|
||||||
'switch_themes' => true,
|
$role->add_cap('edit_users');
|
||||||
'edit_themes' => true,
|
$role->add_cap('edit_files');
|
||||||
'activate_plugins' => true,
|
$role->add_cap('manage_options');
|
||||||
'edit_plugins' => true,
|
$role->add_cap('moderate_comments');
|
||||||
'edit_users' => true,
|
$role->add_cap('manage_categories');
|
||||||
'edit_files' => true,
|
$role->add_cap('manage_links');
|
||||||
'unfiltered_html' => true,
|
$role->add_cap('upload_files');
|
||||||
'import' => true,
|
$role->add_cap('import');
|
||||||
'read' => true,
|
$role->add_cap('unfiltered_html');
|
||||||
'level_10' => true,
|
$role->add_cap('edit_posts');
|
||||||
'level_9' => true,
|
$role->add_cap('edit_others_posts');
|
||||||
'level_8' => true,
|
$role->add_cap('edit_published_posts');
|
||||||
'level_7' => true,
|
$role->add_cap('publish_posts');
|
||||||
'level_6' => true,
|
$role->add_cap('edit_pages');
|
||||||
'level_5' => true,
|
$role->add_cap('read');
|
||||||
'level_4' => true,
|
$role->add_cap('level_10');
|
||||||
'level_3' => true,
|
$role->add_cap('level_9');
|
||||||
'level_2' => true,
|
$role->add_cap('level_8');
|
||||||
'level_1' => true,
|
$role->add_cap('level_7');
|
||||||
'level_0' => true
|
$role->add_cap('level_6');
|
||||||
)),
|
$role->add_cap('level_6');
|
||||||
|
$role->add_cap('level_4');
|
||||||
'editor' =>
|
$role->add_cap('level_3');
|
||||||
array('name' => __('Editor'),
|
$role->add_cap('level_2');
|
||||||
'capabilities' => array(
|
$role->add_cap('level_1');
|
||||||
'edit_posts' => true,
|
$role->add_cap('level_0');
|
||||||
'edit_others_posts' => true,
|
|
||||||
'edit_published_posts' => true,
|
// Add caps for Editor role
|
||||||
'publish_posts' => true,
|
$role = $wp_roles->get_role('editor');
|
||||||
'edit_pages' => true,
|
$role->add_cap('moderate_comments');
|
||||||
'moderate_comments' => true,
|
$role->add_cap('manage_categories');
|
||||||
'manage_categories' => true,
|
$role->add_cap('manage_links');
|
||||||
'manage_links' => true,
|
$role->add_cap('upload_files');
|
||||||
'upload_files' => true,
|
$role->add_cap('unfiltered_html');
|
||||||
'unfiltered_html' => true,
|
$role->add_cap('edit_posts');
|
||||||
'read' => true,
|
$role->add_cap('edit_others_posts');
|
||||||
'level_7' => true,
|
$role->add_cap('edit_published_posts');
|
||||||
'level_6' => true,
|
$role->add_cap('publish_posts');
|
||||||
'level_5' => true,
|
$role->add_cap('edit_pages');
|
||||||
'level_4' => true,
|
$role->add_cap('read');
|
||||||
'level_3' => true,
|
$role->add_cap('level_7');
|
||||||
'level_2' => true,
|
$role->add_cap('level_6');
|
||||||
'level_1' => true,
|
$role->add_cap('level_6');
|
||||||
'level_0' => true
|
$role->add_cap('level_4');
|
||||||
)),
|
$role->add_cap('level_3');
|
||||||
|
$role->add_cap('level_2');
|
||||||
'author' =>
|
$role->add_cap('level_1');
|
||||||
array('name' => __('Author'),
|
$role->add_cap('level_0');
|
||||||
'capabilities' => array(
|
|
||||||
'edit_posts' => true,
|
// Add caps for Author role
|
||||||
'publish_posts' => true,
|
$role = $wp_roles->get_role('author');
|
||||||
'upload_files' => true,
|
$role->add_cap('upload_files');
|
||||||
'read' => true,
|
$role->add_cap('edit_posts');
|
||||||
'level_2' => true,
|
$role->add_cap('publish_posts');
|
||||||
'level_1' => true,
|
$role->add_cap('read');
|
||||||
'level_0' => true
|
$role->add_cap('level_2');
|
||||||
)),
|
$role->add_cap('level_1');
|
||||||
|
$role->add_cap('level_0');
|
||||||
'contributor' =>
|
|
||||||
array('name' => __('Contributor'),
|
// Add caps for Contributor role
|
||||||
'capabilities' => array(
|
$role = $wp_roles->get_role('contributor');
|
||||||
'edit_posts' => true,
|
$role->add_cap('edit_posts');
|
||||||
'read' => true,
|
$role->add_cap('read');
|
||||||
'level_1' => true,
|
$role->add_cap('level_1');
|
||||||
'level_0' => true
|
$role->add_cap('level_0');
|
||||||
)),
|
|
||||||
|
// Add caps for Subscriber role
|
||||||
'subscriber' =>
|
$role = $wp_roles->get_role('subscriber');
|
||||||
array('name' => __('Subscriber'),
|
$role->add_cap('read');
|
||||||
'capabilities' => array(
|
$role->add_cap('level_0');
|
||||||
'read' => true,
|
|
||||||
'level_0' => true
|
|
||||||
))
|
|
||||||
);
|
|
||||||
// FIXME: Temporary code to reset roles and caps if flag is set.
|
|
||||||
if ( defined('RESET_CAPS') )
|
|
||||||
update_option($table_prefix . 'user_roles', $roles);
|
|
||||||
else
|
|
||||||
add_option($table_prefix . 'user_roles', $roles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -22,7 +22,10 @@ class WP_Roles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_role($role, $capabilities, $display_name) {
|
function add_role($role, $display_name, $capabilities = '') {
|
||||||
|
if ( isset($this->roles[$role]) )
|
||||||
|
return;
|
||||||
|
|
||||||
$this->roles[$role] = array('name' => $display_name,
|
$this->roles[$role] = array('name' => $display_name,
|
||||||
'capabilities' => $capabilities);
|
'capabilities' => $capabilities);
|
||||||
update_option($this->role_key, $this->roles);
|
update_option($this->role_key, $this->roles);
|
||||||
|
@ -41,7 +44,7 @@ class WP_Roles {
|
||||||
update_option($this->role_key, $this->roles);
|
update_option($this->role_key, $this->roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_cap($role, $cap, $grant) {
|
function add_cap($role, $cap, $grant = true) {
|
||||||
$this->roles[$role]['capabilities'][$cap] = $grant;
|
$this->roles[$role]['capabilities'][$cap] = $grant;
|
||||||
update_option($this->role_key, $this->roles);
|
update_option($this->role_key, $this->roles);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +80,7 @@ class WP_Role {
|
||||||
$this->capabilities = $capabilities;
|
$this->capabilities = $capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_cap($cap, $grant) {
|
function add_cap($cap, $grant = true) {
|
||||||
global $wp_roles;
|
global $wp_roles;
|
||||||
|
|
||||||
$this->capabilities[$cap] = $grant;
|
$this->capabilities[$cap] = $grant;
|
||||||
|
|
Loading…
Reference in New Issue