Skip to:
Content
Pages
Categories
Search
Top
Bottom

User user id instead of login in profile url


  • coopersita
    Participant

    @coopersita

    Is there a way to redirect all profile page links so they use the user id, instead of user login/nicename? Some users have their email as their username, so we want to hide it.

    So to go from
    /forums/users/{login}

    to
    /forums/users/{id}

    I was able to change the URLs so they point to the right place:

    function bbp_custom_author_link(  $url,  $user_id,  $user_nicename){
                $url = site_url()."/forums/users/".$user_id;
    	   return $url;
        }
        add_filter( 'bbp_get_user_profile_url', 'bbp_custom_author_link', 10, 3);

    But once you click on the link, you end up in a 404.

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

  • Robin W
    Moderator

    @robin-w

    no easy solution – basically wordpress lets you login with your email so users can still login using email address if their have a different username. So if you need this as a solution then your registration process should not allow users to use their email as username or warn them that if they do it will be public.

    You can change any existing ones using

    How to Change a Username on WordPress


    coopersita
    Participant

    @coopersita

    Thanks, but unfortunately, the registration is being done via another plugin (we do bulk registration for courses using a CSV file, and the plugin uses the email to create the logins).

    I think that if I can add a rewrite rule so the user id also redirects to the profile page, that would be enough.

    I’ll post here if I find a solution.


    Robin W
    Moderator

    @robin-w

    ok


    coopersita
    Participant

    @coopersita

    I haven’t made much progress. I tried adding a rewrite rule and changing from ‘users’ from ‘members’ to avoid rules clashing:

    function bbp_custom_author_rewrite(){
        add_rewrite_rule(
            "^forums/members/([^/]*)$",
            'index.php?bbp_user=$matches[1]',
            "top"
        );
    }
    add_action( 'init', 'bbp_custom_author_rewrite', 10);

    But I think I’m missing the part where the template uses the query var to load the correct content because I keep getting 404 errors.

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