I am starting to get comfortable with Custom Post Types, but I don´t get the capabilities for them right.

I have something like this:

// define capabilities...
$capabilities_werden = array(
'publish_posts' => 'publish_werden_event',
'edit_posts' => 'edit_werden_event',
'edit_others_posts' => 'edit_others_werden_event',
'delete_posts' => 'delete_werden_event',
'delete_others_posts' => 'delete_others_werden_event',
'read_private_posts' => 'read_private_werden_event',
'edit_post' => 'edit_werden_event',
'delete_post' => 'delete_werden_event',
'read_post' => 'read_werden_event'

// ... use them for a custom post type...
function register_events_werden() {
      'labels' => array(
         'name' => __('Events in Werden'),
         'singular_name' => __('Event in Werden'),
         'new_item' => __('Neues Event'),
      'public' => true,
      'has_archive' => true,
      'exclude_from_search' => true,
      'capability_type' => 'werden_event',
      'capabilities' => $capabilities_werden,

// ... and later on create a role
add_role('werden_event_author', 'Werden Events', array (
   'publish_werden_event' => true,
   'edit_werden_event' => true,
   'edit_others_werden_event' => true,
   'delete_werden_event' => true,
   'delete_others_werden_event' => true,
   'read_private_werden_event' => true,
   'edit_werden_event' => true,
   'delete_werden_event' => true,
   'read_werden_event' => true,
   // more standard capabilities here
   'read' => true,

The Custom Post Type works fine and I can also assign the new role to a user. But when a user with that role is logged in there are just "Dashboard" and "Profile" to choose from, but not the Custom Post Type menu.

What am I missing?

  • 1
    This isn't directly relevant, but add_role changes the database, you only need to do it once, not on every page load – Tom J Nowell Oct 27 '15 at 2:55
  • Yes, I´m aware of that. I will hook it to the theme activation in the end. But this way I´m sure I can see the changes once I reload. – flomei Oct 27 '15 at 8:05
  • add_role will short itself out and return early if it picks up that the role already exists, if you're planning on updating a role you need to delete it before adding – Tom J Nowell Oct 27 '15 at 20:36
  • Well, actually my codes runs a remove_role() before the add_role(). (Maybe it´s just a problem with the order of the functions and roles? That made sense in my head before I went to bed yesterday...) – flomei Oct 28 '15 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.