admin管理员组文章数量:1122846
How to create new role with same capabilities of existing role. Eg: I would like to create a new role with same capabilities of administrator or editor and so on..
How to create new role with same capabilities of existing role. Eg: I would like to create a new role with same capabilities of administrator or editor and so on..
Share Improve this question asked Oct 19, 2011 at 5:33 AadiAadi 5072 gold badges6 silver badges10 bronze badges 2- What have you tried? What worked? What didn't? Have you tried Members Plugin? Or Capability Manager Plugin? Do they do the things you want? – soulseekah Commented Oct 19, 2011 at 5:42
- You can use User Role Editor if you want to do everything visually :) – user9567 Commented Oct 19, 2011 at 10:57
5 Answers
Reset to default 44Try this... This should work.
<?php
add_action('init', 'cloneRole');
function cloneRole()
{
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
$adm = $wp_roles->get_role('administrator');
//Adding a 'new_role' with all admin caps
$wp_roles->add_role('new_role', 'My Custom Role', $adm->capabilities);
}
?>
Check it.
You could always use the User Role Editor plugin;
- Install the plugin
- Go to Users > User Role Editor
- Click "Add Role" to the right
- Choose the role you wish to duplicate from the "Make copy of" dropdown in the dialogue box
- Click "Add Role" in the dialogue box
suppose you want to clone the editor.
$edr = $wp_roles->get_role('Editor');
add_role('clonerole', 'clone roles', $edr->capabilities);
the system that worked in my case is this:
<?php
add_action('init', 'cloneRole');
function cloneRole() {
$adm = get_role('administrator');
$adm_cap= array_keys( $adm->capabilities ); //get administator capabilities
add_role('new_role', 'My Custom Role'); //create new role
$new_role = get_role('new_role');
foreach ( $adm_cap as $cap ) {
$new_role->add_cap( $cap ); //clone administrator capabilities to new role
}
}
?>
As of 2024, cloning a role is better achieved with the wp
CLI role command, e.g.
wp role create 'new-role' 'New-role' --clone 'existing-role'
本文标签: capabilitiesHow to create a clone role in wordpress
版权声明:本文标题:capabilities - How to create a clone role in wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306490a1932976.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论