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.

//Added by Steve to customize the Wishlist login
global $userdata;

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" />
<?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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineDon't talk to me.Commented:
Try this instead of get_currentuserinfo();

$current_user = wp_get_current_user();


<?php if (!intval($current_user->ID)) { ?>

Sometimes that works when get_currentuserinfo() won't due to conflicts in global calls.


Alternately, why is:

if ( is_user_logged_in() )

not an option?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stkoontzAuthor Commented:
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,

Jason C. LevineDon't talk to me.Commented:
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.
stkoontzAuthor Commented:
Worked beautifully!  And thanks for the extra tip for bringing the logged out use to the homepage.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.