Capabilites not working

I created a custom post type:

add_action( 'init', 'artwork_feature');
function artwork_feature() {
register_post_type( 'artwork',
    array(
    'labels' => array(
            'name' => __( 'Artwork' ),
            'singular_name' => __( 'Artwork' )
        ),
    'public' => true,
    'exclude_from_search' => false,
    'capability_type' => 'artwork',
    'supports' => array('custom-fields', 'comments', 'title', 'editor', 'thumbnail'),
    'capabilities' => array(
            'publish_posts' => 'publish_artworks',
            'edit_posts' => 'edit_artworks',
            'edit_others_posts' => 'edit_others_artworks',
            'delete_posts' => 'delete_artworks',
            'delete_others_posts' => 'delete_others_artworks',
            'read_private_posts' => 'read_private_artworks',
            'edit_post' => 'edit_artwork',
            'delete_post' => 'delete_artwork',
            'read_post' => 'read_artwork',
        ),
    'map_meta_cap' => true,
    'taxonomies' => array('post_tag'),
    'has_archive' => true   
    )
);

}

Read More

Then I installed the MEMBERS plugin, created a new role ‘Artists’ and went into the role and clicked ‘Add New Capabilities’. I added:

  1. edit_artworks
  2. delete_artworks

Then in my Admin Role I added:

  1. edit_artworks
  2. delete_artworks
  3. publish_artworks
  4. edit_others_artworks
  5. delete_others_artworks
  6. read_private_artworks

Also, following a tutorial I added this to the functions.php:

//Set roles to meta capabilities
add_filter( 'map_meta_cap', 'my_map_meta_cap', 10, 4 );

function my_map_meta_cap( $caps, $cap, $user_id, $args ) {

/* If editing, deleting, or reading a artwork, get the post and post type object. */
if ( 'edit_artwork' == $cap || 'delete_artwork' == $cap || 'read_artwork' == $cap ) {
    $post = get_post( $args[0] );
    $post_type = get_post_type_object( $post->post_type );

    /* Set an empty array for the caps. */
    $caps = array();
}

/* If editing a artwork, assign the required capability. */
if ( 'edit_artwork' == $cap ) {
    if ( $user_id == $post->post_author )
        $caps[] = $post_type->cap->edit_posts;
    else
        $caps[] = $post_type->cap->edit_others_posts;
}

/* If deleting a artwork, assign the required capability. */
elseif ( 'delete_artwork' == $cap ) {
    if ( $user_id == $post->post_author )
        $caps[] = $post_type->cap->delete_posts;
    else
        $caps[] = $post_type->cap->delete_others_posts;
}

/* If reading a private artwork, assign the required capability. */
elseif ( 'read_artwork' == $cap ) {

    if ( 'private' != $post->post_status )
        $caps[] = 'read';
    elseif ( $user_id == $post->post_author )
        $caps[] = 'read';
    else
        $caps[] = $post_type->cap->read_private_posts;
}

/* Return the capabilities required by the user. */
return $caps;

}

Now when I create artworks and publish them I can only View them in both roles. I am missing the Edit, Quick Edit, & Trash links.

Can someone help?

Related posts

Leave a Reply