Skip to:
Content
Pages
Categories
Search
Top
Bottom

How To Change PERMALINK?


  • tazogamer
    Participant

    @tazogamer

    Hello.
    How to change user’s permalinks (profile page urls), from nicename to ID’s:
    mysite.com/forums/user/Mike-jovanr

    to

    mysite.com/forums/user/99

    ???

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

  • Robin W
    Moderator

    @robin-w

    It’s do-able undoubtably, but not sure how much code you’d need to change.

    Why are you wishing to do this?


    tazogamer
    Participant

    @tazogamer

    I WANT IT.
    HOW TO DO THAT?


    Robin W
    Moderator

    @robin-w

    you don’t actually need to change the permalinks eg is Kazza were user 15

    http://www.mysite.com/forums/users/15/edit/

    works just as well as

    http://www.mysite.com/fourms/users/kazza/edit

    so you’d need to change how the profile page is called so that it displays the no. in the url.

    Given that profile is called from

    any topic or reply display (click the avatar or author name)
    several widgets (click the avatar or author name)
    possibly other areas

    you’d need to re-code these areas.

    the function bbp_reply_author_link is used for topic and reply display, not sure if widgets use that as well.


    tazogamer
    Participant

    @tazogamer

    Robin W! Thanks so much! Your answers led me to the solution:
    in functions.php , i have added(with add_filter) a modified “bbp_get_user_profile_url” function,which generates profile urls (original is in bbpress\includes\users\template.php):

    here is my code:

    remove_filter( 'bbp_get_user_profile_url', 'bbp_get_user_profile_url');
    add_filter('bbp_get_user_profile_url','my_replaced' , 10 ,4);	
    function my_replaced ($url, $user_id, $user_nicename = '' ){
    	global $wp_rewrite;
    	if ( empty( $user_id ) ) {return false;}
    	$early_profile_url = apply_filters( 'bbp_pre_get_user_profile_url', (int) $user_id );
    	if ( is_string( $early_profile_url ) ) {   return $early_profile_url; }
    	if ( $wp_rewrite->using_permalinks() ) { 	// if pretty permalinks
    		$url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%';
    		if ( empty( $user_nicename ) ) { $user_nicename = bbp_get_user_nicename( $user_id );}
    
    		$url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_id, $url );
    		$url = home_url( user_trailingslashit( $url ) );
    
    	} 
    	else { 	// Unpretty permalinks
    		$url = add_query_arg( array( bbp_get_user_rewrite_id() => $user_id ), home_url( '/' ) );
    	}
    	//return apply_filters( 'Replaced_bbp_get_user_profile_url', $url, $user_id, $user_nicename );
    	return $url;
    }	

    Robin W
    Moderator

    @robin-w

    Hey great, glad you’re fixed !

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

You must be logged in to reply to this topic.