WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $user_ID unavailable in sidebar.php ? (8 posts)

  1. RangerRoman
    Member
    Posted 7 years ago #

    The bigger picture is simply a different looking sidebar for when a user is logged in.

    The problem is that I can't seem to access $user_ID in my sidebar.php file. I'm stumped.

    I'm using the following two lines to help me figure this out:

    User identity: <?php echo $user_identity; ?><br/>
    User ID: <?php echo $user_ID?><br/>

    When I put them in index.php, they return a value. Even when I put them immediately before <?php get_sidebar(); ?>.

    But inside sidebar.php they return nothing.

    I'm not using any plug-ins.
    Any ideas?

    Thanks,
    Roman

  2. MichaelH
    Member
    Posted 7 years ago #

    This function might help: Function_Reference/get_currentuserinfo

  3. RangerRoman
    Member
    Posted 7 years ago #

    Thanks, but it doesn't seem to help. I use the following lines:

    User Identity: <?php echo $user_identity; ?><br/>
    User ID: <?php echo $user_ID?><br/>
    User login: <?php echo $user_login?><br/>
    User level: <?php echo $user_level?><br/>
    User url: <?php echo $user_url?><br/>
    User_pass_md5: <?php echo $user_pass_md5?><br/>
    User identity: <?php echo $user_identity?><br/>

    In index.php, right before get_sidebar(), they all have values.

    In sidebar.php, nothing. :(

    -Roman

  4. Kafkaesqui

    Posted 7 years ago #

    Make sure to scope the variables as global. Example:

    <?php global $user_identity; echo $user_identity; ?>

  5. RangerRoman
    Member
    Posted 7 years ago #

    I've betrayed my inexperience. Thank you very much for that simple fix.

    -Roman

  6. bear133
    Member
    Posted 7 years ago #

    This dose not work for me. I put:

    <?php global $user_identity; echo $user_identity; ?>

    in sidebar.php but it gave me nothing. I also tried putting it in index.php nothing happened. But when i putt it in comments.php i get the value.

    Any one got a clue?

  7. bear133
    Member
    Posted 7 years ago #

    Hmm ok here is some more strange strange stuff. When i put it in the sidebar and go to a post. I can see the value. But when i view the site from the index page the value is gone from the sidebar. Same goes for page. But when searching or browsing an archive the value appears in the sidebar.

  8. bear133
    Member
    Posted 7 years ago #

    problem solved. a little mix up with subdomain and without the subdomain.

Topic Closed

This topic has been closed to new replies.

About this Topic