Joris Menke
Joris Menke

Reputation: 33

How do i add an custom post type to a new role created by the Members plugin for wordpress

I have created a new role in the Members plugin, However that specific role needs to only have access to 2 custom post types i have created. These CPT's are created using the label tag.

The problem is that the custom post type doesn't show up on the members plugin when i want to assign it.

I tried using the capabilities tag but when i use that it does show up but when i login as the user assigned with that role it doesnt show the CPT in the nav bar of wordpress.

English isn't my first language so please excuse me if the formatting is wrong.

Upvotes: 2

Views: 340

Answers (1)

Nick
Nick

Reputation: 356

Try to assign capabilities to that new role, in functions.php file:

function add_role_caps() {

//roles to add capabilities
$roles = array('YOUR-NEW-ROLE','editor','administrator');

//set capabilities for selected roles
foreach($roles as $role) {

$myrole = get_role($role);

$myrole->add_cap( 'read' );
$myrole->add_cap( 'read_MYCPT');
$myrole->add_cap( 'read_private_MYCPTS' );
$myrole->add_cap( 'edit_MYCPT' );
$myrole->add_cap( 'edit_MYCPTS' );
$myrole->add_cap( 'edit_others_MYCPTS' );
$myrole->add_cap( 'edit_published_MYCPTS' );
$myrole->add_cap( 'publish_MYCPTS' );
$myrole->add_cap( 'delete_others_MYCPTS' );
$myrole->add_cap( 'delete_private_MYCPTS' );
$myrole->add_cap( 'delete_published_MYCPTS' );

  }
}
add_action('admin_init','add_role_caps',999);

Just replace the CAPS values with your own. This answer assumes that the CPT was created with the optional plural descriptive name for the custom post type.

Upvotes: 1

Related Questions