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

Brent Shepherd thenbrent at gmail.com
Wed Jul 28 10:53:54 UTC 2010


Raj,

You need to map the wiki_page meta capabilities using the map_meta_cap
filter.

Doesn't help much does it? :)

It's best explained in code. Check out this file:
http://github.com/Prospress/Prospress/blob/master/pp-posts/pp-capabilities.php

There are three functions, each well commented enough for you to learn how
to manage the capabilities for a custom post type.

I've started work on a plugin to allow admins to manage capabilities for all
custom posts types, and to act as a guide to other plugin developers for
mapping meta caps. Once you get your head around it, if you'd like to help
write the plugin, let me know.

Brent




On Mon, Jul 26, 2010 at 12:28 PM, Raj <list at expost.org> wrote:

> 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
>
>
>
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list