Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/c21c7e83428224908c70a16548aa8918 to your computer and use it in GitHub Desktop.
Save KaineLabs/c21c7e83428224908c70a16548aa8918 to your computer and use it in GitHub Desktop.
Change Member Username with Custom Profile Fields
<?php
/**
* Change Member Username with Custom Profile Fields.
*/
function yzc_change_member_username_with_custom_fields( $member_name, $user_id ) {
$name = xprofile_get_field_data( 1, $user_id );
$surname = xprofile_get_field_data( 621, $user_id );
// Get User Full Name.
$fullname = $name;
if ( ! empty( $surname ) ) {
$fullname .= " " . $surname;
}
if ( empty( $fullname ) ) {
$fullname = $member_name;
}
return $fullname;
}
add_filter( 'bp_core_get_user_displayname', 'yzc_change_member_username_with_custom_fields', 100, 2 );
@andreeapurta
Copy link

I changed 1,621 with my fields ids and seems like it is not working. Any ideea why?
Youzify version 3.3.0

@AgileDevOpsCoach
Copy link

Where did you get the field IDs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment