How to achieve conditional (i.e. role-dependent) display of menu items?

Forums Forums Menus How to achieve conditional (i.e. role-dependent) display of menu items?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #540
    nv1962
    Member

    This is a feature question, not a feature request: is there a way to show a menu item <i>only</i> if the user is logged in with a given role level (or higher)? I.e. what I’m trying to figure out is if there’s a way to show a pseudo-secret menu item only to logged in users with certain roles (think: private area). I’ve seen <a href="http://wordpress.org/extend/plugins/user-access-manager/">this plugin</a> but given its beta-status (although I’m seeing it’s pretty well-evolved now) I’m not too sure if there’s another way to accomplish that, without hacking away at WP core files.

    #4665

    Hmm, interesting idea. You would need to code that directly. The plugin can’t do it itself.

    I actually use that method on http://dunedinicehockey.hellyer.kiwi/, albeit that site doesn’t use a dropdown menu.

    You don’t need a plugin for it BTW, the coding is pretty simple. I’ll look itup and be back shortly with a script  for you.

    #4666

    I thought it was easy. Having trouble finding how to check what use role someone is though <img decoding=” title=”Sad” />

    #4667
    nv1962
    Member

    <s>I hope I’m posting in time although if you can post that snippet I’d be more than obliged as</s> I found that that plugin I linked to above does <i>exactly</i> what I want.

    For the takers: you have to create a separate "Group" to which you (as the admin) can assign members, by going to each (intended) member’s profile page and checking the membership box for that Group.

    Then, in the Page Settings section of the User Access Manager plugin (it requires >= WP2.7) you select "Hide complete pages" ("Yes") which will ensure that <i>only</i> the assigned members of the group in question can see the menu (navigation) items assigned to it.

    Finally, on every page that you want to be accessible only to a specific group, you select the check box for that Group (under "Access") and presto! The corresponding menu item of that page is visible <i>only</i> to members of that Group. You could this way even have several, different "secret" areas / pages for different groups, each only seeing "their" pages (and corresponding menu items). Of course, as the admin, you see everything – but the "secret" (locked behind user credentials) pages are marked visibly for the admin with a tailing [L] added to the title, so you always know what’s "secret" or "protected". The non-group member doesn’t see the "hidden" menu items at all.

    Bonus feature of that plugin: you can also indicate certain filetypes – via the file extension – as access-protected (it’s accomplished through a .htaccess mod handled by the plugin, managing also the corresponding .htpasswd file) so that uploaded files are accessible only by the members of that assigned group with access granted.

    Thought I’d mention that solution… It’s really awesome, how plugins can create a fully-featured, tailor-made and rich CMS out of WordPress.

    <s>Still, as it’s a rather feature-rich plugin: if you have a more efficient code hack, I’ll take that instead! (I’m not using the extra functionality of User Access Manager, so…)</s>

    <b>Added later:</b> ack – too late… Sorry about that, Ryan!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.