wordpress - 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');
}
但是,对于其他角色(例如编辑和作者)也可以正常工作。
解决方案
您可以尝试不同的方法:-
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;
}
推荐阅读
- python - 在df pandas中将数字AB分开到A和B
- apache-spark - 使用 zeppelin 在 kubernetes 上运行 Spark
- r - R中的随机森林 - 应用于测试/验证集
- excel - Excel VBA 显示带有 Afterupdate 和 Change 事件的货币
- visual-studio-2019 - 什么取代了 WM_BNCLICKED
- android - 后台服务中的推送通知颤动
- php - 第一条语句执行,但第二条语句不执行
- sql - 在sql中设置记录集的批号
- python - python sqlite为什么将值解释为列
- javascript - 如何在多维数组上使用 FILTER 来检索唯一值?