It’s a little hackish and should be completed but it works for now.
Also I had a chat with the people from WooThemes and they told me this feature should be available in the following months within the plugin, so this will become obsolete.
//Hack - Shows only user's own resources if the user does not have the edit_others_manage_booking_resources capability
function bookable_resource_limit_posts_to_author($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin ) return $query;
if( !current_user_can('administrator') && !current_user_can( 'edit_others_manage_booking_resources' ) && ( $_GET['post_type'] == 'bookable_resource' ) ) {
global $user_ID;
$query->set('author', $user_ID );
echo '<style>.subsubsub, .icl_subsubsub {display:none !important;}</style>'; //Fugly - hide table quick links
}
return $query;
}
add_filter('pre_get_posts', 'bookable_resource_limit_posts_to_author');
add_filter('views_edit-bookable_resource','bookable_resource_quicklinks');
function bookable_resource_quicklinks($views) {
unset($views['all']);
unset($views['publish']);
unset($views['trash']);
return $views;
}
//Show Resources in menu and redefine Vendor Admin Role to be able to manage resource
function modify_bookable_resource_custom_post_type()
{
//Modify Custom post type to allow access and show up in menu
global $wp_post_types;
$p = 'bookable_resource';
// Someone has changed this post type, always check for that!
if ( empty ( $wp_post_types[ $p ] )
or ! is_object( $wp_post_types[ $p ] )
or empty ( $wp_post_types[ $p ]->labels )
)
return;
$wp_post_types[ $p ]->show_in_menu = true;
$wp_post_types[ $p ]->map_meta_cap = false;
$wp_post_types[ $p ]->supports = array( 'title', 'author' ); //Not working, why ? -> modified in web/app/plugins/woocommerce-bookings/woocommerce-bookings.php - line 406
//Redefine Vendor Amin role
remove_role( 'wc_product_vendors_admin_vendor' );
add_role( 'wc_product_vendors_admin_vendor', 'Vendor Admin', admin_vendor_caps() );
}
add_action( 'wp_loaded', 'modify_bookable_resource_custom_post_type', 1002 );
//Redefine Admin Vendor capabilities
//Copied and modified from plugins/woocommerce-product-vendors/includes/class-wc-product-vendors-roles-caps.php
function admin_vendor_caps() {
return apply_filters( 'wcpv_default_admin_vendor_role_caps', array(
'read_product' => true,
'manage_product' => true,
'edit_products' => true,
'edit_product' => true,
'edit_published_products' => true,
'edit_shop_orders' => true,
'assign_product_terms' => true,
'upload_files' => true,
'read' => true,
'manage_bookings' => true,
'edit_others_products' => false,
'view_vendor_sales_widget' => true,
'delete_published_products' => true,
'delete_others_products' => false,
'delete_posts' => true,
'delete_others_posts' => false,
'edit_comment' => false,
'edit_comments' => false,
'view_woocommerce_reports' => false,
'publish_products' => false,
//Add resource capabilities to the Vendor Admin role
'edit_manage_booking_resource' => true,
'read_manage_booking_resource' => true,
'delete_manage_booking_resource' => true,
'edit_manage_booking_resources' => true,
'edit_others_manage_booking_resources' => false, //WHY IS IT SHOWING OTHERS' RESOURCES ??
'publish_manage_booking_resources' => true,
'read_private_manage_booking_resources' => true,
'edit_manage_booking_resources' => true,
'delete_others_manage_booking_resources' => false,
) );
}