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:

Gori teri aankhen kahe

Gori teri aankhen kahe
raat bhar sooyi nahi
chanda dekhe chupke kahi
aur taare jaante hain sabhi
ke kisne dil le liya
kisko dil de diya
yeh dil ka lagana koi jaanta nahi
Gori teri aankhen kahe
raat bhar sooyi nahi

Dil mein teri yaad basi
tu samjhe ga nahi
jo hain mere paas hai tera
mera kuch nahi
kyun akhiya chupao
kyun tujhko satao
dil tod ke tera
mein kya pao
bol piya bol piya bol
piya bol piya bol piyaaa bol

saajan teri baatein badi
ke mein raat bhar sooyi nahi
chanda ne bhi dekha nahi
aur taaro ko yeh maloom nahi
ke meine tujhe dil diya
tera dil le liya
mera tu hi hain bahana
kyun manta nahi
saajan teri baatein badi
ke mein raat bhar sooyi nahi

Aate jaate mausam jaise
lagte the sabhi
humne bhi to manga rab se
apna bhi koi
Duniya se bachao
palko mein chupao
dil jeet ke tera
sab ko batao
sun gori sun gori sun gori sunnn
sun gori sun gori sunnnnn

Gori teri aankhen kahe
jaane anjaane mein kahi
chanda ne bhi dekha nahi
aur taaro ne bhi jaana nahi
ke tune mujhe dil diya
mera dil de diya
mera jeene ka bahana
koi aur nahi

gori teri aanken