0

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' );
        }
        }
ashanrupasinghe
  • 758
  • 1
  • 10
  • 22
  • Found a solution: https://wordpress.stackexchange.com/questions/290090/how-to-enable-a-custom-post-type-to-custom-user-role-in-wordpress/290100#290100 – ashanrupasinghe Jan 04 '18 at 10:04

1 Answers1

1

You may use this plugin for your custom post type and custom user role.

Hope this will helps you.

For more information,

Sunil Dora
  • 1,407
  • 1
  • 13
  • 26