• Resolved saphod

    (@saphod)


    Hi,

    I want to show some links in the sidebar of my page only if I am logged in, e.g. “New Post”, “Edit Theme”, “Manage” etc., so that I have direct access and do not have to go via the admin panel – saves some clicks, you know. ??

    First, I tried

    <?php if (!$user_ID) { ?>
    (I would set up the link list here)
    <? } ?>

    That didn’t work, meaning the link list would not show up at all.

    Then, I tried

    <?php if (!$user_login) { ?>
    (I would set up the link list here)
    <? } ?>

    That didn’t work either, because now the list would show up even with me not being logged in.

    FORGET IT!
    I just realized the “!” = NOT in front of the variable… DAMN!

    Rechecked and edited…
    but erasing “!” does not change anything: the list would not show up…

    Any suggestions?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter saphod

    (@saphod)

    Hi…. anyone, please?

    Thread Starter saphod

    (@saphod)

    OK, I surrender… ??

    It’s a bit of code with which some PHP developer can help you… I’d search for something in the code which will be like “If user logged in, then…”, then would re-use this bit of code to make your little bit of magic work ??

    Use trial and error ?? I am not so proficient in PHP as to help you easily… I’m afraid :-/

    PS OK, after a quick test, here’s what I came up with:

    <?php
    if ( is_user_logged_in() ) {
      echo "(Put your stuff here! Like,
      (I would set up the link list here - no problems...)";
      }
    ?>

    You can modify it at your own ease, to suit your needs. I know this is not the best way to implement it, but it works. I checked, logged in and logged out, the “if” statement worked OK.

    Try it! ??

    My $ 0.02 ??

    Thread Starter saphod

    (@saphod)

    Hi lelion!

    Your code works – just the way I wanted it to work!

    The problem with my code was that I did not define $User_ID – you have to set it as a global variable and then use get_currentuserinfo(), as I have just found out.

    Anyway, your way is less complicated, and I will use that one. Thank you very much!

    You’re welcome!

    I’m glad my 0.01% ability to read PHP scripts helped in this case ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How can I check if I am logged in?’ is closed to new replies.