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

Joaquin Rodriguez Montero yojoaquin at gmail.com
Fri Jun 25 21:20:08 UTC 2010

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',

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?



More information about the wp-hackers mailing list