WordPress.org

Forums

is_user_logged_in doesn't work (5 posts)

  1. icecappacino
    Member
    Posted 2 years ago #

    I'm trying to log in a Facebook user as a wordpress user using the wp_insert_user wp_auth_cookie and wp_set_current_user and wp_signon(null,true) in that order on the wp_loaded hook which gives me the user user_logged_in() result as true after the process...

    however in trying to refresh the page the user_logged_in() results false which again tries to repeat the steps above even though the user has been successfully created and logged in. It leads me to believe that either the is_user_logged_in is being called too early before the user can be instantiated or the user is not being properly logged in

    How can I safely check user is logged in after the user has been instantiated?

  2. pankaj_kumar036
    Member
    Posted 2 years ago #

    <?php if ( is_user_logged_in() ) {
    	   global $user_login;
            get_currentuserinfo();
    
    ?>
    <div id="loginInfo" width="100%" style="text-align:right;">
        <!-- text that logged in users will see -->
    <span style="margin-right:22px">Welcome <?php echo ucfirst($user_login); ?>    <a href="http://www.neweastsidecommunity.com" title="Logout">Log Out</a></span>
    </div>
    <?php
     }?>


    [Please use the code buttons when posting code here]

    I'M NOT ABLE TO REDIRECT ON THE LINK PAGE

  3. Pioneer Web Design
    Member
    Posted 2 years ago #

    http://codex.wordpress.org/Function_Reference/is_user_logged_in

    <?php
    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
    } else {
        echo 'Welcome, visitor!';
    }
    ?>

    Start with above (and perhaps use PHP also to change some text?)

    http://codex.wordpress.org/Function_Reference/get_currentuserinfo

  4. tazo todua
    Member
    Posted 2 years ago #

    is_user_logged_in() may not work, if the script is outside of wp folder ?? ... yet, i am not sure about that.

  5. cs2009pc
    Member
    Posted 1 year ago #

    is_user_logged_in() may not work, if the script is outside of wp folder ?? ... yet, i am not sure about that.

    Confirmed, I had the same problem and the dozen other threads on the internet did not have anyone mentioning this (or I didn't read the manual right).

    Wrong Way
    ./test.php
    ./wordpress/wp-blog-header.php

    Correct Way
    ./wordpress/test.php
    ./wordpress/wp-blog-header.php

Topic Closed

This topic has been closed to new replies.

About this Topic