Change WordPress user roles and capabilities › Forums › New Feature Request › Custom Post Type Rights › Reply To: Custom Post Type Rights
10/11/2019 at 02:22
#6097
Vladimir
Keymaster
You may try this solution:
add_action( 'registered_post_type', 'cpt_add_edit_permissions', 10, 2 );
function cpt_add_edit_permissions( $post_type, $post_type_object ) {
if ( !class_exists( 'URE_Lib') ) {
return;
}
$roles = array('administrator', 'editor');
$lib = URE_Lib::get_instance();
$capabilities = $lib->get_edit_post_capabilities();
foreach( $capabilities as $capability ) {
if ( isset( $post_type_object->cap->$capability ) ) {
URE_Capabilities::add_cap_to_roles( $roles, $post_type_object->cap->$capability );
}
}
}
This code automatically adds edit capabilities to roles from the all $roles array for any registered post type.
Parameters:
$post_type – post type slug, like ‘post’,
$post_type_object – self commented.
Just fill $roles array with your own roles ID, which is allowed to create new custom post types and setup this code as a must use plugin to wp-content/mu-plugins folder.