Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

For example, if I create a post type called "destinations" does that automatically create capabilities like "edit_destinations" or "delete_destinations"?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

It does not automatically create that capability in the sense that there is no new capability registered with WordPress. Instead it defaults to use the capabilities assigned to creating/editing posts. For example, if an author logs in they will be able to create and publish a new destination entry by default.

You can override this with the capabilities value when using register_post_type. See Justin Tadlock's excellent tutorial here http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress

share|improve this answer
    
hehe, coincidentally i was just reading Justin Tadlock's articles! Good stuff! Thanks! –  trusktr Jun 29 '11 at 0:56
add comment

I define a central var for the custom post type: public $post_type_1 = 'archiv';

and use this on add new capabilities:

        $capabilities = array(
            'edit_post'          => 'edit_' . $this->post_type_1,
            'edit_posts'         => 'edit_' . $this->post_type_1 . 's',
            'edit_others_posts'  => 'edit_others_' . $this->post_type_1 . 's',
            'publish_posts'      => 'publish_' . $this->post_type_1 . 's',
            'read_post'          => 'read_' . $this->post_type_1,
            'read_private_posts' => 'read_private_' . $this->post_type_1 . 's',
            'delete_post'        => 'delete_' . $this->post_type_1
        );

Also i add this new capabilties objects to the differnet default roles, only on activation of the plugin:

        foreach ( $this->todo_roles as $role ) {
            $wp_roles->add_cap( $role, 'edit_'          . $this->post_type_1 );
            $wp_roles->add_cap( $role, 'edit_'          . $this->post_type_1 . 's' );
            $wp_roles->add_cap( $role, 'edit_others_'   . $this->post_type_1 . 's' );
            $wp_roles->add_cap( $role, 'publish_'       . $this->post_type_1 . 's' );
            $wp_roles->add_cap( $role, 'read_'          . $this->post_type_1 );
            $wp_roles->add_cap( $role, 'read_private_'  . $this->post_type_1 . 's' );
            $wp_roles->add_cap( $role, 'delete_'        . $this->post_type_1 );
            $wp_roles->add_cap( $role, 'manage_'        . $this->taxonomy_type_1 );
        }

        foreach ( $this->read_roles as $role ) {
            $wp_roles->add_cap( $role, 'read_' . $this->post_type_1 );
            $wp_roles->add_cap( $role, 'read_' . $this->post_type_1 );
            $wp_roles->add_cap( $role, 'read_' . $this->post_type_1 );
        }

        global $wp_rewrite;
        $wp_rewrite->flush_rules();

But, you must also unregister this objects, if the plugin will be uninstalled.

You can see an example on this gist: https://gist.github.com/978690

share|improve this answer
    
Thanks for the tip. Hey, quick question: when you use the add_cap function, is that the same function that plugins like "Capability Manager" or "Members" plugins use in their inner workings? –  trusktr Jul 1 '11 at 6:32
    
yep, the plugins use also this function. –  bueltge Jul 1 '11 at 18:36
1  
@bueltge why do you need to flush_rules() after adding capabilities? Also, if you use the following code to register capabilities for a custom post type: 'capability_type' => array('archives', 'archive'), 'map_meta_cap' => true, then when adding a capability, for example edit_archive capability using add_cap method, doesn't it get expanded to include corresponding primitive caps: edit_archives, edit_published_archives, edit_other_archives and edit_private_archives. OR do they have to be added separately? –  dashaluna Sep 18 '11 at 11:05
    
@bueltge I got very confused with capabilities and trying to understand them better, if my comment doesn't make much sense, please have a look at my full question here tiny.cc/ybbo4 Many thanks :) –  dashaluna Sep 18 '11 at 11:07
    
@bueltge Also, after adding the capabilities to the admin role (the same set of capabilities as you have in todo_roles loop) the admin user still can't even edit others custom posts, and I don't understand why :S –  dashaluna Sep 18 '11 at 11:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.