Membership2 Pro autoswap Login Logout in Menu

I am thinking this is an essential feature for any membership system but I can't find this in this membership 2 pro.
Once I install membership 2 pro, it auto generate 3 menu,
1. account
2. membership
3. registration

1. Once I login / registration, the menu should be auto change to logout, but I can't find this in this plugin in, how do I accomplished it.

2. I only have 1 membership plan, how can I skip it for choose it. By default if only one membership should link the user to the registration page. Possible to accomplished it anyway?

Thanks!

  • Ash

    Hello @YEOH

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    #1. I am marking this as a feature request. For now you can try the following script:

    function add_login_logout_link($items, $args)
    {
    if(is_user_logged_in())
    {
    $newitems = '<li><a title="Logout" href="'. wp_logout_url('index.php') .'">logout</a></li>';
    $items .= $newitems;
    }
    else
    {
    $newitems = '<li><a title="Login" href="'. wp_login_url('index.php') .'">login</a></li>';
    $items .= $newitems;
    }
    return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    #2. In the register page use the following shortcode:

    [ms-membership-title id="189" label=""]
    [ms-membership-details id="189" label=""]
    [ms-membership-price id="189" label="Price:" currency="yes"]
    [ms-membership-buy id="189"]

    Where 189 is the membership ID.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Ash

    Hello @YEOH

    You will need to know the menu location of the top menu. By default it should be "primary", but it depends on the theme.

    Please try the following code (which includes the registration menu link too) and replace LOCATION with the top menu location:

    function add_login_logout_link( $items, $args ){
    	if( $args->theme_location == 'LOCATION' ){
    		if( is_user_logged_in() ) {
    			$newitems = '<li><a title="Logout" href="'. wp_logout_url('index.php') .'">Logout</a></li>';
    			$items .= $newitems;
    		}else{
    			$newitems = '<li><a title="Login" href="'. wp_login_url('index.php') .'">Login</a></li>';
    			$newitems = '<li><a title="Login" href="'. wp_registration_url() .'">Register</a></li>';
    			$items .= $newitems;
    		}
    	}
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Ash

    Hello @YEOH

    Sure :slight_smile: In that case use the following code:

    function add_login_logout_link( $items, $args ){
    	if( $args->theme_location == 'LOCATION' ){
    		if( is_user_logged_in() ) {
    			$newitems = '<li><a title="Logout" href="'. wp_logout_url('index.php') .'">Logout</a></li>';
    			$items .= $newitems;
    		}else{
    			$newitems = '<li><a title="Login" href="CUSTOM_LOGIN">Login</a></li>';
    			$newitems = '<li><a title="Login" href="'. wp_registration_url() .'">Register</a></li>';
    			$items .= $newitems;
    		}
    	}
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Replace CUSTOM_LOGIN with your custom login page :slight_smile:

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.