How to create new roles using clone in wordpress

In this Tutorial We are Learning how to Create and Clone the Role in word press before staring the tutorial lets first we need to know what is role

Role is which defined the what a specific user can do on website in word press we have 5 predefined roles.

1.Administrator – Full access to Websites
2.Editor – Have Few limited access in website .Editor can publish post ,Edit the post, review posts submitted by contributors and schedule the post for review.
3.Author – publish Post
4.Contributor – Write the post but cannot publish and Submit the post for review.
5.Subscriber – Right to Post the comment only.

1.clone administrator role

add_action('init', 'CreatecloneRole');
function CreatecloneRole()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
 
    $adms = $wp_roles->get_role('administrator');
    $wp_roles->add_role('new_admin', 'new admin', $adms->capabilities);
}

2.clone Editor role

add_action('init', 'CreatecloneRoleEditor');
function CreatecloneRoleEditor()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
 
    $etr = $wp_roles->get_role('Editor');
    $wp_roles->add_role('new_Editor', 'new Editor', $etr->capabilities);
}

3.clone Author role

add_action('init', 'CreatecloneRoleAuthor');
function CreatecloneRoleEditor()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
 
    $atr = $wp_roles->get_role('Author');
    $wp_roles->add_role('new_Author', 'new Author', $atr->capabilities);
}

4.clone Contributor role

add_action('init', 'CreatecloneRoleContributor');
function CreatecloneRoleContributor()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
 
    $ctr = $wp_roles->get_role('Author');
    $wp_roles->add_role('new_Author', 'new Author', $ctr->capabilities);
}

5.clone Subscriber role

add_action('init', 'CreatecloneRoleSubscriber');
function CreatecloneRoleSubscriber()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
 
    $scr = $wp_roles->get_role('Author');
    $wp_roles->add_role('new_Author', 'new Author', $scr->capabilities);
}

Add a Comment

Your email address will not be published. Required fields are marked *

14 + 7 =