Last active
October 7, 2023 08:13
-
-
Save KaineLabs/c21c7e83428224908c70a16548aa8918 to your computer and use it in GitHub Desktop.
Change Member Username with Custom Profile Fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
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
I changed 1,621 with my fields ids and seems like it is not working. Any ideea why?
Youzify version 3.3.0