Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Login To Bottom of Forums and Topics

Viewing 11 replies - 1 through 11 (of 11 total)
  • @tharsheblows

    Participant

    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

    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

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

    @yoyoma1974

    Participant

    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

    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

    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

    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

    Awesome, that works. Thanks again!

    @ivurs

    Participant

    Hello,

    It doesnt work, I add these code in the end of functions.php file

    but get an error of this file and make the website cannot be accessed

    Please provide more guidance, thanks!

    @casiepa

    Moderator

    Hi,
    What are the last 3 lines of your working functions.php ?
    Pascal.

    @lijitimit

    Participant

    Old topic to be chiming in on but this helped a lot, thanks @tharsheblows!

    I changed it up to simply add buttons to the pages instead of the login form, and made sure that upon login, it redirected back to the topic or forum.

    //this adds the login and register links 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() ) ){ ?>
    		<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
                    <a href="<?php echo wp_registration_url(); ?>">Register</a>
    <?php
    	}
    }
    
    add_action('bbp_template_after_single_topic', 'mjj_new_reply_login');
    
    //this adds the llogin and register links 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() ){ ?>
    		<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
                    <a href="<?php echo wp_registration_url(); ?>">Register</a>
    <?php
    	}
    }
    
    add_action('bbp_template_after_single_forum', 'mjj_new_topic_login');

    I personally did them as buttons, if you have a .button class just add class="button" between <a and href=.

    Hope that helps someone in the future.

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar