WordPress Clone User Role to create New Role
- Article
- Comment (1)
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.
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)