Link to home
Start Free TrialLog in
Avatar of stkoontz
stkoontzFlag for United States of America

asked on

Displaying logout option after WordPress login

I'm trying to customize the login feature of the WishList membership plugin for WordPress.  Everything works fine except that once a user has logged in, the sidebar doesn't change to the logout option.  It stays on the login option.

It's as if the userdata isn't being recognized so the 'else' isn't executed.  I added the following code to sidebar.php.

<?php
//Added by Steve to customize the Wishlist login
global $userdata;
get_currentuserinfo();
?>

The site is www.onmissioninsights.com 

<?php if (!intval($userdata->ID)) { ?>
<form method="post" action="http://onmissioninsights.com/wp-login.php">
Discover full curriculum campaigns, teaching tools, and other valuable resources FREE to ON MISSION INSIGHTS premier members. 
<a href="http://onmissioninsights.com/become-a-member-and-access-our-premium-content/">Become a Member</a>

<h4>Already a premier member?  Login here.</h4>
<label>Username: <input class="wlmember_loginwidget_input_username"  type="text" name="log" size="15" /></label>
<label>Password: <input class="wlmember_loginwidget_input_password" type="password" name="pwd" size="15" /></label>
<label><input  class="wlmember_loginwidget_input_checkrememberme" type="checkbox" name="rememberme" value="forever" /> Remember Me</label><input class="wlmember_loginwidget_input_submit" type="submit" name="wp-submit" value="Login" />

&raquo; <a href="http://onmissioninsights.com/wp-login.php?action=lostpassword">Lost your Password?</a><input type="hidden" name="wlm_redirect_to" value="wishlistmember" /><input type="hidden" name="redirect_to" value="wishlistmember" />
</form>
<?php } else { ?>
<h1>Welcome, <?php echo $userdata->user_firstname; ?></h1>
<a href="<?php echo wp_logout_url('http://www.onmissioninsights.com'); ?>">Logout</a>
<?php } ?>

Open in new window


Thanks in advance for any help.

Steve
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stkoontz

ASKER

Hi Jason,

Thanks for coming on to help me out.

I switched to if(is_user_logged_in()) and it worked fine.  (I didn't know about the command.)

Using get_currentuserinfo() allowed the option of putting the user's name on the welcome screen.  I just took the name off since it's not really needed.

Now the 'log out' option shows, but when I click 'log out' the user is taken to the WordPress login screen.  Do you know a command, besides the one I'm using below, that would take them back to the website homepage?  (Or should I post this in another question.)

<a href="<?php echo wp_logout_url('http://www.onmissioninsights.com'); ?>">Logout</a>

Thanks again,

Steve
Using get_currentuserinfo() allowed the option of putting the user's name on the welcome screen.  I just took the name off since it's not really needed.

You could probably still use it or wp_get_current_user for echoing purposes.  Just watch out for conflicting globals introduced in functions.php that may give you issues.

Technically it should be another question but we use:

<a href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a>

Open in new window


to logout and redirect to site home.
Worked beautifully!  And thanks for the extra tip for bringing the logged out use to the homepage.

Steve