WordPress.org

Support

Support » Plugins and Hacks » Nav Menu Roles » [Resolved] Show menu for logged out AND by role

[Resolved] Show menu for logged out AND by role

  • How can I show a menu item for both logged out users AND by role?

    Here is an example. I have a job board. I’d like to show the menu items Post a Job and Post a Resume for logged out users. For logged in Subscribers I’d like to show Post a Job and hide Post a Resume. For logged in Candidates I’d like to show Post a Resume and hide Post a Job.

    I can’t seem to be able to select by “By role” and logged out at the same time.

    https://wordpress.org/plugins/nav-menu-roles/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author helgatheviking

    @helgatheviking

    You can’t. The plugin just isn’t set up for that. Best case would be to create 2 menu items for “Post a Job”: the first, only shown to logged out users and the second show to Candidates.

    ah i didn’t even think of that. very logical 🙂 thank you!

    Plugin Author helgatheviking

    @helgatheviking

    It isn’t really ideal, but yours seems a special use case and I’m probably not updating the plugin to change how it works any time soon.

    I have a similar case.

    Where I have a WooCommerce store and I’d like to show a link for Join for those users that don’t have an active Subscription, but also those that aren’t logged in as well.

    Plugin Author helgatheviking

    @helgatheviking

    I’m open to suggestions. I just don’t want to have all checkboxes because then people could easily check ‘all logged in’ and ‘all logged out’ and it would be a mess.

    That I totally get for sure.

    I’m totally shooting off the top of my head right now, but maybe if ‘By Role’ is selected then there are radio buttons for Logged In/Logged Out/Both and then you have the roles listed as checkboxes?

    Plugin Author helgatheviking

    @helgatheviking

    What about adding “Logged Out” as a pseudo “role” and giving it a checkbox?
    http://i.imgur.com/M686iYe.png

    I don’t know how that would play with the back-end code however. As a friendly reminder that this code is on Github and I am open to contributions.

    I think that may work — I had forked it and working on a solution that seems to work well.

    Plugin Author helgatheviking

    @helgatheviking

    Send me a pull request if you come up with something good.

    Plugin Author helgatheviking

    @helgatheviking

    It turns out that this is already possible using the current filters available in NMR. Modified from the FAQ and taking into account @codewaggle‘s correction to the FAQ (to be published soon) here is my suggestion:

    function kia_new_roles( $roles ){
    	$roles['logged-out'] = 'All Logged Out';
    	return $roles;
    }
    add_filter( 'nav_menu_roles', 'kia_new_roles' );
    
    function kia_item_visibility( $visible, $item ){
        if( isset( $item->roles ) && is_array( $item->roles ) && in_array( 'logged-out', $item->roles ) && ! is_user_logged_in() ){
    		$visible = true;
    	}
    	return $visible;
    }
    add_filter( 'nav_menu_roles_item_visibility', 'kia_item_visibility', 10, 2 );

    I make no guarantees and can’t really work on it further. It seems to work for me, but hasn’t been extensively tested either.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Show menu for logged out AND by role’ is closed to new replies.
Skip to toolbar