Change user profile URL in Buddypress with nickname or userID

admin

Administrator
Staff member
I am using this code which is partially working for changing the profile url everywhere in buddypress and wordpress from “http:/mywebsite/user/username” to “http:/mywebsite/user/userid”

Code:
    function _bp_core_get_user_domain($domain, $user_id, $user_nicename = false, $user_login = false) {
    if ( empty( $user_id ) ){
        return;
    }
    if( isset($user_nicename) ){
        $user_nicename = bp_core_get_username($user_id);
    }
    $after_domain =  bp_get_members_root_slug() . '/' . $user_id;

    $domain = trailingslashit( bp_get_root_domain() . '/' . $after_domain );
    $domain = apply_filters( 'bp_core_get_user_domain_pre_cache', $domain, $user_id, $user_nicename, $user_login );
    if ( !empty( $domain ) ) {
        wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
    }
    return $domain;
}

add_filter('bp_core_get_user_domain', '_bp_core_get_user_domain', 10, 4);

function _bp_core_get_userid($userid, $username){
    if(is_numeric($username)){
        $aux = get_userdata( $username );
        if( get_userdata( $username ) )
            $userid = $username;
    }
    return $userid;
}

add_filter('bp_core_get_userid', '_bp_core_get_userid', 10, 2);

function _bp_get_activity_parent_content($content){
    global $bp;
    $user = get_user_by('slug', $bp->displayed_user->fullname); // 'slug' - user_nicename
    return preg_replace('/href=\"(.*?)\"/is', 'href="'.bp_core_get_user_domain($user->ID, $bp->displayed_user->fullname).'"', $content);
}

add_filter( 'bp_get_activity_parent_content','_bp_get_activity_parent_content', 10, 1 );

add_filter('bp_core_get_userid_from_nicename', '_bp_core_get_userid', 10, 2);

It is working perfectly for me at the moment BUT not on this little place (see picture):

<a href=" " rel="nofollow"> </a>

– url change of the author of an activity starting-message is not working in both groups activities and personnal activities

<ul>
<li>url change of the author of an activity REPLY is working</li>
</ul>

I don’t know if I am explaining very well what issue I have got but I hope you will understand.

Thank you for your answers

PS : thanks to aSeptik from StackExchange for the code