[wp-hackers] Custom Post Type with contributor-like capabilities?

Jake Goldman wphackers at jakemgold.myfastmail.com
Fri Jun 25 21:50:22 UTC 2010

  I will experiment more with that, but let me flesh out my (I think 
legitimate) use case.

if ( !get_role('guestblogger') )
     $caps = get_role('subscriber')->capabilities;
     $caps = array_merge( $caps, array( 'guest_blog' => true ) );
     add_role( 'guestblogger', 'Guest Blogger', $caps );

    // add guest blogger capability to others
     $role = get_role( 'administrator' );
     $role = get_role( 'adminlite' );
     $role = get_role( 'editor' );
     $role = get_role( 'author' );

register_post_type( 'guest-blogs', array(
     'label' => 'Guest Posts',
     'singular_label' => 'Guest Blog Post',
     'description' => 'Guest blog posts from the members.',
     'public' => true,
     'capability_type' => 'post',
     'capabilities' => array( 'edit_posts' => 'guest_blog' ),
     'supports' => 
     'menu_position' => 6

The idea here, anyhow, is that I don't want to add a bunch of new 
capabilities to administrators, editors, and authors (who should full 
access to guest posts). I want most of the new content type's 
capabilities to inherit those of "posts". In other words, if a role has 
the capability to "publish_posts", it should be able to publish "guest 
posts" (without a new capability). I /only/ want a unique capability for 
basic, contributor-like "edit_posts".

Perhaps I simply need to add unique, strictly named capabilities for 
'edit_post' and 'delete_post'? Or am I fundamentally missing something here?

Thanks for the input.


On 6/25/2010 5:27 PM, Andrew Nacin wrote:
> On Fri, Jun 25, 2010 at 4:16 PM, Jake Goldman<
> wphackers at jakemgold.myfastmail.com>  wrote:
>>   I'm attempting to create a custom post type "guest blogs" with a
>> contributor-like custom role, "guest blogger".
>> When registering the custom post type, I pass a custom capability for
>> "edit_posts" using the "capabilities" argument ("guest_blog"). The "guest
>> blog" capability is added to the new custom "guest blogger" role, as well as
>> a few other roles (like administrator).
> If you use a capability type like "gpost", which defaults to "post" then
> WordPress will automatically generate the edit_gposts, publish_gposts,
> delete_gposts (etc) capabilities for you. Additionally, it will know how to
> properly handle the edit_gpost, publish_gpost, and delete_gpost meta
> capabilities.
> If you want finer grained control, you can individual name each of the
> capabilities WP would otherwise generate for you based on the capability
> type.
> See register_post_type() and get_post_type_capabilities(), in
> wp-includes/post.php.
> _______________________________________________
> 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