WordPress.org

Support

Support » Plugins and Hacks » wp_get_current_user not working in 2.9?

wp_get_current_user not working in 2.9?

Viewing 9 replies - 1 through 9 (of 9 total)
  • I have several installations, and the $current_user function seems to be broken on my 2.9 installation. Let me know if you figure this one out. [email moderated]

    I am also having this problem.

    I’m in the same boat. Any ideas?

    I made a workaround for this issue on my WP 3.0 install:

    <?php
    $thisuser = wp_get_current_user();
    if ( 0 == $thisuser->ID ) {  // Not logged in.
    } else {  // Logged in.
    echo '<li><a href="' . get_option('siteurl') . '/wp-admin/profile.php">Logged in as ' . $thisuser->display_name .'</a></li>';
    }
    ?>
    torvad
    Member

    @torvad

    I’m having the same problem. Did anyone find a good solution to the problem?

    wp_get_current_user() returns false, and it’s because $current_user is empty.

    When you log into WP, in which function or class is this variable instatiated with a user object?

    The wp_get_current_user() function appears to work fine for me (2.9.2 ->). Make sure its called after testing if the user is logged otherwise it will return NULL.

    @torvad – $current_user var is populated by the function call. If the function returns NULL then the var will be empty.

    As @ibr shows – you need to test if the user is logged in before making the function call. Here’s a similar way to test,

    <?php global $user;
        if (is_user_logged_in()) {
            $user = wp_get_current_user();
             ......

    is_user_logged_in() returns false inside the function &get_posts() which is in query.php

    When you edit a post in WP the file admin/post.php is called. I checked and found out that is_user_logged_in() returns true in this file.

    Why does it return false inside query.php? I am logged in…

    Is there a function that logs off the user when calling this file?

    for me the problem appeared when i activated, try to activate theme_test_drive plugin.
    it was solved when i deleted the plugin

    i had the same problem with theme-tester – had to delete it desactivate it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘wp_get_current_user not working in 2.9?’ is closed to new replies.