Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Login To Bottom of Forums and Topics


  • yoyoma1974
    Participant

    @yoyoma1974

    I’d like to add a login area just beneath the Topics in a Forum and beneath the replies in Topics so non-logged in members have a smoother experience. So just below where it says “You must be logged in to reply to this topic.” I’d like a login area. Is this possible without extensive editing to files?

    Thanks for any help on this.

    Tim

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

  • tharsheblows
    Participant

    @tharsheblows

    Are you using a custom bbpress template in your theme? You will need to edit some files in there if so. I don’t think there’s another way, although you might look to see if there’s a plugin that does it.


    yoyoma1974
    Participant

    @yoyoma1974

    I searched for a plugin but couldn’t find anything like that, bummer. hmmm, not sure if were using a custom bbpress template. I don’t think so. If we’re not using a custom template would we need to create one? Then I imagine copy and past the login code at the bottom of that file?


    caothanhtrung87
    Participant

    @caothanhtrung87

    i think you should find a plugin to do this. You should’nt edit HTML because that so bad


    yoyoma1974
    Participant

    @yoyoma1974

    ok, but there don’t seem to be any plugins that specifically add the login to the bottom of the topics/forum pages, unless I missed it but I did a lot of searching. Maybe there’s another plugin that would allow me to add the Login shortcode to the bottom area of the Topics/Forums templates?


    tharsheblows
    Participant

    @tharsheblows

    Editing the template files is fine – that’s one of the big draws of open source to me.

    If you add this to your current theme’s functions.php file, you should get login forms for non-logged in users in the appropriate places. NB: never ever edit your functions.php file through the WordPress admin area – you need to have ftp access or your access to your hosting control panel (ie independent of WordPress) so you can undo whatever you’ve just done in case it all goes wrong.

    I can try to explain where the functions.php file is but I do tend to make people more confused sometimes so won’t unless you ask!

    //this adds the login form on a single topic so someone can leave a reply. It uses the same logic as form-reply
    function mjj_new_reply_login(){
    	if( !bbp_current_user_can_access_create_reply_form() && !bbp_is_topic_closed() && !bbp_is_forum_closed( bbp_get_topic_forum_id() ) ){
    		bbp_get_template_part('form', 'user-login');
    	}
    }
    
    add_action('bbp_template_after_single_topic', 'mjj_new_reply_login');
    
    //this adds the login form on a single forum so someone can start a topic. It uses the same logic as form-topic
    function mjj_new_topic_login(){
    	if( !bbp_current_user_can_access_create_topic_form() && !bbp_is_forum_closed() ){
    		bbp_get_template_part('form', 'user-login');
    	}
    }
    
    add_action('bbp_template_after_single_forum', 'mjj_new_topic_login');

    yoyoma1974
    Participant

    @yoyoma1974

    Thanks tharsheblows! That works perfectly. I thought I might also add a “Register here” link beneath that but I guess just adding an echo statement within the if statement is not the way to do this, it didn’t get outputted.

    function mjj_new_reply_login(){
    if( !bbp_current_user_can_access_create_reply_form() && !bbp_is_topic_closed() && !bbp_is_forum_closed( bbp_get_topic_forum_id() ) ){
    bbp_get_template_part(‘form’, ‘user-login’);
    echo ‘Register here‘;
    }
    }


    tharsheblows
    Participant

    @tharsheblows

    Oh good! That should work, actually. If I had done that and it didn’t work for me, it would have been because I only added it to one function and not the other, so maybe check that… :)

    Here is the full code with “Register here” linked to /register-now -

    //this adds the login form with a register here link underneath on a single topic so someone can leave a reply. It uses the same logic as form-reply
    function mjj_new_reply_login(){
    	if( !bbp_current_user_can_access_create_reply_form() && !bbp_is_topic_closed() && !bbp_is_forum_closed( bbp_get_topic_forum_id() ) ){
    		bbp_get_template_part('form', 'user-login');
    		echo '<a href="/register-now">Register here</a>';
    	}
    }
    
    add_action('bbp_template_after_single_topic', 'mjj_new_reply_login');
    
    //this adds the login form with a register here link underneath on a single forum so someone can start a topic. It uses the same logic as form-topic
    function mjj_new_topic_login(){
    	if( !bbp_current_user_can_access_create_topic_form() && !bbp_is_forum_closed() ){
    		bbp_get_template_part('form', 'user-login');
    		echo '<a href="/register-now">Register here</a>';
    	}
    }
    
    add_action('bbp_template_after_single_forum', 'mjj_new_topic_login');

    yoyoma1974
    Participant

    @yoyoma1974

    Awesome, that works. Thanks again!

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

You must be logged in to reply to this topic.