WordPress.org

Ready to get started?Download WordPress

Forums

Hide/Display Menu Items Based on User Role - Plugin? (8 posts)

  1. Travis Pflanz
    Member
    Posted 2 years ago #

    I have been searching for a while and cannot find the answer...

    Is there a plugin that will allow me to hide/display menu items based on user role?

    I don't necessarily want to block users from ever accessing a menu item, I simply want to hide it in the menu.

    For example: On my new baseball blog, I plan to allow all users (contributor status upon registration) the ability to submit custom posts (blog post, link, image, video), but I also want to allow approved authors the ability to enter ad code to be able to make money from their posts.

    I have a FAQ page to help authors set up their ad code. I don't want this page to be viewable in the menu for users with contributor status to avoid confusion, although it is not important to completely block contributors from viewing this page.

    Also, I don't want to create a bunch of different menus then hide a menu based user role. I want one menu, and hide certain items.

    I find it odd there is no plugin for this, especially since there are SO many to hide menu items on the dashboard based on user role.

    I don't care if this is a free or premium plugin. Let me know what I am missing.

    Thanks in advance

  2. kmessinger
    Volunteer Moderator
    Posted 2 years ago #

  3. Travis Pflanz
    Member
    Posted 2 years ago #

    Thanks for the reply, but I don't think any of these do what I am looking for. I am looking to HIDE items from a menu, not BLOCK them completely.

    If I am mistaken, please give more details as to the solution I am looking to accomplish.

  4. chevymanusa
    Member
    Posted 2 years ago #

    I am with tpflanz about this, need something to hide menu items for guests, not block them.

  5. Seth Alling
    Member
    Posted 1 year ago #

    I am also looking for a solution to do the same thing and I think I may have figured out how to do it.

    Place this code before your body tag:

    global $current_user;
    if ( is_user_logged_in() )
    	$user_role = 'role-' . $current_user->roles[0];
    else
    	$user_role = 'role-guest';

    Next, make sure your body tag is using the body_class() function and place $user_role inside of it. Depending on your theme, it will roughly look something like this:

    <body <?php body_class($user_role); ?>>

    This will add the class role-administrator or some other role name to the body. If the user is not logged in, the class will be role-guest.

    Then, all you have to do is add a CSS class (turned off by default - can be found in Screen Options on the Menu admin page) to the menu item you want to hide.

    Finally use CSS to hide the menu item from the user.

  6. cslim
    Member
    Posted 1 year ago #

    I have been searching for days in the internet to resolve this need to hide the menu-item created by Appearance-->Menu from the Public and display it only to members. I think your solution should work.

    As a computer idiot, I need very specific instructions on how to implement your solution.

    Thank you a thousand times if you can spare your time to do so.

  7. jwallen3rd
    Member
    Posted 1 year ago #

    @Seth

    concerning the
    <body <?php body_class($user_role); ?>>

    Mine currently is
    <body <?php body_class(PC_THEME_NAME_SLUG) ?>>

    How do I place $user_role in my situation?

  8. Earthman Web & Media
    Member
    Posted 1 year ago #

    The CSS hiding will hide the menu items, yes, but not restrict acess to the pages...

    If you want greater control over access to the content, then you might need a membership plugin....

    Wishlist Member
    Infusionsoft / iMember360
    Justin Tadlock's members plugin

    All of these can do what you want, but need some major setup.

Topic Closed

This topic has been closed to new replies.

About this Topic