Login as non-admin user removes Dashboard submenu. I wish to re-enable it

Ideally, since the "Dashboard" submenu is gone for authors, I just want to replace it with a single link that

Ideally, since the "Dashboard" submenu is gone for authors, I just want to replace it with a single link that pulls up the wp-admin home page.

Just re-enabling Dashboard>home would work well too.

[edit] Here is what I have now. I know this isn't the best way to do this, but I couldn't get "add_menu_page" do do it correctly. I manually edited the $menu variable.

This will work as a solution if I cannot find a better way.

add_action( 'admin_menu', function (){
    if ( !current_user_can( 'administrator' ) ) {
        global $menu;
        $menu[0]=[
            0 => 'Dashboard',
            1 => 'read',
            2 => 'index.php',
            3 => '',
            4 => 'menu-top menu-top-first menu-icon-dashboard',
            5 => 'menu-dashboard',
            6 => 'dashicons-dashboard',
        ];
    }
});

Ideally, since the "Dashboard" submenu is gone for authors, I just want to replace it with a single link that pulls up the wp-admin home page.

Just re-enabling Dashboard>home would work well too.

[edit] Here is what I have now. I know this isn't the best way to do this, but I couldn't get "add_menu_page" do do it correctly. I manually edited the $menu variable.

This will work as a solution if I cannot find a better way.

add_action( 'admin_menu', function (){
    if ( !current_user_can( 'administrator' ) ) {
        global $menu;
        $menu[0]=[
            0 => 'Dashboard',
            1 => 'read',
            2 => 'index.php',
            3 => '',
            4 => 'menu-top menu-top-first menu-icon-dashboard',
            5 => 'menu-dashboard',
            6 => 'dashicons-dashboard',
        ];
    }
});
Share Improve this question edited Apr 25, 2019 at 19:10 De Coder asked Apr 25, 2019 at 6:01 De CoderDe Coder 3291 silver badge11 bronze badges 1
  • I located where the theme author removed the menu via remove_menu_page() – De Coder Commented Apr 30, 2019 at 17:54
Add a comment  | 

1 Answer 1

Reset to default 1

It's not the menu you need to adjust - it's your roles and capabilities.

By default, a WP Core Author has "Dashboard" in their menu. You're correct, they do not have a submenu under Dashboard, but clicking Dashboard takes them to the same page as "Dashboard > Home" for other users.

You may want to look through whatever plugins you're using that may have adjusted permissions, and/or use a user role plugin to check what permissions users have. If they can't see "Dashboard" at all, they need "read" capability added:

// hook to admin init
add_action('admin_init', 'add_author_caps');
function add_author_caps() {
    // get the author role
    $role = get_role('author');
    // add "read" capability
    $role->add_cap('read');
}

You can add this temporarily wherever you like - theme or plugin - and after you've logged in and viewed anything in wp-admin, you can remove this code as WP will save the capability.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745551827a4632611.html

相关推荐

  • Login as non-admin user removes Dashboard submenu. I wish to re-enable it

    Ideally, since the "Dashboard" submenu is gone for authors, I just want to replace it with a single link that

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信