我正试图为WooThemes的预订插件带来新的功能。在合并预订和供应商插件时,不允许供应商用户管理资源(资源是定制的帖子)。
我将新功能添加到资源自定义post中,然后将这些功能添加到供应商角色(通过用户角色插件)。
现在,资源显示在管理员菜单中,用于供应商角色,但当我尝试添加新资源时,我会得到“您无权访问此页面”错误。
我添加的新功能:https://i.stack.imgur.com/OCDlV.png
添加到角色中的功能:https://i.stack.imgur.com/5t696.png
使用角色登录时显示的资源:https://i.stack.imgur.com/go0ZZ.png
但是单击add按钮不起作用:https://i.stack.imgur.com/9jD5k.png
=======================================================
感谢@mmm评论,我发现这些功能被称为"manage_booking_resource“。然后,经过更多的阅读,我找到了一个(远不是完美的)解决方案,如下所示。
发布于 2018-05-23 11:19:08
这有点麻烦,应该已经完成了,但现在起作用了。
另外,我还和WooThemes的人聊了聊,他们告诉我,这个功能应该在接下来的几个月里在插件中可用,所以这个功能将变得过时。
//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 '.subsubsub, .icl_subsubsub {display:none !important;}'; //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,
) );
}https://wordpress.stackexchange.com/questions/303094
复制相似问题