I have created a custom post type called Course Documents using WordPress Custom Post Type UI plugin. Also, I have created a new user role called Teacher.
add_role('rpt_teacher',
'Teacher',
array(
'read' => true,
'edit_posts' => false,
'delete_posts' => false,
'publish_posts' => false,
'upload_files' => true,
)
);
And now I want to enable the custom post type in teacher dashboard nav menu. I have used below code in my functions.php but nothing happens. How can I resolve my issue?
add_action('admin_init','rpt_add_role_caps',999);
/**
add teachers capability
*/
function rpt_add_role_caps() {
// Add the roles you'd like to administer the custom post types
$roles = array('rpt_teacher','editor','administrator');
// Loop through each role and assign capabilities
foreach($roles as $the_role) {
$role = get_role($the_role);
$role->add_cap( 'read' );
$role->add_cap( 'read_course_document');
$role->add_cap( 'edit_course_document' );
$role->add_cap( 'edit_course_documents' );
$role->add_cap( 'edit_published_course_documents' );
$role->add_cap( 'publish_course_documents' );
$role->add_cap( 'delete_published_course_documents' );
}
}