Answers:
试试这个...这应该工作。
<?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);
}
?>
检查。
在我的情况下工作的系统是这样的:
<?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
}
}
?>