Skip to:
Content
Pages
Categories
Search
Top
Bottom

WordPress to BuddyPress profile sync


  • krioteh
    Participant

    @krioteh

    In BuddyPress there is a built-in mechanism for synchronizing profile fields from WordPress.
    By default, it synchronizes only the “display_name” field, which is not always sufficient.
    Here is an example of the code by which you can synchronize any available fields in the WordPress field with the Buddypress fields

    function xprofile_sync_bp_profile2( &$errors, $update, &$user ) {
    	// Bail if profile syncing is disabled.
    	if ( bp_disable_profile_sync() || ! $update || $errors->get_error_codes() ) {
    		return;
    	}
        // Querying data from a table "usermeta", first we get the value of the custom field "address" and substitute this value for the "Address" field of the xprofile BuddyPress
        $address = get_user_meta( $user->ID, 'address', 'true' );  
    	xprofile_set_field_data( 'Address', $user->ID, $address );
      	//Similarly with other fields
        $firstname = get_user_meta( $user->ID, 'first_name', 'true' );  
    	xprofile_set_field_data( 'Name', $user->ID, $firstname );
      	$lastname = get_user_meta( $user->ID, 'last_name', 'true' );  
    	xprofile_set_field_data( 'Lastname', $user->ID, $lastname );
      	$description = get_user_meta( $user->ID, 'description', 'true' );  
    	xprofile_set_field_data( 'Bio', $user->ID, $description );
      
      	// Querying data from a table "user"
        xprofile_set_field_data( 'E-mail', $user->ID, $user->user_email );
        xprofile_set_field_data( 'Site', $user->ID, $user->user_url );
    }
    add_action( 'user_profile_update_errors', 'xprofile_sync_bp_profile2', 10, 3 );

    Unfortunately, the fields are synchronized only when the profile is updated. I do not know how to start mass synchronization 🙁

    I hope someone will find this information useful.

Viewing 5 replies - 1 through 5 (of 5 total)

  • krioteh
    Participant

    @krioteh

    Nobody knows how to run a massive update of user profiles in the WordPress?
    Sadness … 🙁


    Henry Wright
    Moderator

    @henrywright

    Unfortunately, the fields are synchronized only when the profile is updated. I do not know how to start mass synchronization

    This is likely because you’re hooking to a hook fired at profile update. You’ll need to hook your code to something that gets fired at another point in time.


    krioteh
    Participant

    @krioteh

    I, like that dog: I understand everything – I can not say 🙂

    I just made changes to the standard BuddyPress function, there was this hook.
    I think that I need to call a loop, which in turn will sort through all the users and start synchronization in this cycle. Then add this cycle to the crowns so that the synchronization is done according to the schedule.

    But how to translate this into php …
    Ok, I’ll go and smoke the manuals. Thanks for the tip-off.


    Norman Cates
    Participant

    @normancates

    That’s awesome.

    Why is this not a standard part of Buddypress? (Rhetorical question)

    IMO, any fields should be designated (or able to be designated) as linked to the WP profile information.

    THis is a CONSTANT source of confusion for me and any users. Because some plugins use the WordPress profile info, and some the Buddypress info.

    I get that they probably need to do that. But at least let us synchronise the data.

    Including display name options…

    Please, BP / WP developers, slam an interface on this and let us keep our data consistent.

    Cheers,
    Norm


    Varun Dubey
    Participant

    @vapvarun

    @normancates, BuddyPress has an only primary field as Name, rest are user-defined.
    With BuddyPress, you are also allowed to create additional First Name & Last Name fields, and it will need some custom codes like pasted by @krioteh.

    You can try https://wordpress.org/plugins/bp2wp-full-sync/, hopefully, it will help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar