【问题标题】:Wordpress : Add_cap || edit menu onlyWordPress : Add_cap ||仅编辑菜单
【发布时间】:2018-01-10 17:59:25
【问题描述】:

(首先,对不起我的英语不好)

我想知道是否有一种纯 php 方式允许 编辑用户 编辑菜单。

此代码允许编辑器访问外观菜单,并且工作正常。

// get the the role object
$role_object = get_role( 'editor' );

// add capability to this role object
$role_object->add_cap( 'edit_theme_options' );

但我不希望他编辑主题或小部件。我知道有插件可以管理这些功能,但我正在寻找一种简单的 php 方式来做到这一点,有什么想法吗?

提前致谢!

【问题讨论】:

    标签: php wordpress roles


    【解决方案1】:

    您对此有何看法?

    $role_object = get_role('editor');
    $role_object->add_cap('edit_theme_options');
    
    add_action('admin_head', function() 
    {
      // Check if the user === 'editor'
      if (is_object(get_role('editor'))) {
          remove_submenu_page('themes.php', 'themes.php');
          remove_submenu_page('themes.php', 'widgets.php');
      }
    });
    

    【讨论】:

    • 我不知道remove_submenu_page!确实有很大帮助,这正是我想要的,谢谢!我对 wordpress 有点陌生 :)
    • @AlexisWollseifen 很高兴它现在正在工作!不要忘记设置您要解决的问题。
    猜你喜欢
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    相关资源
    最近更新 更多