• Resolved Krissieg

    (@krissieg)


    Any help would be greatly appreciated!

    Hi there, I’ve managed to hide and add elements I need in the admin dashboard for the user role: Trader. BUT, I can’t for the life of me work out how to hide the top bar ‘View Products’ item when you select ‘Products’ in the admin menu below. I don’t want to hide the Site menu you see, so simply hiding the bar isn’t an option. See screengrab:

    https://oyoo.earth/wp-content/uploads/2023/11/Hide-View-Products.png

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @krissieg

    I hope you are doing well today.

    We have a feature Admin Bar which help to re-order or add item in that area. To cover your request you will need a custom code, which I shared below:

    <?php
    
    function user_role_admin_body_class( $classes ) {
    global $current_user;
    foreach( $current_user->roles as $role )
    $classes .= ' role-' . $role;
    return trim( $classes );
    }
    
    //choose only 1 filter depend from back or front end
    add_filter( 'admin_body_class', 'user_role_admin_body_class' ); //for back_end

    follow this guide to implement this code as a mu plugin on your site https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Notes:

    • with the above code in the admin area <body will have an additional CSS class for each role, like “role-author” etc. In your case, it will also generate class “role-trader”. Log in as Trader to your site and double-check the source of admin page to see the correct class.
    • In Branda Admin Bar module (Custom CSS section) or Branda Custom CSS module itself add this code:
    .role-trader #wpadminbar #wp-admin-bar-archive {display:none;}

    Make sure “.role-trader” is the same as your class from <body class after you check source.

    Kind Regards,
    Kris

    Thread Starter Krissieg

    (@krissieg)

    HI Kris, thanks for this info. I’m a bit of a beginner when it comes to coding. So I’m not sure what you mean when you say about double-checking the source of the admin page for the correct class. Where do I look for that? Thank you for your patience in advance!

    Thread Starter Krissieg

    (@krissieg)

    Don’t worry, I’ve just added the code in the css and it works without having to add something in the mu-plugin area. You can close this ticket! Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to hide View Products’ is closed to new replies.