WooThemes-供应商/预订-允许供应商管理资源

时间:2018-05-09 作者:Pierre

我正在尝试从WooThemes为bookings插件带来新功能。在组合预订和供应商插件时,不允许供应商用户管理资源(资源是自定义帖子)。

我将新功能添加到资源自定义帖子中,然后将这些功能添加到供应商角色(通过用户角色插件)

现在,资源显示在供应商角色的管理菜单中,但当我尝试添加新资源时,会出现“您无权访问此页面”错误。

我添加的新功能:https://i.stack.imgur.com/OCDlV.png

添加到角色的功能:https://i.stack.imgur.com/5t696.png

使用角色登录时显示的资源:https://i.stack.imgur.com/go0ZZ.png

但单击“添加”按钮不起作用:https://i.stack.imgur.com/9jD5k.png

=======================================================

Edit :

多亏了@mmm comment,我确定这些功能被称为“manage\\u booking\\u resource”。在阅读了更多的资料后,我找到了一个(远不完美的)解决方案,如下所示。

1 个回复
最合适的回答,由SO网友:Pierre 整理而成

这有点粗糙,应该完成,但现在还可以。

我还与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 \'<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,

    ) );
}

结束

相关推荐

About Wordpress capabilities

我知道WordPress是博客引擎的最佳选择,通过一些插件,如Advance Custom Field,WP可以成为一个很棒的CMS。但它仍然有利于出版商将内容推送给用户。现在我的处境相当严峻。我的朋友想使用WP作为一个引擎,用户可以贡献他们的帖子,其他人可以查看它。是否可以使用WP我可以创建自定义主题(&a);插件可以做到这一点,但当用户在插件上放置很多东西(页面和帖子)时,它对性能有好处吗?