如何从 WordPress 管理端隐藏特定用户角色的条带?

问题描述 投票:0回答:2

我正在使用用户角色编辑器并尝试为特定用户隐藏此条带网关

我应该在用户编辑器角色的设置中检查什么,以便我可以看到订单但看不到条带。

php wordpress plugins stripe-payments
2个回答
0
投票

您正在使用的“Stripe Gateway”插件似乎无法提供按角色有选择地允许或拒绝使用的功能。今天测试了其中一些,我还没有找到这样的。因此(很棒的)用户角色编辑器插件可能无法帮助您完成此任务。但不要绝望!还有其他方法:-)

如果我理解正确的话,您想对一个或多个角色/用户隐藏 Stripe 设置(这样实时 API 密钥是安全的),对吗?将其从角色中删除是最简单的。

实际上,涉及两个步骤。一种是自然地隐藏您提到的“Stripe Gateway”菜单,但在 WooCommerce Payment 选项卡下也可以找到 Stripe 设置。我们还需要隐藏用户/角色的选项卡。

可能有更优雅的解决方案,但我可以提供完成此任务的建议。

  1. 要隐藏不需要的“Stripe”菜单,请安装 Adminimize 插件并激活。
  2. 然后仪表板 - 设置 - 管理 - 菜单选项
  3. 出现的屏幕将以表格形式显示在左侧,所有仪表板菜单,其中应包括您的“Stripe Gateway”。右侧是角色列表。
  4. 在管理表中找到不需要的“Stripe Gateway”菜单,并为表右侧的商店经理角色勾选“停用商店经理”设置复选框。
  5. 请记住向下滚动并单击“更新选项”按钮以保存插件设置。

希望仪表板中该角色的菜单现已消失。

现在我找不到您正在使用的确切 Stripe 插件,但用另一个示例来生成屏幕截图,说明我所写的内容(链接到屏幕截图)。 Adminimize - hiding a menu from Shop manager role

第二步是删除 WooCommerce 商店经理角色的“付款”选项卡。这个问题已经在这里得到了解答。使用该帖子中的代码,将以下内容添加到您的子主题的functions.php(如果您使用的是子主题)。

    add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $tabs ) {
    // Declare the tabs we want to hide
    $tabs_to_hide = array(
        'Payments',
        );


    // Get the current user
    $user = wp_get_current_user();

    // Check if user is a shop-manager
    if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {

        // Remove the tabs we want to hide
        $tabs = array_diff($tabs, $tabs_to_hide);
    }

    return $tabs;
}

结果如下所示(链接到屏幕截图)。 Hiding a tab in WooCommerce

我确信有更有经验的 WooCommerce 人员可以提供更好的答案,但我希望这会有所帮助。


0
投票

所以我创建了这个:

add_action( 'admin_menu', 'remove_admin_menu_items', 999 );

function remove_admin_menu_items() {

    // global $woocommerce;
    global $submenu;
    $current_user = wp_get_current_user();
    $role = $current_user->roles;
    // To hide settings by role :any_new_role
    if ($role[0] == 'any_new_role') {
        // users menu
        unset( $submenu['users.php'][5] ); // removes list of users
        unset( $submenu['users.php'][15] ); // removes edit your profile
   
        remove_menu_page('wc_stripe'); // Hiding stripe gateway settings
        remove_menu_page('woocommerce'); // Hiding woocommerce settings
        remove_menu_page('automatewoo'); // Hiding automatewoo settings
        remove_menu_page('jetpack'); // Hiding jetpack settings
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.