你好@NetConstructor:
我想这就是你需要的。请注意,我没有包括您的\'website_owner\'
角色,只需添加一个名为\'manage_administrators\'
.
此外,我只尝试从没有\'manage_administrators\'
功能(当然,您需要将其添加到管理员角色中),我还简单地在“添加新用户”页面上删除了管理员作为角色选项。我没有试图确保他们不能通过一些邪恶的方法删除或添加管理员,也没有禁用任何其他允许他们添加或删除管理员的功能。也就是说,也许这就足够了?
add_action(\'user_row_actions\',\'yoursite_user_row_actions\',10,2);
function yoursite_user_row_actions($actions, $user_object) { // remove the ability to delete an administrator
global $pagenow;
if ($pagenow==\'users.php\' && isset($user_object->caps[\'administrator\']) && !current_user_can(\'manage_administrators\'))
unset($actions[\'edit\']);
unset($actions[\'delete\']);
return $actions;
}
add_action(\'editable_roles\',\'yoursite_editable_roles\');
function yoursite_editable_roles($all_roles) { // remove the ability to add an administrator
global $pagenow;
if (in_array($pagenow,array(\'user-edit.php\',\'user-new.php\')) &&
!current_user_can(\'manage_administrators\'))
unset($all_roles[\'administrator\']);
return $all_roles;
}
add_action(\'admin_init\',\'yoursite_admin_init\');
function yoursite_admin_init() {
$wp_roles = new WP_Roles();
$wp_roles->use_db = true;
$administrator = $wp_roles->get_role(\'administrator\');
if (!$administrator->has_cap(\'manage_administrators\'))
$wp_roles->add_cap(\'administrator\',\'manage_administrators\');
$website_owner = $wp_roles->get_role(\'website_owner\');
if (!$website_owner) {
//let\'s use the editor as the base capabilities
$caps = get_role(\'editor\')->capabilities;
$caps = array_merge( $caps, array(
\'install_plugins\' => false,
\'activate_plugins\' => false,
\'update_plugins\' => false,
\'delete_plugins\' => false,
\'list_users\' => true,
\'add_users\' => true,
\'create_users\' => true,
\'edit_users\' => true,
\'delete_users\' => true,
\'remove_users\' => true,
\'unfiltered_upload\' => true,
\'install_themes\' => false,
\'update_themes\' => false,
\'delete_themes\' => false,
\'switch_themes\' => false,
\'edit_theme_options\' => true,
\'manage_options\' => false,
\'import\' => false,
\'update_core\' => false,
\'edit_dashboard\' => false,
\'gravityforms_view_entries\' => true,
\'gravityforms_edit_entries\' => true,
\'gravityforms_delete_entries\' => true,
\'gravityforms_export_entries\' => true,
\'gravityforms_view_entry_notes\' => true,
\'gravityforms_edit_entry_notes\' => true,
\'gravityforms_feed\' => true,
\'manage_administrators\' => false,
));
$wp_roles->add_role(\'website_owner\',\'Website Owner\',$caps);
}
}