Hello @mohamettarik
Thanks for reaching us
First, you need to create new BuddyPress fields for the First Name and Last Name. And then, you can use this snippet
https://gist.github.com/KaineLabs/c21c7e83428224908c70a16548aa8918#file-yzc_change_member_username_with_custom_fields-php
Please change 1 and 621 with those fields ID.
Best Regards, KaineLabs Team.
Hello, appreciating support, you are great people.
I added the snippet to pb-custom.php file, I tried replacing 1 with first_name
621 with last_name
exactly without any modifications but not worked.
<?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( first_name, $user_id );
$surname = xprofile_get_field_data( last_name, $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 );
i think missing something or i could not code fields names right.
-
This reply was modified 2 years, 7 months ago by mohamettarik.
Hello @mohamettarik
On the line 7 and 8, please use fields ID NUMBER instead of the fields title. Please check this screenshot to know how to get it >> https://buddypress.org/wp-content/uploads/15/2013/10/hovering-on-edit-ann.png
Best Regards, KaineLabs Team.
Really appreciated,, you made my day 🙂 working well
-
This reply was modified 2 years, 7 months ago by mohamettarik.
You’re welcome @mohamettarik
I will close this ticket. But if you have any other questions, you can open a new ticket. 🙂
Best Regards, KaineLabs Team.
How can I display name and username ?
-
This reply was modified 2 years, 3 months ago by jakaria5482.