Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

wp and bp profile syncing–works only sporadically (38 posts)

Started 2 years, 4 months ago by: Dan Butcher

  • Profile picture of Dan Butcher Dan Butcher said 2 years, 4 months ago:

    I’m running mu2.8.6/bp1.1.3, and the problem I’m having is that most of the time, when my students register on the site and complete the BP profile, that information is not synced with the WP profile. The BP profile will show the full name, but when I go to the WP profile on the backend, I see only the username and nickname fields are populated, and the others are blank; the display name shows the username.

    So, when that student comments on a post, her username is shown, and there’s no link back to her profile. However, a few students register (for instance, one did just a few minutes ago) and all their information is fully synced–the WP profile shows username, first name, last name, the display name shows first and last, and the URL is the BP profile.

    I have not been able to determine what, if anything, these few exceptions do differently to have their profiles sync. I’m assuming that these exceptions are what is supposed to be the rule when profile syncing is working correctly.

    Any ideas on what I can do to get this working correctly all the time?

  • This is my big pet peeve with Buddypress; there is no consistent built-in way to store fullname (as firstname + lastname). Profile synching only happens when members update their profile using the WP backend.

    This is by design. BP’s lead developer Andy Peatling believes firstname/lastname would not work for international users.

    My ugly workaround is here. Also see this one. I use the Javascript trick to generate a username from the fullname, so at least those are easier to recognize.

  • Profile picture of Dan Butcher Dan Butcher said 2 years, 4 months ago:

    @Peterverkooijen, thanks for the the links and explanation. I tried your “ugly workaround,” putting it into a plugin, but I get this error:

    Fatal error: Cannot redeclare synchro_wp_usermeta() (previously declared in /home/dandoese/public_html/wp-content/plugins/bp-custom.php:15) in /home/dandoese/public_html/wp-content/plugins/bp-custom.php on line 35

    (In other words, the beginning of the function and the end); undoubtedly I have missed something somewhere in how I’m supposed to use this code.

  • Looks like the function is already in your bp-custom.php, which is not part of standard Buddypress. Can you check in the file if it’s the exact same code?

    If so, how did it get there…?

    If it’s not the same function, you can probably fix the problem by search/replace in the function: synchro_wp_usermeta -> custom_synchro_wp_usermeta

    I don’t remember if I replaced an existing function with the same name. Buddypress did have a function to update wp_usermeta when profile info is updated, but I think that one had another name.

  • Profile picture of Dan Butcher Dan Butcher said 2 years, 4 months ago:

    I created bp-custom.php, and it contains only your code. I just added a plugin heading above it and wrapped it in an opening and closing php tags.

  • Profile picture of Mike Pratt Mike Pratt said 2 years, 4 months ago:

    I don’t know if I necessarily need to generate new data but I’d like to have teh BP name show instead of the username on blog comments. Probably as simple as replacing the call that shows the username in comments with a query feeding in the username and returning the first and last name, if only for display purposes

  • Profile picture of Paul Gibbs Paul Gibbs said 2 years, 4 months ago:

    @Dan http://wordpress.org/extend/plugins/buddypress-real-names/installation/ but I have no idea if it does anything special with BP->WP profile syncing. If you’ve got a repeatable case of BP changes not syncing to the WP profile, please create a bug ticket on http://trac.buddypress.org/.

  • What does that plugin do? It has some vague requirements:

    Create three news fields that will be used by the plugins (ex. “Member name”, “Member firstname”,”Member bothnames”). I suggest “Member name” to be a required field.
    Fill the values of those fields for your profile (the datas for at least one user are needed to setup the plugin options)

    Where are you supposed to create those fields? xprofile? In addition to the existing fullname field? You can already do that without this plugin.

    wp_usermeta is nowhere in the plugin. That is the table WP uses to store firstname and lastname. Any solution in Buddypress should leverage wp_usermeta or at least synchronize with it imho. This plugin solves nothing.

    If you’ve got a repeatable case of BP changes not syncing to the WP profile, please create a bug ticket on http://trac.buddypress.org/.

    The problem Dan Butcher described looks like standard Buddypress behavior to me. It’s not a bug, it’s a feature, based in Andy Peatling’s design decision that firstname + lastname would cause international incidents.

    Below again my hack as I use it in my sites, minus creation + update of a fullname-derived username for user_login, user_nicename, user_url and integration with a mailing list script I use:

    function synchro_wp_usermeta($user_id, $password, $meta) {
    	global $bp, $wpdb;
    
    	$uid = get_userdata($user_id);
    	$email = $uid->user_email;
    
    	$fullname = $meta[field_1];
    	$space = strpos( $fullname, ' ' );
    
    	if ( false === $space ) {
    		$firstname = $fullname;
    		$lastname = '';
    	} else {
    		$firstname = substr( $fullname, 0, $space );
    		$lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
    	}
    
    update_usermeta( $user_id, 'nickname', $fullname );
    update_usermeta( $user_id, 'first_name', $firstname );
    update_usermeta( $user_id, 'last_name', $lastname );
    
    $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $user_id ) );
    
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

    I have this code in bp-custom.php or functions.php, not as a plugin. Adding a plugin header could have caused Dan Butcher’s error messages.

    BTW, I’m still looking for code to validate the fullname input for at least a two part name, so make a space required. I now get a lot of users only entering a first name. In that case the lastname field in wp_usermeta will stay empty.

  • Profile picture of Mike Pratt Mike Pratt said 2 years, 4 months ago:

    Why not do the following (as we have)

    1. Have 4 name fields in BP registration

    1. username
    2. 1st name
    3. last name
    4. display name (the bp required field)

    Make them all required. We describe “display name” to everyone as “how you want your name to be viewed throughout the site’ If we had a choice, we’d get rid of it and mash 1st and last names together for display purpose. On the other hand, we have also seen many users do the following:

    1. username -> jim1974
    2. James
    3. Smith
    4. Jim Smith

    Obviously, this allows for nicknames and with a little prodding, you get people entering nicer monikers than “ladiesman269″

    Now, with the (lame) fact that WP user table is actually different (not sure why it wasn’t co-opted for BP purposes) All you have to do is create a function that writes the xprofile field values for 1st and Last name over to the WP table, in addition to setting the “display name value accordingly.

    a thousand user later and no one has complained.

  • Why not do the following (as we have) …
    1. username
    2. 1st name
    3. last name
    4. display name (the bp required field)

    Because it’s not necessary. The goal should be to keep the registration form as short and simple as possible and not annoy new users.

    Look at the registration process on Facebook, LinkedIn, etc. Most have:

    First Name:
    Last Name:
    Email:
    Password:

    I use a javascript trick generate the username from the fullname in a hidden field – I can use email as username thanks to this plugin. Since BP has a built-in fullname field I’m stuck with splitting that out in firstname and lastname.

    I have considered using fullname for firstname and creating a field_2 for lastname, but that causes all kinds of other issues.

    Unfortunately there is no check/validation on what’s entered in the fullname field. The input is also not cleaned up to get capitals on the first letters and small caps on the rest. So the input could be anything, often just a first name or even ladiesman269.

    Which undermines any reason of having that required fullname/display field in the first place…

    All you have to do is create a function that writes the xprofile field values for 1st and Last name over to the WP table, in addition to setting the “display name value accordingly.

    You have to do that straight from the registration form, to make sure that the data is there where/when you need it. That is basically what my function does. If you can get it to work. Apparently it doesn’t for Dan Butcher. :-(

    Now, with the (lame) fact that WP user table is actually different (not sure why it wasn’t co-opted for BP purposes)

    That had mystified me since last Spring, but here’s Andy’s reason.

  • Profile picture of Mike Pratt Mike Pratt said 2 years, 4 months ago:

    As much as I agree that you want to keep it simple, the last thing I want to do is a. auto-generate usernames (you have to tell them and they have to remember – let them decide) or b. parse a field into various name fields (parsing is just begging for errors – too may what-ifs)

    FYI – Facebook has you do the same 4 fields you mention you are doing. Fine. But look deeper: they then auto-generate a username. why? who knows since you always login with an email address. Additionally they auto-gen a drop down list of “display names”

    So what’s the diff between me and FB? I let you pick your display name up front in addition to your username. Ideal no but better than the alternative…for me.

    Bottom line is: let’s keep this discussion to how to do our own work arounds. The core way of doing does not appear to be changing. Fine (we can always leave the BP-sphere) Instead, let’s make it work.

    I hearby declare it off limits to refer to Andy’s decision not to include firsname/lastname ever again. :-) We get it.

  • As much as I agree that you want to keep it simple, the last thing I want to do is a. auto-generate usernames (you have to tell them and they have to remember – let them decide)

    They don’t in my site. They log in with email address. The only reason to still have an (autogenerated) username is because you need it for the URL.

    parse a field into various name fields (parsing is just begging for errors – too may what-ifs) … But look deeper: they then auto-generate a username. why? who knows … Additionally they auto-gen a drop down list of “display names” … So what’s the diff between me and FB?

    Also not much difference between me and FB. The difference between your solution and FB is what the user actually sees on the registration form. I don’t believe a new user will be all that interested in those extra choices.

    I hearby declare it off limits to refer to Andy’s decision not to include firsname/lastname ever again.

    It’s not up to you to decide what the limits of discussion are. You may get it, but until Andy/WP/Automattic gets it I’ll keep bringing it up. I like the features WP/WPMU/BP offers, there are really no alternatives for those, but they need to get central member management and the database structure up to standard.

  • Profile picture of Andy Peatling Andy Peatling said 2 years, 4 months ago:

    I don’t understand your issues with member management? WordPress MU provides excellent member management tools, and BuddyPress rides on the back of this. What is it that you need so desperately?

  • Profile picture of Mike Pratt Mike Pratt said 2 years, 4 months ago:

    Dude – it was sarcasm. Or a more polite way of saying “We get your point. You don’t like the way he does names. Ok. No need to hammer it home on every single thread, every chance you get.” Just trying to help so you’re not completely ignored.

  • Profile picture of Mike Pratt Mike Pratt said 2 years, 4 months ago:

    @Andy I think the central issue is that WP and BP store member info separately. For the uninitiated, it means that comments on blogs on a BP sire will not show the same profile info as comments on forums, etc. b/c the blog gets it’s info from the Wp table. So if you go into my admin on my site, none of the info is filled out except email and username, altho there’s AIM, website, First Name etc. But none of that is made avail into a BP install. On my site, the blog comments say ” username” commented….. instead of “Display name” commented.

    Additionally, if WP has all those user fields, why are they not exposed to BP already? That’s what is being talked about. So I am writing functions to sync up that data.