bbPress

Simple, Fast, Elegant

bbPress support forums » Themes

Check if a user is logged in?

(9 posts)
  • Started 1 year ago by FofR
  • Latest reply from parthatel
  • This topic is resolved
  1. FofR
    Member

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

    Posted 1 year ago #
  2. 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"

    Posted 1 year ago #
  3. are you running integration with wordpress?

    Posted 1 year ago #
  4. 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?

    Posted 1 year ago #
  5. 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.

    Posted 1 year ago #
  6. 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

    Posted 1 year ago #
  7. parthatel
    Member

    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.

    Posted 1 month ago #
  8. 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.

    Posted 1 month ago #
  9. parthatel
    Member

    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.

    Posted 1 month ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.