latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

%%current_user_login%% Menu Button

Home Forums Community Forum %%current_user_login%% Menu Button

Tagged: , ,

This topic contains 3 replies, has 2 voices. Last updated by  Andy Ogden 4 years, 6 months ago.

Topic Author Topic
Posted: Friday Apr 27th, 2012 at 12:04 pm #12055

Hi,

Is it possible to link %%current_user_login%% to a menu button so that if a user has a page called the same as their name it will take them to it?

And then if the user does not have a page created it will take them to the membership page?

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Monday Apr 30th, 2012 at 5:27 pm #12233

UPDATE:

I have managed to create a hyperlink which takes the current logged in users username and redirects them to their page if created.

<a href="?php echo S2MEMBER_CURRENT_USER_LOGIN; ?>/">Client Area</a>

My next question is:

How can i wrap this in an if statement to say that if the username does not = a page name then redirect them to the home page?

Posted: Thursday May 3rd, 2012 at 7:38 am #12453

Hi All,

I now have the following code

<a href="<?php echo (defined('S2MEMBER_CURRENT_USER_LOGIN') ? S2MEMBER_CURRENT_USER_LOGIN : post_name);?>/">Client Area</a>

But it’s still not redirecting the user if they don’t have a page created?

Any help would be great!

Posted: Thursday Jun 21st, 2012 at 10:04 am #17127

I’ve been trying to find out how to do the same thing and just managed to get it working, so hopefully you’ll find my solution helpful. You seem to have gone down the redirect route, but since your original request was for a menu button I’m hoping you’re still interested.

I’ve created a members only version of the menu and then used a function to add an additional button which includes the a page I’ve created that matches their custom capability.

Dependant Setup: –

  • Each user account has a custom capability defined that matches their username exactly.
  • Create a page with the same name, or at least the same slug as the custom capability. This page will act as the users personal homepage

Optional Setup: –

To add an extra menu in WordPress you can use the following article – http://codex.wordpress.org/Function_Reference/register_nav_menus
But essentially something like this, which should be found in functions.php

register_nav_menus( array(
	'public_menu' => 'Public Menu',
	'member_only' => 'Members Only Menu'
) );

This is accompanied by a change in header.php to decides which version of the menu a user gets to see depending on whether they’re logged in or not

if ( is_user_logged_in() ) {
	wp_nav_menu( $member_args );
	} else {
	wp_nav_menu( $visitor_args );
}

What I did here is to leave a ‘Member Area’ item on the public menu which pointed to wp-admin so that the user can log in. The members only version of the menu doesn’t have this option and my solutions continues…

In functions.php add a new function

// Changes to insert a member area only link to direct users to their personal home page
add_filter( 'wp_nav_menu_items', 'add_member_link', 10, 2 );

function add_member_link( $items, $args ) {

    if (is_user_logged_in() && $args->theme_location == 'members') {
        $items .= '<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="http://www.andyogden.co.uk/members/'.S2MEMBER_CURRENT_USER_LOGIN.'">Member Area</a></li>';
    }
    return $items;
}
// End of change by AO
Viewing 3 replies - 1 through 3 (of 3 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.