Losing first and last name fields
-
I’m using BBpress for forums and Buddypress for forum profile features and in future would like to use more BuddyPress features. My problem is that if a user changes their forum name, it is changes the first name account field to the forum name and clears out the last name account field. If I uncheck the Buddypress setting “Sync with profile fields” this does not occur but the forum name does not change at all. I don’t mind syncing forum name with “display name” but the first and last name fields can’t be wiped out. I know I must be doing something wrong but can’t find it. I’m also using Memberpress for registration.
-
Wow, I’ve just discovered that if I deactivate Buddypress, I can change all the account fields: first name, last name, nickname AND display name. This is what I want with Buddypress enabled and I see that it works this way on this forum here, but I can’t see what I have done in Buddypress to break this.
Doesn’t look like anybody’s going to help us here, Marcus. If I find the answer, other than getting rid of Buddypress, I’ll let you know. Please do the same for me if you find an answer. So far I have come up empty.
Hi @tdurocher-
What screen are you using to change the bbPress “forum name”? (That’s unfamiliar to me.)
BuddyPress uses the user’s profile to manage names, and doesn’t generally interact with the First and Last name fields; it allows the user to manage the Display Name field. For instance, via http://bptest.local/members/admin/profile/edit/group/1/
Adding MemberPress to the mix complicates the issue somewhat, too.
Ah, thanks for the response. The url I’m using is, for example, https://masteringid.com/members/testmember/profile/edit/group/1/, which produces the following form:
Edit Profile
Editing “Forum username” Profile Group
Name (required)This field may be seen by: Everyone
Forum SignatureNote that I have changed “base profile” to “forum username” as it seemed more to the point. So I think this is the page you are referring to but there is no Display Name field shown. I don’t so much need the First and Last Name fields as the display name field, because, although changing the forum username will change the display name, it also changes the First and Last Name (through the “Sync with WP profile” checkbox.
BBpress alone shows First Name, Last Name, Nickname, and the Display Name dropdown. If I could have the Nickname and Display Name fields, or even just the Display Name field, I think I’d be okay.
David (@dcavins), do you have any ideas why I wouldn’t be seeing the Display Name under Edit Profile, as you said it should? Or why Buddypress overrides important BBpress fields for editing the forum profile? I think there must be a way around this. I do not see that Memberpress is involved in this profile page at all (no apparent mepr classes or js shown in developer tools). Thanks very much for any help.
Hi Tom-
I’d guess that you (or the previous site admin) edited the Display Name field to be called “Name.” You can check by visiting this screen on your installation: /wp-admin/users.php?page=bp-profile-setup
“Display Name” is usually the first profile field created, so if you inspect the
input
, and it has thename=field_1
, then you can guess that your “Name” field is the “Display Name” field I’m talking about, just renamed, similar to how you renamed the “Base profile.” It sounds like when you’re talking about “Forum Name” you’re talking about BP’s Base Profile > Display Name, but with your own naming convention.I also was wrong about the synchronization between Display Name and First and Last name. If I update the Display Field to be “Too Slim”, the WP First Name will become “Too” and the WP Last Name will become “Slim,” assuming that “Enable BuddyPress to WordPress profile syncing” (s you said). The WordPress “Display Name” field will become “Too Slim.” The WP “Display Name” is also looks like what is used by bbPress in its loops.
So, if you want your users to be able to change the name used by the bbPress forums, you’ll need to have “Enable BuddyPress to WordPress profile syncing” checked. Then, the WP “Display Name” field is updated when the BP “Display Name” field is checked. If you want to leave WP’s First and Last Name fields to not be synced after sign-up, the following code could be added to your
bp-custom.php
file or wherever you keep your customization code:// Remove BP's action because it syncs nickname, display_name, first_name and last_name. remove_action( 'xprofile_data_after_save', 'xprofile_sync_wp_profile_on_single_field_set' ); function my_custom_xprofile_sync_wp_display_name_only_on_single_field_set( $user_id = 0 ) { // Bail if profile syncing is disabled. if ( bp_disable_profile_sync() ) { return true; } if ( empty( $user_id ) ) { $user_id = bp_loggedin_user_id(); } if ( empty( $user_id ) ) { return false; } $fullname = xprofile_get_field_data( bp_xprofile_fullname_field_id(), $user_id ); bp_update_user_meta( $user_id, 'nickname', $fullname ); wp_update_user( array( 'ID' => $user_id, 'display_name' => $fullname ) ); } add_action( 'xprofile_data_after_save', 'my_custom_xprofile_sync_wp_display_name_only_on_single_field_set' );
It’s a modified version of this function, leaving the first and last name logic out: https://github.com/buddypress/BuddyPress/blob/5.0.0/src/bp-xprofile/bp-xprofile-functions.php#L803
Thanks for your answer. I believe it will work for me but it may take me a day or two to check it all out.
Hi David,
I have tried out your code and there’s a problem. But first, to address your question about the “name” field, when I’m talking about Forum Name I am talking about the Group (which had been called Base Profile). That is what I changed to Name, for UX reasons. However, I see that the field I’m calling “Name” is field_1 so probably I did change it from Display Name to Name but, as I think you know, that is not the problem.
Regarding the code you gave me, that did solve the problem of not updating the WP First and Last name fields. However, it also prevented changes to the forum name or display name or whatever you want to call the name in the Forum Profile. I’m tempted to try commenting out the line:
bp_update_user_meta( $user_id, 'nickname', $fullname );
but I’m working on a live site with quite a bit of action and got a little spooked that I might change everybody’s existing posts/names, so for now I’ve just removed all your code.
Thanks,
TomHi @dcavins. Just @mentioning you in case you’re not subscribed. I think you code can work for me if we can just get the Forum name back to being savable.
After looking at the original function in the link you posted, I’m guessing that updating the nickname with $fullname is not wrong, but it doesn’t seem to be working. I notice that this function in the original code is attached to two actions that are different than the one you had me attach to. Could this be the problem? Remember, I have removed the original xprofile_sync function.
add_action( 'bp_core_signup_user', 'xprofile_sync_wp_profile' ); add_action( 'bp_core_activated_user', 'xprofile_sync_wp_profile' );
Thanks,
TomHi Tom-
It sounds like you have a lot of balls in the air. For instance:
Remember, I have removed the original xprofile_sync function.
Honestly, I can’t know enough about your setup to tell you anything for sure. What I can tell you is this:
• bbPress uses WordPress’s “Display Name” field, not a BuddyPress field.
• BuddyPress only updates the WP “Display Name” field when profile syncing is enabled.
• BP’s default sync function also updates WP’s “First Name” and “Last Name”
• The replacement function I provided updates WP’s “Display Name” but _not_ the “First Name” and “Last Name” fields.Feel free to comment out the “nickname” update line. You won’t hurt anything. You’ll just not update the BP “nickname” field. Which won’t affect the name bbPress displays.
@dcavins, when I say I removed the xprofile_sync function, that was part of your suggested code. More precisely, I removed the function from the action and then added your revised function. I guess that should not prevent the forum name from being set and yet it apparently does. Well, your bullet items are good info, especially that first one. I will look at this again.
What IS the BP nickname field, if it doesn’t use that? Maybe I’ll need to ask on the bbpress forum. Thanks again, I’ll see what I can do with this information. I’m starting to smell my theme being involved.
Sorry, it’s not the BP nickname field. That’s actually a WP user meta field.
Other things that appear to be true:
• BP uses WP’s “Display Name” to label the user in activity items and elsewhere.
• WP’s ‘nickname’ meta is required but not used widely?So it seems like the key field for display in BP, bbPress and WP is WP’s “display name” field.
Ha! Names are confusing!
Yeah. To make in even more confusing WP offers the ability to set the display_name to any of the other names (nickname, first name last name, username, and more) – I think it is username by default. Well I’ve learned something about WP’s and BP’s use of names, so maybe that will help me figure out what is going wrong with the xprofile function you sent me. It is failing to update the (apparently one single) display name. Maybe bbpress does NOT user display name for its “forum name”. Anyway, I’m missing something about the the BBPress/Buddypress integration with regard to names. Unfortunately, this is not the highest priority thing I’m working on….
Note that you will have to have “Enable BuddyPress to WordPress profile syncing” checked in order for the function I provided to work.
Also, “WP offers the ability to set the display_name to any of the other names (nickname, first name last name, username, and more)”, yes that’s true, but when your preference is saved, the value you chose is copied into the “display_name” field in the
wp_user
database, so don’t get distracted by that issue–it’s still the WP “display_name” that bbPress and BuddyPress care about.@dcavins and others. The code you suggested was incorrect. Here is the correct code to fix the problem, at least it works for me with no apparent side-effects:
function my_xprofile_sync_wp_profile( $user_id = 0 ) { // Bail if profile syncing is disabled. if ( bp_disable_profile_sync() ) { return true; } if ( empty( $user_id ) ) { $user_id = bp_loggedin_user_id(); } if ( empty( $user_id ) ) { return false; } $fullname = xprofile_get_field_data( bp_xprofile_fullname_field_id(), $user_id ); bp_update_user_meta( $user_id, 'nickname', $fullname ); wp_update_user( array( 'ID' => $user_id, 'display_name' => $fullname ) ); } remove_action( 'xprofile_data_after_save', 'xprofile_sync_wp_profile_on_single_field_set'); function my_xprofile_sync_wp_profile_on_single_field_set( $data ) { echo("made it to my_xprofile"); if ( bp_xprofile_fullname_field_id() !== $data->field_id ) { return; } my_xprofile_sync_wp_profile( $data->user_id ); } add_action( 'xprofile_data_after_save', 'my_xprofile_sync_wp_profile_on_single_field_set' );
Great, thanks for the update!
- You must be logged in to reply to this topic.