[wp-hackers] Custom Post Type + Capabilities & Roles

Jake Goldman wphackers at jakemgold.myfastmail.com
Fri Jun 25 21:36:56 UTC 2010


  That (mostly) works... but that's not what I'm trying to do.

I'm trying to create an equivalent to post *contributors*, not authors 
(which I can do).

Are you able to create a new role that can submit "questions" for review 
via the admin, and can edit his / her own questions before publication, 
but can't edit others' questions or published questions?

On 6/25/2010 5:20 PM, Joaquin Rodriguez Montero wrote:
> Hi guys,
>
> I'm adding a 'Questions' section on my site by adding a custom post type. So
> far, so good:
>
>      add_action('init', 'question_register');
>      function question_register() {
>      $args = array(
>                'label' =>  __('Questions'),
>                'singular_label' =>  __('Question'),
>                'public' =>  true,
>                'show_ui' =>  true,
>                'capability_type' =>  'question',
>                'hierarchical' =>  false,
>                'rewrite' =>  true,
>                'supports' =>  array('title', 'comments', 'editor')
>               );
>
>          register_post_type( 'question' , $args );
>      }
>
> I'd like users to register and be able to post Questions, so I thought:
>
> 'capability_type' =>  'question',
>
> Therefore I created a user role and add those caps:
>
> add_role( 'questions_writer', 'Questions Writer',
> array('read,question,edit_question,publish_question,read_question,delete_question'));
>
> read to see the dashboard + profile, everything else to read, edit, delete
> the questions publish by him.
>
> As I changed the code several times before getting the 'final' code I
> thought adding:
> global $wp_roles;
> $wp_roles->add_cap( 'questions_writer', 'question' );
> $wp_roles->add_cap( 'questions_writer', 'edit_question' );
> $wp_roles->add_cap( 'questions_writer', 'edit_others_question' );
> $wp_roles->add_cap( 'questions_writer', 'publish_question' );
> $wp_roles->add_cap( 'questions_writer', 'read_question' );
> $wp_roles->add_cap( 'questions_writer', 'read_private_question' );
> $wp_roles->add_cap( 'questions_writer', 'delete_question' );
> $wp_roles->add_cap( 'questions_writer', 'read' );
>
> Problem: I can't get the Questions panel to be viewable by this user :'(
>
> Any ideas?
>
> Thanks,
>
> Chocks
> _______________________________________________
> 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