WordPress Clone User Role to create New Role |
X

Congrats, You are Subscribed to Receive Updates.

WordPress Clone User Role to create New Role


Today, lets  talk about WordPress User  roles and capabilities.  when we come to play with User roles. we need to copy some use capability to other user Role. Here i am going to give you a simple code to copy the author as teacher.  Just one example makes you to understand how it’s working.

add_action('init', 'cloningauthor');

function cloningauthor()
{
    global $wp_roles;  // Delcaring roles and collecting the author role capability here.
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();

    $adm = $wp_roles->get_role('author');
    //Adding a 'new_role' with all admin caps
    $wp_roles->add_role('teacher', 'Teacher', $adm->capabilities);
}

The above code will help you to clone the author role as teacher. If you have problems in implementation drop your comments below.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

One comment

  1. commenter

    How to fetch post data according to category id in WordPress.
    And also how to display custom field value on post page(single post page)

Reply to ram Cancel reply

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

*

Current ye@r *

Menu

Sidebar