I’m trying to configure capabilities for a custom post type. I want to enable editing, but disable creating and deleting. create_posts
cannot be set to false unless delete_posts
is also false, but it seems that this combination disables the editing screen.
Thanks!
There are a lot of capabilities, you can set for your post type.
foreach ( self::$todo_roles as $role ) {
$wp_roles->add_cap( $role, 'edit_' . self::$post_type_1 );
$wp_roles->add_cap( $role, 'read_' . self::$post_type_1 );
$wp_roles->add_cap( $role, 'delete_' . self::$post_type_1 );
$wp_roles->add_cap( $role, 'edit_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'edit_others_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'publish_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'read_private_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'delete_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'delete_private_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'delete_published_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'delete_others_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'edit_private_' . self::$post_type_1 . 's' );
$wp_roles->add_cap( $role, 'edit_published_' . self::$post_type_1 . 's' );
}
With something like the above you can add capabilities the roles.
As hint to the source. The self::$post_type_1
is a variable in a class for the custom post type. The foreach
loop is to add this capabilities often to different roles.