Created
January 26, 2024 03:31
-
-
Save Jerl92/bf8146c2bb9cfa7baf2561a2cc839a7f to your computer and use it in GitHub Desktop.
How to enable a custom post type to custom user role in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| 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' ); | |
| } | |
| } | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://wordpress.stackexchange.com/questions/290090/how-to-enable-a-custom-post-type-to-custom-user-role-in-wordpress