I already mention to you that give us little more details about the plan that you want to do?
Here is the solution that I think it would be helpful for you.
If you want to used map_meta_cap => true then you will need to change capability_type as well with your own type, see more https://codex.wordpress.org/Function_Reference/register_post_type#capability_type
But if you set your own capability_type value then you will need to add capability to users role those you want to add.
here is a complete example.
if ( !class_exists( 'WPSE64458_CPT_Register' ) ) {
class WPSE64458_CPT_Register {
function __construct() {
add_action( 'init', array( $this, 'wpse64458_register_post_types' ), 5 );
add_action( 'admin_init', array( $this, 'wpse64458_add_caps' ), 5 );
add_filter( 'register_post_type_args', array( $this, 'wpse64458_modify_cpt_registry' ) , 10, 2 );
}
/**
* Register core post types.
*/
public function wpse64458_register_post_types() {
if ( ! is_blog_installed() || post_type_exists( 'member' ) ) {
return;
}
register_post_type( 'member',
apply_filters( 'wpse64458_callb_post_type_member',
array(
'labels' => array(
'name' => __( 'Members', 'domaintext' ),
'singular_name' => __( 'Member', 'domaintext' ),
'all_items' => __( 'All Members', 'domaintext' ),
'menu_name' => _x( 'Members', 'Admin menu name', 'domaintext' ),
'add_new' => __( 'Add New', 'domaintext' ),
'add_new_item' => __( 'Add new member', 'domaintext' ),
'edit' => __( 'Edit', 'domaintext' ),
'edit_item' => __( 'Edit member', 'domaintext' ),
'new_item' => __( 'New member', 'domaintext' ),
'view' => __( 'View member', 'domaintext' ),
'view_item' => __( 'View member', 'domaintext' ),
'search_items' => __( 'Search members', 'domaintext' ),
'not_found' => __( 'No members found', 'domaintext' ),
'not_found_in_trash' => __( 'No members found in trash', 'domaintext' ),
'parent' => __( 'Parent member', 'domaintext' ),
'featured_image' => __( 'Member image', 'domaintext' ),
'set_featured_image' => __( 'Set member image', 'domaintext' ),
'remove_featured_image' => __( 'Remove member image', 'domaintext' ),
'use_featured_image' => __( 'Use as member image', 'domaintext' ),
'insert_into_item' => __( 'Insert into member', 'domaintext' ),
'uploaded_to_this_item' => __( 'Uploaded to this member', 'domaintext' ),
'filter_items_list' => __( 'Filter members', 'domaintext' ),
'items_list_navigation' => __( 'Members navigation', 'domaintext' ),
'items_list' => __( 'Members list', 'domaintext' ),
),
'public' => true,
'show_ui' => true,
'capability_type' => 'member',
'map_meta_cap' => true,
'menu_icon' => 'dashicons-groups',
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
'rewrite' => array( 'slug' => 'member' ),
'query_var' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'has_archive' => 'members',
'show_in_nav_menus' => true,
'show_in_rest' => true,
)
)
);
} // end of wpse64458_register_post_types
/**
* Get capabilities.
*
* @return array
*/
private function wpse64458_set_caps() {
$capabilities = array();
$capability_types = array( 'member' );
foreach ( $capability_types as $capability_type ) {
$capabilities[ $capability_type ] = array(
// Post type
"edit_{$capability_type}",
"read_{$capability_type}",
"delete_{$capability_type}",
"edit_{$capability_type}s",
"edit_others_{$capability_type}s",
"publish_{$capability_type}s",
"read_private_{$capability_type}s",
"delete_{$capability_type}s",
"delete_private_{$capability_type}s",
"delete_published_{$capability_type}s",
"delete_others_{$capability_type}s",
"edit_private_{$capability_type}s",
"edit_published_{$capability_type}s",
// Terms
// "manage_{$capability_type}_terms",
// "edit_{$capability_type}_terms",
// "delete_{$capability_type}_terms",
// "assign_{$capability_type}_terms",
);
}
return $capabilities;
}
/*
Add Capability
*/
public function wpse64458_add_caps(){
global $wp_roles;
if ( ! class_exists( 'WP_Roles' ) ) {
return;
}
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
$capabilities = $this->wpse64458_set_caps();
foreach ( $capabilities as $cap_group ) {
foreach ( $cap_group as $cap ) {
$wp_roles->add_cap( 'editor', $cap );
$wp_roles->add_cap( 'administrator', $cap );
}
}
}
public function wpse64458_modify_cpt_registry( $args, $post_type ){
// Do not filter any other post type
if ( 'member' !== $post_type ) {
// Give other post_types their original arguments
return $args;
}
if( current_user_can('editor') ) {
$args['capabilities']['create_posts'] = false;
}
// Give the custom-css-js post type it's arguments
return $args;
}
}
}
then inherite the class with new WPSE64458_CPT_Register();
With this example I disable editor role to add new member post functionality. modify whatever you like, or you can do this others as well. but you previously mention that you already tried to follow WooCommerce, actually they also do this way,
Hope it make sense to you.
HappyCodding!