Register Post Types, Using Capabilities:

Register Post Types, Using Capabilities:

When using custom post types in wordpress, I did some research and found some permission levels. These things are not exclusively explained in WordPress documentation ( ).

For example, I am adding a custom post type called book, then I would add following code to my plugin:

add_action('init', 'add_books_init');
function add_books_init()
  $labels = array(
    'name' => _x('Books', 'post type general name'),
    'singular_name' => _x('Book', 'post type singular name'),
    'add_new' => _x('Add New', 'book'),
    'add_new_item' => __('Add New Book'),
    'edit_item' => __('Edit Book'),
    'new_item' => __('New Book'),
    'view_item' => __('View Book'),
    'search_items' => __('Search Books'),
    'not_found' =>  __('No books found'),
    'not_found_in_trash' => __('No books found in Trash'),
    'parent_item_colon' => '',
    'menu_name' => 'Books'

  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => array('slug'=>'mybooks'),
    'capability_type' => array('book','books'),
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title', 'comments', 'editor'),

Notice the argument capability_type, which is optional in register post type. However, if we do not add this argument, the new book section will be registered with permissions as that of posts.

Now, in our case, the books sections is registered as a new entity, having its own permission set. We need to assign some new permissions to any user to access this entity (to an administrator also!)

In our case, the permissions that need to be assigned are mentioned below:


We can use some sort of plugins or use wp_capability variable to assign these permissions. I used capsman plugin for the same. Have a look at the screenshot: