Skip to:
Content
Pages
Categories
Search
Top
Bottom

Login, Register, Lost Password links


  • mica123
    Participant

    @mica123

    I know that similar questions have been asked many times – unfortunately I have not found any satisfactory answers – I very much hope for your help as follows:
    I set up Forums on full page widths without sidebars.
    I would like to have the login, register and lost passwords links at the top of
    the forum page the same way as bbPress Support forum has – I am not referring to menu links.
    Can you please help?
    Many thanks.

Viewing 25 replies - 1 through 25 (of 27 total)

  • mica123
    Participant

    @mica123

    Actually, I can see that this bbPress support forum created a submenu showing the login, register and lost passwords links at the top of the index page. So I take it that this was done with the help of CSS.


    Robkk
    Moderator

    @robkk

    On this site it is custom links in the WordPress toolbar.

    You can follow this tutorial to add custom links to the admin bar.

    http://www.wpbeginner.com/wp-tutorials/how-to-add-custom-shortcut-links-to-wordpress-toolbar/

    There is also this plugin that can add links above forum pages.

    https://wordpress.org/plugins/bbpress-login-register-links-on-forum-topic-pages/

    And also you could just place the bbPress login widget in a sidebar you have and input additional authentication links in the widgets input fields.


    mica123
    Participant

    @mica123

    Thank you very much for this. It seems I haven’t explained this very well.
    I would like to have these links on the frontend of the Forum Index page for participants who should not have access to the backend at all.
    I had a look at the plugin but my pages are full width as I don’t want to use the sidebar.
    Is there another way of doing this?
    Many thanks.


    Robkk
    Moderator

    @robkk

    I listed 3 different choices you could do. What you are looking for might be in the plugin I listed.


    mica123
    Participant

    @mica123

    Hello

    After experimenting with all your suggestions I think I would like to use the code from
    https://codex.bbpress.org/layout-and-functionality-examples-you-can-use/ #11.This redirects both logged in and not logged in users to specific pages which is what I want.
    This works partially – I am trying to attach it to my second menu – not the primary menu but whathever I try it doesn’t work. If I leave the code as it is, it displays the links on both menus. I tried to use
    if ($args->theme_location == 'sub-header-menu')
    in various places such as:
    if(is_bbpress() && $args->theme_location == 'sub-header-menu')

    I would need this for both logged in and not logged in users.
    Thank you very much for your patience. I hope you can help.


    Robkk
    Moderator

    @robkk

    Try using something like the menu slug instead. Just type in the name you entered of the menu in lowercase each space is a _.

    && $args->menu->slug == 'name_of_menu')


    mica123
    Participant

    @mica123

    Many thanks for your infinite patience. I am afraid it didn’t work.
    I have to give up and get a plugin. Many thanks again.


    Robkk
    Moderator

    @robkk

    You could post the code you are using so I can double check to see how it is if you still want to do this manually without a plugin.


    mica123
    Participant

    @mica123

    When I use this code without the
    if(is_bbpress() && $args->theme_location == 'sub-header-menu')

    it works but I get the links on both menus. Below is the code I tried to use for the second menu only – the second menu is called Logins – I tried to use both sub-header-menu or logins.
    I tried your suggestion with both as well.

    add_filter( 'wp_nav_menu_items', 'my_nav_menu_login_link' );
    function my_nav_menu_login_link($menu) {
        //uncomment the next line if you only want login on bbpress pages
    
       if(is_bbpress() && $args->theme_location == 'sub-header-menu')
        if (is_user_logged_in()) {
            //set the $url on the next line to the page you want users to go back to when they logout
            $url = '$url = 'http://www.mysite.com/forums';
            $url2=wp_logout_url($url) ;
            $loginlink = '<li><a title="Logout" href="'.$url2.'">Logout</a></li>';
            }
        else {
            $current_user = wp_get_current_user();
            $user=$current_user->user_login ;
            //set $page on the next line = the permalink for your login page
            $page=''login' ;
            $loginlink = '<li><a href="/'.$page.'/">Login</a></li>';
                    }
         //uncomment out the next lines if you only want login on bbpress pages
       }
        else {
       $loginlink="" ;
          }
            $menu = $menu . $loginlink;
            return $menu;
            }

    Robkk
    Moderator

    @robkk

    You did try it like this right??

    if(is_bbpress() && $args->menu->slug == 'sub_header_menu')

    If it still doesn’t work you can try finding the menu location in your theme, which might most likely be in the functions.php file, but it could be different depending on the theme. You would spot by the register nav menu function like what is listed in this page.

    https://codex.wordpress.org/Function_Reference/register_nav_menus

    If you have a free theme I could check it out and get the arguments you need.


    mica123
    Participant

    @mica123

    @robkk yes I tried it like this – nothing shows up.
    My free theme is Responsive (not Responsive II) from Cyberchimps.
    I would really appreciate it if we could get to the bottom of it.
    All this works only if I use the code as it is without the menu location but the links go to both menus.
    Thanks.


    mica123
    Participant

    @mica123

    @robkk, further to my previous reply: perhaps I could hide the link on the main menu with CSS if we can’t get it to work.
    I was also wondering if the code could include a line to redirect the user to the forum page after login? Could the code also include links for Register and Lost Password?


    Robkk
    Moderator

    @robkk

    This should show the items in the specific menu.

    add_filter( 'wp_nav_menu_items', 'rkk_add_auth_links', 10 , 2 );
    function rkk_add_auth_links( $items, $args ) {
        if (is_user_logged_in() && $args->theme_location == 'sub-header-menu') {
            $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'sub-header-menu') {
            $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
            $items .= '<li><a href="'. site_url('wp-login.php?action=register') .'">Register</a></li>';
            $items .= '<li><a href="'. site_url('wp-login.php?action=lostpassword') .'">Lost Password</a></li>';
        }
        return $items;
    }

    By default it leads to the regular wordpress login form. if you want to change that to a frontend page, you can change this site_url('wp-login.php') to something like this site_url('/login/').

    login redirect you would need to use something like this.

    function rkk_login_redirect($redirect_to, $request, $user) {
        return (is_array($user->roles) && in_array('administrator', $user->roles)) ? admin_url() : site_url('/forums/');
    } 
    add_filter('login_redirect', 'rkk_login_redirect', 10, 3);

    This login redirect code redirect admins to the WordPress backend, but anything else to the forums.


    mica123
    Participant

    @mica123

    That’s great – thanks very much. I am learning a lot with your help. Very much appreciated.


    mica123
    Participant

    @mica123

    @robkk I have now tried your code and it works beautifully. The links show up in the sub-header-menu. The login and logout redirect works too. As I am trying this out on my local computer I don’t know if the reset and lost password redirect would work as well?

    There is another problem: if I click on login or reset or lost password button without giving a user name and password, it goes to the standard WordPress login page which is not good at all. Can this be remedied? We are almost there.
    Many, many thanks.


    Robkk
    Moderator

    @robkk

    Are you trying to use the bbPress shortcodes in pages for logging in and registering??

    These forms are really incomplete in functionality, they don’t redirect back to the login form and show error messages above that form, it just redirects to the default WordPress form to show the error messages. I think using the default WordPress forms or other frontend forms are better for now.


    mica123
    Participant

    @mica123

    Yes, I am using the bbpress forms. Where would I find the default WordPress forms? Also, by other frontend forms – I am not sure what you mean? It is just difficult for me to understand that by not using the bbpress forms, redirects will show error messages without any code?


    Robkk
    Moderator

    @robkk

    In the code I posted the menu links should lead to the default WordPress forms.

    Login, Register, Lost Password links

    Other plugins can add frontend forms like Theme My Login, woocommerce, some other membership plugins.

    I am basically saying the bbPress forms are incomplete in functionality, it might be better to use something else like the default WordPress forms.


    mica123
    Participant

    @mica123

    @robkk
    Thank you so much. I finally got the wp-login forms working. I even managed to style them by enqueuing the login style sheet. Here I have a question – I used the following:

    function my_login_stylesheet() {
        wp_enqueue_style( 'custom-login', get_template_directory_uri() . '/style-login.css' );
        wp_enqueue_script( 'custom-login', get_template_directory_uri() . '/style-login.js' );
    }
    add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );

    This is fine, but the style sheet is loaded in my theme directory (responsive). I tried to load it into my child theme (responsive-child-theme) but it doesn’t work. Is the maian theme directory the correct location? What happens if the theme is updated?

    All this is new to me as I never set up a forum before, just websites. I am concerned about security. I am going to install Akismet. Should I also do something about honeypot registration? If so, what would you recommend? Would you also recommend reCaptcha? If so, what would be the best way to implement it?
    Many thanks.


    mica123
    Participant

    @mica123

    Hello @robkk,

    I am afraid I discovered another problem which I discuss here.
    Would you be able to advise me on this? I very much hope so.


    Robkk
    Moderator

    @robkk

    To enqueue files in your child theme use get_stylesheet_directory_uri.

    Put the custom login stylesheets into your child theme named style-login.css or whatever you want to call it, and in the function use get_stylesheet_directory_uri instead of template_directory.

    https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

    Will check out the other topic in a minute.


    mica123
    Participant

    @mica123

    Many thanks, yes, it worked. Hope to hear from you regarding the other topic.


    Robkk
    Moderator

    @robkk

    its no problem, your welcome 🙂


    mica123
    Participant

    @mica123

    Hello,

    I hope you won’t mind if I come back to this topic. Everything works with the login and logout links – both redirecting to a certain page. I added the profile link to the menu which shows up after a user login (taken from Layout and functionality – Examples you can use as follows:

    function rk_bbp_menu_profile_link( $items, $args ) {
    
        if( is_user_logged_in() && $args->theme_location == 'sub-header-menu')  {
    
    		
    
    	$current_user = wp_get_current_user();
    
            $user = $current_user->user_nicename;
    
    	$profilelink = '<a href="/ihabbpress/tenant-forums/users/' . $user . '/">Your Profile</a>';
    
            $items .=  '<li>' . $profilelink .  '</li>';
    
    	}
    
        return $items;
    
    }

    This is fine except that when the user logs out, he/she stays on the same profile page
    he/she had been on before logging out. This is not good – users should be redirected to a specific page. I thought that this code would automatically inherit the redirection link from the Logout code. Many thanks.


    mica123
    Participant

    @mica123

    Hello again,

    many apologies for causing a misunderstanding here. All the login/logout links work. I was only asking about the profile link after logout – this is also fine. My question can be ignored.

    Many apologies to @robkk. The profile link code is his – taken from How to add user profile link to specific menu

    Thanks.

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