[wp-hackers] Adding a custom content type that only a particular role can create/modify

Raj list at expost.org
Mon Jul 26 02:28:01 UTC 2010


Hi all,

 

Here's what I need to do in my plugin:

 

1.       Add a Wiki Page Content Type

2.      Add 'Wiki Editor' Role

3.      Ensure that the users of Wiki Editor role and only they are able to
create and edit 'Wiki Page' type.

 

 

Here's what happens:

 

Nothing. When I create a user of type Wiki Editor and then log in and then
log in as that user, I see no option to create content of any type. When the
user logs in I see just two menu items -  Dashboard and  Profile

 

I had initially set the capability_type to 'post'. But that allowed anyone
with the 'publish_posts' permissions to create Wiki Pages. So I renamed the
capability_type to 'wiki_page'. Then the Wiki Page content type became
unavailable for the administrator account. To solve that I added wiki_editor
to the administrator's role after which the Wiki Page was visible to the
admnistrator's account.

 

Here's the full code:



<?php

/*

Plugin Name: Wiki

Author: Rajasekharan S

Description: This is a plugin to add a Wiki to Wordpress. 

*/

 

function wiki_init() 

{

     

     

  $labels = array(

    'name' => _x('Wiki Pages', 'post type general name'),

    'singular_name' => _x('Wiki Page', 'post type singular name'),

    'add_new' => _x('Add New', 'wikipage'),

    'add_new_item' => __('Add New Wiki Page'),

    'edit_item' => __('Edit Wiki Page'),

    'new_item' => __('New Wiki Page'),

    'view_item' => __('View Wiki Page'),

    'search_items' => __('Search Wiki Pages'),

    'not_found' =>  __('No wikipages found'),

    'not_found_in_trash' => __('No wikipages found in Trash'), 

    'parent_item_colon' => ''

  );

  

  $args = array(

    'labels' => $labels,

    'public' => true,

    'publicly_queryable' => true,

    'show_ui' => true, 

    'query_var' => true,

    'rewrite' => true,

    'capability_type' => 'wiki_page',

    'hierarchical' => false,

    'menu_position' => 5,

    'supports' =>
array('title','editor','author','thumbnail','excerpt','comments')

  ); 

  register_post_type('wikipage',$args);

  

  $role_capabilities =
array('read'=>1,'edit_wiki_page'=>1,'edit_others_wiki_pages'=>1,'edit_publis
hed_wiki_pages'=>1,'read'=>1,'publish_wiki_pages'=>1);

  

  add_role( 'wikicontributor', 'WikiContibutor', $role_capabilities );

  

}

 

add_action('init', 'wiki_init');

 

Please tell me what I am doing wrong. How do I make this thing work. 

 

Warm Regards,

Raj Sekharan

 

 



More information about the wp-hackers mailing list