I'm creating a project's plugin that needs two CPTs and a custom role to manage only that two CPTs. Creating the CPTs was the simple part, but I'm stuck on creating a custom user role for a week.
My CPTs are declared by:
register_post_type("cpt1", [
'label' => "CPT 1",
...
'capability_type' => "cpt",
]);
register_post_type("cpt2", [
'label' => "CPT 2",
...
'capability_type' => "cpt",
]);
And I'm declaring custom user role this way:
remove_role("cpt_manager");
add_role("cpt_manager", "CPT Manager", [
'read' => true,
'cpt' => true,
]);
But it's not working... I also tried declaring user role this way:
remove_role("cpt_manager");
add_role("cpt_manager", "CPT Manager", [
'read' => true,
'cpt' => true,
'read_cpt1' => true,
'edit_cpt1' => true,
'publish_cpt1' => true,
'delete_cpt1' => true,
'read_cpt2' => true,
'edit_cpt2' => true,
'publish_cpt2' => true,
'delete_cpt2' => true,
]);
But I can't make this to work.
Can someone help me pls?
When registering you custom post type you need to define the capabilties in a more granulat manner, see documentation for more info.