Forcing BuddyPress to utilize user_nicename for member urls and mentions

For an upcoming project that will be utilizing BuddyPress 1.2 – I hit a snag with the user_login and member slugs. Importantly the column user_login may contain an @ symbol or other special characters. Since my user registration is via WordPress the user_nicename column is already cleaned and ready to go.

***WARNING***

This requires editing core files and will break whatever upgrade process you use. Thus I can not guarantee this will work for everyone (I’m already one pint into a Arrogant Bastard Ale) I tried to extract the changes I made, so hopefully this is all of them.

You can download a zip file or see below.

bp-activity-filters.php
104c104,105
< if ( !$user_id = username_exists( $username ) )
---
> //ETIVITI (rich!) force user_nicename
> if ( !$user_id = bp_core_get_userid( $username ) )

bp-core-catchuri.php
115c115,117
< if ( get_userdatabylogin( $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
---
> //ETIVITI (rich!) force user_nicename
> if ( get_user_by('slug', $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
>

bp-activity.php
114a115,117
> //ETIVITI (rich!) force user_nicename
> $user_nicename = ( !empty( $bp->displayed_user->userdata->user_nicename ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
>
127c130,131
< bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_login ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );
---
> //ETIVITI (rich!) force user_nicename
> bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_nicename ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );

bp-core.php
1001c1001
<
---
> //ETIVITI (rich!) force user_nicename
1003c1003
< return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
---
> return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_nicename = %s", $username ) ) );
1040,1043c1040,1041
< if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
< $username = $user_login;
< else
< $username = $user_nicename;
---
> //ETIVITI (rich!) force user_nicename
> $username = $user_nicename;

Please let me know if I fudged anything up here…

This will not work with BP_ENABLE_USERNAME_COMPATIBILITY_MODE – not tested with other bp plug-ins.

This entry was posted in Tech and tagged , . Bookmark the permalink.

One Response to Forcing BuddyPress to utilize user_nicename for member urls and mentions

  1. djkkenny says:

    Just wondering if anyone has turned this into a plugin?

Leave a Reply