// Videos
$labels = array(
'name' => _x( 'Videos', 'post type general name' ),
'singular_name' => _x( 'Video', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Video' ),
'edit_item' => __( 'Edit Video' ),
'new_item' => __( 'New Video' ),
'all_items' => __( 'All Videos' ),
'view_item' => __( 'View Video' ),
'search_items' => __( 'Search Videos' ),
'not_found' => __( 'No Videos found' ),
'not_found_in_trash' => __( 'No Videos found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Videos'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our Videos specific data',
'public' => true,
'taxonomies' => array('category', 'post_tag'),
'menu_position' => 3,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'author'),
'has_archive' => true,
'map_meta_cap' => true,
'capability_type' => 'video',
'capabilities' => array(
'publish_posts' => 'publish_videos',
'edit_posts' => 'edit_videos',
'edit_others_posts' => 'edit_others_videos',
'delete_posts' => 'delete_videos',
'delete_others_posts' => 'delete_others_videos',
'read_private_posts' => 'read_private_videos',
'edit_post' => 'edit_video',
'delete_post' => 'delete_video',
'read_post' => 'read_video',
),
);
register_post_type( 'video', $args );
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 movie, get the post and post type object. */
if ( 'edit_video' == $cap || 'delete_video' == $cap || 'read_video' == $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 movie, assign the required capability. */
if ( 'edit_video' == $cap ) {
if ( $user_id == $post->post_author )
$caps[] = $post_type->cap->edit_posts;
else
$caps[] = $post_type->cap->edit_others_posts;
}
/* If deleting a movie, assign the required capability. */
elseif ( 'delete_video' == $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 movie, assign the required capability. */
elseif ( 'read_video' == $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;
}