Spiffier role creation code.

git-svn-id: http://svn.automattic.com/wordpress/trunk@2898 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-09-20 23:48:28 +00:00
parent 196c1920ed
commit 22fb57c5c6
2 changed files with 91 additions and 96 deletions

View File

@ -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,
'moderate_comments' => true,
'manage_categories' => true,
'manage_links' => true,
'upload_files' => true,
'manage_options' => true,
'switch_themes' => true,
'edit_themes' => true,
'activate_plugins' => true,
'edit_plugins' => true,
'edit_users' => true,
'edit_files' => true,
'unfiltered_html' => true,
'import' => true,
'read' => true,
'level_10' => true,
'level_9' => true,
'level_8' => true,
'level_7' => true,
'level_6' => true,
'level_5' => true,
'level_4' => true,
'level_3' => true,
'level_2' => true,
'level_1' => true,
'level_0' => true
)),
'editor' => // Add caps for Administrator role
array('name' => __('Editor'), $role = $wp_roles->get_role('administrator');
'capabilities' => array( $role->add_cap('switch_themes');
'edit_posts' => true, $role->add_cap('edit_themes');
'edit_others_posts' => true, $role->add_cap('activate_plugins');
'edit_published_posts' => true, $role->add_cap('edit_plugins');
'publish_posts' => true, $role->add_cap('edit_users');
'edit_pages' => true, $role->add_cap('edit_files');
'moderate_comments' => true, $role->add_cap('manage_options');
'manage_categories' => true, $role->add_cap('moderate_comments');
'manage_links' => true, $role->add_cap('manage_categories');
'upload_files' => true, $role->add_cap('manage_links');
'unfiltered_html' => true, $role->add_cap('upload_files');
'read' => true, $role->add_cap('import');
'level_7' => true, $role->add_cap('unfiltered_html');
'level_6' => true, $role->add_cap('edit_posts');
'level_5' => true, $role->add_cap('edit_others_posts');
'level_4' => true, $role->add_cap('edit_published_posts');
'level_3' => true, $role->add_cap('publish_posts');
'level_2' => true, $role->add_cap('edit_pages');
'level_1' => true, $role->add_cap('read');
'level_0' => true $role->add_cap('level_10');
)), $role->add_cap('level_9');
$role->add_cap('level_8');
$role->add_cap('level_7');
$role->add_cap('level_6');
$role->add_cap('level_6');
$role->add_cap('level_4');
$role->add_cap('level_3');
$role->add_cap('level_2');
$role->add_cap('level_1');
$role->add_cap('level_0');
'author' => // Add caps for Editor role
array('name' => __('Author'), $role = $wp_roles->get_role('editor');
'capabilities' => array( $role->add_cap('moderate_comments');
'edit_posts' => true, $role->add_cap('manage_categories');
'publish_posts' => true, $role->add_cap('manage_links');
'upload_files' => true, $role->add_cap('upload_files');
'read' => true, $role->add_cap('unfiltered_html');
'level_2' => true, $role->add_cap('edit_posts');
'level_1' => true, $role->add_cap('edit_others_posts');
'level_0' => true $role->add_cap('edit_published_posts');
)), $role->add_cap('publish_posts');
$role->add_cap('edit_pages');
$role->add_cap('read');
$role->add_cap('level_7');
$role->add_cap('level_6');
$role->add_cap('level_6');
$role->add_cap('level_4');
$role->add_cap('level_3');
$role->add_cap('level_2');
$role->add_cap('level_1');
$role->add_cap('level_0');
'contributor' => // Add caps for Author role
array('name' => __('Contributor'), $role = $wp_roles->get_role('author');
'capabilities' => array( $role->add_cap('upload_files');
'edit_posts' => true, $role->add_cap('edit_posts');
'read' => 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');
'subscriber' => // Add caps for Contributor role
array('name' => __('Subscriber'), $role = $wp_roles->get_role('contributor');
'capabilities' => array( $role->add_cap('edit_posts');
'read' => true, $role->add_cap('read');
'level_0' => true $role->add_cap('level_1');
)) $role->add_cap('level_0');
);
// FIXME: Temporary code to reset roles and caps if flag is set. // Add caps for Subscriber role
if ( defined('RESET_CAPS') ) $role = $wp_roles->get_role('subscriber');
update_option($table_prefix . 'user_roles', $roles); $role->add_cap('read');
else $role->add_cap('level_0');
add_option($table_prefix . 'user_roles', $roles);
} }
?> ?>

View File

@ -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;