Tips and Tricks HQ Support Portal › Forums › WP eMember › Question about adding login status to Nav bar on page
- This topic has 9 replies, 4 voices, and was last updated 14 years ago by amin007.
-
AuthorPosts
-
January 13, 2010 at 1:30 am #652rjd2Member
I would like to have an area on a nav bar that indicates that the user is “Logged In” or “Logged Out”. If they are logged out I would like to have something shown like “Login | Register” and have it redirect them to the “registration” page if they need a new account. If they already have an account I would like it to show “User Logged In” in the same area on the nav bar.
How would I do something like this?
January 13, 2010 at 7:50 am #17190amin007ParticipantYou will need to add a bit of PHP code to check if the member is logged in or not and depending on that you can show different links.
Following is an example of PHP code that you can potentially use
if (function_exists('wp_eMember_install'))
{
$emember_auth = Emember_Auth::getInstance();
$user_id = $emember_auth ->getUserInfo('member_id');
if (!empty($user_id))
{
//Member is logged in so display whatever you want
}
else
{
//Member is not logged in
}
}January 13, 2010 at 6:57 pm #17191rjd2MemberPlease bear with me here since I am still pretty new at PHP.
In wordpress i have my header.php file and I would like to add this code in there somewhere to show something like “Login | Register” or if they are already logged in, “Logged in as USERNAME | Edit Profile | Logout”.
The code would be similar to this (with hyperlinks of course). Do I need to make sure my header.php file knows where the wp_eMember_install() function is located? ie, which file it is located in within the eMember plugin files?
if (function_exists(‘wp_eMember_install’))
{
global $auth;
$user_id = $auth->getUserInfo(‘member_id’);
if (!empty($user_id))
{
// Display “Logged in as USERNAME | Edit Profile | Logout”
}
else
{
//Display “Login | Register”
}
}
January 14, 2010 at 12:00 am #17192amin007ParticipantYou should just be able to place the above code in your “header.php”. WordPress knows if that function is available or not
January 14, 2010 at 7:24 pm #17193hermediaMemberTried this inserted into header.php (where my WP login plugin was inserted) and it’s not showing
<?php
if (function_exists(‘wp_eMember_install’))
{
global $auth;
$user_id = $auth->getUserInfo(‘member_id’);
if (!empty($user_id))
{
//Member is logged in so display whatever you want
}
else
{
//Member is not logged in
}
} ?>
January 14, 2010 at 11:11 pm #17194amin007ParticipantDid you just paste the exact same thing or did you actually put the code where it has the comment like:
//Member is logged in so display whatever you want
You will need to add in your HTML code that you want in the block where it’s a comment telling you that you need place your HTML code there.
November 15, 2010 at 5:12 pm #17195gcollignonMemberHi, I am trying this too, but I don’t know what to put instead of //Member is logged in so display what you want.
Thanks
November 16, 2010 at 1:28 am #17196amin007ParticipantYou put whatever message you want to display to your members.
November 17, 2010 at 2:11 am #17197gcollignonMemberHi Amin, thanks for your response. I am still a little bit confused.
How do I display the information like you mentioned above:
-Display “Logged in as USERNAME | Edit Profile | Logout”
Thanks
Gabriel
November 17, 2010 at 5:28 am #17198amin007ParticipantYou will have to code it up but if you don’t have PHP coding knowledge then try to use this compact login option explained here:
http://www.tipsandtricks-hq.com/wordpress-membership/using-a-compact-login-and-join-us-message-203
-
AuthorPosts
- You must be logged in to reply to this topic.