Skip to:
Content
Pages
Categories
Search
Top
Bottom

Check if a user is logged in?

  • I would like to display some content only when a user is logged into the forums, how can I do this in the template?

Viewing 16 replies - 1 through 16 (of 16 total)
  • It can do done with IF and User ID.

    I do not know the file that deals with user login but something like this should work:

    If $user_id = 4;

    echo “what ever you want to show to user #4″

    are you running integration with wordpress?

    In regards to Mirce’s solution, I would think a more global (and simpler) solution would be this if statement:

    <?php if ( bb_is_user_logged_in() ) { ?>;
    --PUT WHATEVER YOU WANT THEM TO SEE HERE--
    <?php } ? >

    This way you don’t need to find out WHO the user is (user_id), but simply whether or not they’re logged in.

    I’m pretty new to this, though, so maybe Mirce knows something I don’t?

    Yes, macwise gave a better solution. I was thinking that FofR wants to show something when a specific user is logged.

    I am new to and I think that your solution is better.

    I am personally tired of having information up to Bozo’s, so I like to use:

    <?php if (bb_current_user_can('write_posts')) : ?>
    DO SOMETHING
    <?php endif; ?>

    That way, the users who are members see the content and spammers cannot! (At least I think not….not going to mark myself as BOZO to find out)

    Trent


    parthatel
    Member

    @parthatel

    That doesn’t work when I add that to my WordPress (it has integrated functions). Nothing appears when I added the code. Also, what is the code to display content if user is logged in, else (if not logged in) display some other content.


    chrishajer
    Participant

    @chrishajer

    parthatel can you post your code here?

    What function are you using to check if the user is logged in? Does it error out or does it just not display any content (if it does not error, then the function is probably a valid function.)

    And showing one content for logged in members and other content for other members is pretty basic PHP:

    <?php
    if (bb_is_user_logged_in() ) {
    echo "You are logged in.n";
    }
    else {
    echo "You are not logged in.n";
    }
    ?>

     

    I’m 99% certain that is the proper function name, and the code will work.


    parthatel
    Member

    @parthatel

    chrishajer, the code you gave me worked. (I barely saw the “Y” in the “You are logged in” hiding behind my main content). So I guess that the code I tried before worked, only that it was hidden behind my main content so I didn’t see it.

    Thanks.


    Shagalaga
    Member

    @shagalaga

    And How to check if a user is logged out?

    eg i want to turn off Ads, if somebody is logged in and show it, when they are not logged in


    chrishajer
    Participant

    @chrishajer

    The code above handles both cases, you’re logged in or you’re logged out. There is no in between. If one is true, the other is false.

    <?php
    if ( bb_is_user_logged_in() ) {
    echo "No ads for you!n";
    }
    else {
    echo "Here is an ad, buy now!n";
    }
    ?>

     

    You could also just check to see if they’re not logged in like this:

    <?php
    if ( !bb_is_user_logged_in() ) {
    echo "Here is an ad, buy now!n";
    }
    ?>

     

    The exclamation in front of the function says “if this is NOT true, then the if statement is true; continue.)


    Shagalaga
    Member

    @shagalaga

    thx! it works!


    curtisdroppelman
    Member

    @curtisdroppelman

    I realize this is old but what if I want to have this same function on my wordpress homepage?

    Basically, how do I get the log logged-in.php / login-form.php functions though wordpress to match BBpress?


    Ashfame
    Participant

    @ashfame

    if you are using WP 3.0, then it has a function to call for login form. use that and if you are not running WP 3.0 then to use such a thing you need to have deep integrated setup which is not recommended and in case you already are, you can use that.

    Another option will be to build a normal login form and make it to send data to the bbPress, search for it, there was a thread about it recently.

    and if you just want to check if user is logged in, then WP has a function is_user_logged_in()


    curtisdroppelman
    Member

    @curtisdroppelman

    Thanks for the quick reply Ash!

    I was in a hurry last night and went with an iFrame solution hosted inside the bbPress folder and placed it inside my wordpress theme, that worked pretty well. When I redesign the site I’ll be sure to use this function, it looks awesome!

    -Curtis


    curtisdroppelman
    Member

    @curtisdroppelman

    I started coding a plugin to do exactly what I asked before, I found this page very helpful. http://codex.wordpress.org/Function_Reference/get_currentuserinfo

    I’ll post a link to the plugin when I’m finished.

    -Curtis

    http://twitter.com/curtis

    I want to hide page links in my main header navigation from non registered members, then have them show up after the user has logged in.

    I’m currently using custom menu manager and wp-members for plugins. The custom menu manager allows me to set which page links show up in the assigned navigation menu (ie: only “about” and “register” are shown on home page the other page links are hidden), but it doesn’t recognize whether the user is logged in or not and the hidden page links are not shown after you’ve logged in still. With wp-members plugin I have the “members” and “project” pages set to block access unless logged in, but this only effects the page access, the nav link for those pages were still showing up in the main navigation until I used the menu manager plugin which hid them totally not conditionally based on log in status which is what I want.

    Is there a php block of code to use or plugin you guys recommend that handles nav link access/visibilty based on log in status? I’m at total loss. Please help me. Visit my site mks76.com/wp/

Viewing 16 replies - 1 through 16 (of 16 total)

You must be logged in to reply to this topic.