Skip to content

Instantly share code, notes, and snippets.

@Jerl92
Created January 26, 2024 03:31
Show Gist options
  • Select an option

  • Save Jerl92/bf8146c2bb9cfa7baf2561a2cc839a7f to your computer and use it in GitHub Desktop.

Select an option

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
<?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' );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment