将shop_Manager角色限制为WooCommerce订单页面

时间:2018-10-09 作者:saeid ezzati

我只想显示woocommerce orders pageshop_manager 角色,并限制用户使用shop_manager 只转到该管理页。

如果未显示此消息:Sorry, you are not allowed to access this page.

我该怎么做?

1 个回复
SO网友:saeid ezzati

我终于找到了解决办法。

function checkUserPermissionsInThisScreen(){
    if (is_admin()){

        $currentUserRoles = wp_get_current_user()->roles;
        if (in_array(\'shop_manager\', $currentUserRoles)){

            $a = get_current_screen();
            if ($a->id != \'edit-shop_order\' && $a->post_type != \'shop_order\'){
                wp_die(\'you do not have needed permissions to see this page\');
            }
        }
    }
}
add_action(\'current_screen\', \'checkUserPermissionsInThisScreen\');

结束

相关推荐

Recommended File Permissions

嘿,伙计们,我花了很长时间试图解决这个问题。我想知道WordPress中的文件权限应该是什么样子in order to use the autoupdate feature. 到目前为止,我的wordpress安装程序一直在询问我的FTP信息,我不想使用那种升级/安装方法,我想使用纯/直接PHP。某些上下文:Web服务器和php fcgi守护程序运行为www-data:www-data</wordpress安装位于/home/blaenk/sites/domain.tld/</首先,我read