Reply To: User Profile Url uses the username. Can that be changed?
Wanted to share my finished code:
// Change the user_nicename which is used as profile url, we do NOT want the username in url! Bad bad BP...
// Wheb using the 'init' action hook this will always run, we should only do this once and then on user register & profile update..
// Please note: the user profile url can now be changed by the user, direct linking from other places on the web may result in 404.
// And offcourse allways use something like: 'bp_core_get_user_domain( $user_id )' when you want to get the user's profile url.
$search = array( ' ', '.' );
$replace = array( '_', '' );
foreach ( get_users() as $user ) {
if ( $user->data->user_status == 0 && $user->data->user_nicename != strtolower(str_replace( $search, $replace, $user->data->display_name)) ) {
$user_ids[] = $user->ID;
}
}
foreach( $user_ids as $uid ) {
$user_data = get_userdata( $uid );
$display_name = $user_data->data->display_name;
if ($display_name) {
$args = array(
'ID' => $uid,
'user_nicename' => strtolower(str_replace( $search, $replace, $display_name))
);
wp_update_user( $args );
}
}