Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] replace %20% usernames with a dash (-) in URL?

  • Avatar of franzvz
    franzvz
    Participant

    @franzvz

    Hello,

    I converted to BuddyPress/bbPress from Invision. And usernames that were with spaces (eg Bob Smith). gave 404s when they clicked on their profiles.

    Then someone suggested to do this

    define( ‘BP_ENABLE_USERNAME_COMPATIBILITY_MODE’, true );

    And it worked. However is there a way to nicely display a username? /bob%20%smith/ looks so ugly. /bob-smith/ looks much better.

    I have a fairly small user base, only about 10 maybe have spaces in their names. I wouldn’t mind doing some manual editing in phpMyAdmin if I can find what to edit.

    Then does future accounts fix themselves if a user choose a space in their name? Or is that not allowed in the default BuddyPress registration?

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of Halo Diehard
    Halo Diehard
    Participant

    @halo-diehard

    I just found this thread, and I have the exact same issue. So glad there is a fix, but I don’t know where to put this that was posted above:

    define( ‘BP_ENABLE_USERNAME_COMPATIBILITY_MODE’, true );

    Also, like is asked above, if anyone knows how to fix the url afterwards from %20% to a hyphen for spaces in the name, like what BuddyPress does, that would be amazing.

    Yes, I can do database edits, if I know what needs to be changed.

    Thanks :D

    Avatar of danbp
    danbp
    Moderator

    @danbp

    Hi @halo-diehard,

    put it into bp-custom.php

    Reference:

    http://codex.buddypress.org/getting-started/customizing/changing-internal-configuration-settings/

    The %20 sanitizing thing is already used. And answer is in the snippet.

    This is actually in /bp-legacy/buddypress-functions.php

    if ( ! empty( $user_query->results ) ) {
    foreach ( $user_query->results as $user ) {
    if ( bp_is_username_compatibility_mode() ) {
    // Sanitize for spaces. Use urlencode() rather
    // than rawurlencode() because %20 breaks JS
    $username = urlencode( $user->user_login );
    } else {
    $username = $user->user_nicename;
    }
    Avatar of Halo Diehard
    Halo Diehard
    Participant

    @halo-diehard

    Thanks so much for your response! First I created bp-custom.php and pasted define( ‘BP_ENABLE_USERNAME_COMPATIBILITY_MODE’, true ); into it, then I put it in my plugins folder, and I got the same 404 except this text was across the top of the page:

    define( ‘BP_ENABLE_USERNAME_COMPATIBILITY_MODE’, true );
    Warning: Cannot modify header information - headers already sent by (output started at /homepages/33/(database here)/htdocs/(mywordpressfolder)/wp-content/plugins/bp-custom.php:1) in /homepages/33/(database here)/htdocs/(mywordpressfolder)/wp-includes/pluggable.php on line 1121

    By sheer luck I recognized that the ‘ and ‘ were the curly ones, and I had JUST read about that last week, so I deleted the apostrophe’s and typed them in myself in notepad++, crossing my fingers. But when I saved and ftp’d the new file, I had the same thing across the top, just with the fixed code!

    define( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE', true );
    Warning: Cannot modify header information - headers already sent by (output started at /homepages/33/(database here)/htdocs/(mywordpressfolder)/wp-content/plugins/bp-custom.php:1) in /homepages/33/(database here)/htdocs/(mywordpressfolder)/wp-includes/pluggable.php on line 1121

    I went and took a peek at pluggagle.php, line 1121, and it is the third line up from this:

    	/**
    	 * Filter the redirect status code.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param int    $status   Status code to use.
    	 * @param string $location The path to redirect to.
    	 */
    	$status = apply_filters( 'wp_redirect_status', $status, $location );
    
    	if ( ! $location )
    		return false;
    
    	$location = wp_sanitize_redirect($location);
    
    	if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )
    		status_header($status); // This causes problems on IIS and some FastCGI setups
    
    	header("Location: $location", true, $status);
    
    	return true;
    }
    endif;

    So 1121 is this bit: header("Location: $location", true, $status);

    That block of code is just above “Sanitizes a URL for use in a redirect”, using function wp sanitize redirect.

    Not sure if any of that points to any clear problem, but it’s pretty much Greek to me :(

    Avatar of danbp
    danbp
    Moderator

    @danbp

    You asked how to fix %20 issue.

    The BP response to that is: // Use urlencode() rather than rawurlencode().
    I you hav suche %20 in some url’s, you have to find what is genrate it. Or go into the DB and remove the spaces manually. This means searching all %20 occurence.

    if anyone knows how to fix the url spaces in the name, like what BuddyPress does, that would be amazing

    Does this means that you use something, but not BP, who create such space mark ? A custom theme perhaps, or a plugin ?

    Theme name and plugin list, please ! ;-)

    Avatar of Halo Diehard
    Halo Diehard
    Participant

    @halo-diehard

    If you see the first post, you will find that the issue begins when the members are imported from another forum type. Apparently my conversion issue was different than the original poster. After finally tracking down the issue, I learned that during *my* conversion, something happened where the nice name was entered without a dash, so:

    Tom Thumb instead of Tom-Thumb

    This was resulting in the 404 when visiting the profile page, although the member could log in and post.

    I finally found a fix, and that was to go into the database, find the nicename and change it, replacing the space with a dash. Fortunately for me, there were only about 20 of them ;)

    Now that there are no spaces, I don’t have the %20 issue anyway.

    Avatar of danbp
    danbp
    Moderator

    @danbp

    Glad you got it to work !

    Apparently my conversion issue was different than the original poster.

    For the next question, open preferably a new topic instead of jumping an old one. ;-)

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

The topic ‘[Resolved] replace %20% usernames with a dash (-) in URL?’ is closed to new replies.