【问题标题】:give shop manager access to appearance wordpress让商店经理访问外观 wordpress
【发布时间】:2021-08-07 17:05:49
【问题描述】:


我想允许“商店经理”访问外观以编辑菜单,我该怎么做,我的意思是我应该将哪些代码添加到 function.php

谢谢你!

【问题讨论】:

标签: wordpress woocommerce


【解决方案1】:

这应该将包含管理菜单的“编辑主题选项”添加到角色“商店经理”

function add_theme_caps() {
    $role = get_role( 'shop_manager' );
    $role->add_cap( 'edit_theme_options' ); 
}
add_action( 'admin_init', 'add_theme_caps');

【讨论】:

  • 确实,如果您能提供帮助,我只想将菜单和小部件交给他!
  • 把上面的放在你的functions.php中
  • 谢谢你!现在效果很好我只想在子菜单中显示菜单和小部件,你知道怎么做吗?!
【解决方案2】:

我在这里找到了解决方案

https://wordpress.stackexchange.com/questions/4191/allow-editors-to-edit-menus

您还可以在外观下显示某些菜单。

希望这会有所帮助。

$role_object = get_role( 'editor' );
$role_object->add_cap( 'edit_theme_options' );

您可以在刷新管理面板后注释掉整个代码,因为上面的代码会对数据库进行持久更改。

您现在拥有对编辑器可见的所有选项。您可以像这样隐藏其他选项:

function hide_menu() {

    remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
    remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu

    // these are theme-specific. Can have other names or simply not exist in your current theme.
    remove_submenu_page( 'themes.php', 'yiw_panel' );
    remove_submenu_page( 'themes.php', 'custom-header' );
    remove_submenu_page( 'themes.php', 'custom-background' );
}

add_action('admin_head', 'hide_menu'); hide_menu() 函数的最后 3 行是针对我的主题的主题。您可以通过在管理面板中单击要隐藏的子菜单来找到第二个参数。您的 URL 将类似于:example.com/wp-admin/themes.php?page=yiw_panel

因此,在本例中,remove_submenu_page() 函数的第二个参数将是 yiw_panel

【讨论】:

    【解决方案3】:

    为所有 Shop Manager 用户角色隐藏顶级菜单“产品”下的 Woocommerce 子菜单(Wordpress 5.1.1):

    function remove_menus_shopmgr(){
    
    // If the current user is a shop manager
    if ( current_user_can('shop_manager') ) {
    
       //removes Products > Categories submenu 
        remove_submenu_page( 'edit.php?post_type=product','edit-tags.php?taxonomy=product_cat&post_type=product' );
    
       //removes Products > Tags submenu
        remove_submenu_page( 'edit.php?post_type=product','edit-tags.php?taxonomy=product_tag&post_type=product' ); 
    
        }
    }
    
    add_action( 'admin_menu', 'remove_menus_shopmgr', 999 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      相关资源
      最近更新 更多