首页 > 解决方案 > Woocommerce - 从商店经理中删除适度评论功能

问题描述

我想moderate_comments从 Shop Manager 角色中删除该功能。

我正在使用下面的代码,它根本不起作用。

add_action( 'init', 'add_hgkb_caps');
function add_hgkb_caps() {
    $shop_manager = get_role( 'shop_manager' );
    $shop_manager->remove_cap('moderate_comments');
}

但是,对于其他角色(例如编辑和作者)也可以正常工作。

标签: wordpresswoocommerce

解决方案


您可以尝试不同的方法:-

add_filter( 'comment_row_actions', 'add_hgkb_caps', 15, 2 );
function add_hgkb_caps( $actions, $comment )
{
    $roles=array('shop_manager'); //You can add more roles
    $current_user = wp_get_current_user();
    $current_user_role=$current_user->roles[0];

    if(in_array($current_user_role,$roles))
    {
        unset( $actions['quickedit'], $actions['edit'], $actions['spam'], $actions['unspam'], $actions['trash'], $actions['untrash'], $actions['approve'], $actions['unapprove'], $actions['delete'] );
    }
    return $actions;
}

推荐阅读