WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Incorrect redirect address for users names with space. (BuddyPress)

[Resolved] Incorrect redirect address for users names with space. (BuddyPress)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Chris Dillon
    Participant

    @cdillon27

    You can accomplish this with a filter. Add this to your theme’s functions.php:

    function hyphenate_username_function( $bool, $variable, $user )
    {
      if( 'hyphenate_username' == $variable )
      {
        return sanitize_title( $user->user_login );
      }
    }
    add_filter( 'rul_replace_variable', 'hyphenate_username_function', 10, 3 );

    Then instead of [variable]username[/variable]
    use [variable]hyphenate_username[/variable].

    You can name that function and variable whatever you want.

    Codex: sanitize_title and sanitize_title_with_dashes

    BackpackersUnion
    Member

    @backpackersunion

    Hi Chris, really appreciate you looking into this.

    I implemented the changes, and it seems the function removed the name from the URL. The result was;
    …/members//profile/

    and a page not found message. When using a non space username (i.e. “carl”), it redirected correctly.

    I looked at the codex, but modifying functions are still a little outside my skill set, but appreciate you including them.

    Do you have any other thoughts on how to get this working. Thanks again.

    BackpackersUnion
    Member

    @backpackersunion

    BTW – wpmission.com is a cool site idea. Ended up checking out all your “favorite plugins” in your wp profile and found a few new ones to try. Looking forward to seeing your launch.

    Chris Dillon
    Participant

    @cdillon27

    Thanks!

    Sorry it didn’t work. I admit I didn’t test that filter very well. Let me work on it.

    Chris Dillon
    Participant

    @cdillon27

    The profile address in BuddyPress is like

    http://example.com/members/username/profile/

    so the filter should be

    function hyphenate_username_function( $bool, $variable, $user )
    {
      if( 'hyphenate_username' == $variable )
      {
        return $user->user_nicename );
      }
    }
    add_filter( 'rul_replace_variable', 'hyphenate_username_function', 10, 3 );

    (notice the nicename which is an already-hyphenated version of their username instead of the sanitize_title function I previously used)

    and the redirect rule becomes

    members/[variable]hyphenate_username[/variable]/profile

    BackpackersUnion
    Member

    @backpackersunion

    That did the trick! You have no idea how much I appreciate your help.

    And thank you for explaining your work. Functions give WordPress so much versatility but I haven’t been able to wrap my head around them. So, still working on them and every tip helps.

    Quick note for anyone else having this problem; At first I received a “Parse error: syntax error”, with luck noticed one less ‘(‘ than the previous code. I guessed on the placement in Chris’s code and got this,

    function hyphenate_username_function( $bool, $variable, $user )
    {
      if( 'hyphenate_username' == $variable )
      {
        return( $user-> user_nicename );
      }
    }
    add_filter( 'rul_replace_variable', 'hyphenate_username_function', 10, 3 );

    Added it right after “return”. The error went away and Chris’s code worked beautifully, but I have no idea if that’s the correct placement.

    Thanks again Chris! I just signed up for your mailing list. Looking forward to it.

    Chris Dillon
    Participant

    @cdillon27

    Sorry for the typo. Glad you got it working. It should actually be

    return $user->user_nicename;

    without a space after -> and without parentheses.

    I’m working on an add-on plugin for Peter’s plugin and I will include this function.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Incorrect redirect address for users names with space. (BuddyPress)’ is closed to new replies.