xprofile_sync_wp_profile( int $user_id,  $field_id = null )

Sync xprofile data to the standard built in WordPress profile data.

Description

Parameters

$user_id

(Required) ID of the user to sync.

Return

(bool)

Source

File: bp-xprofile/bp-xprofile-functions.php

function xprofile_sync_wp_profile( $user_id = 0, $field_id = null ) {

	// 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;
	}

	$firstname_id = bp_xprofile_firstname_field_id();
	$lastname_id  = bp_xprofile_lastname_field_id();
	$nickname_id  = bp_xprofile_nickname_field_id();

	if ( ! $field_id || $field_id == $firstname_id ) {
		$firstname = xprofile_get_field_data( bp_xprofile_firstname_field_id(), $user_id );
		bp_update_user_meta( $user_id, 'first_name', $firstname );
	}

	if ( ! $field_id || $field_id == $lastname_id ) {
		$lastname = xprofile_get_field_data( bp_xprofile_lastname_field_id(), $user_id );
		bp_update_user_meta( $user_id, 'last_name', $lastname );
	}

	if ( ! $field_id || $field_id == $nickname_id ) {
		$nickname = xprofile_get_field_data( bp_xprofile_nickname_field_id(), $user_id );
		bp_update_user_meta( $user_id, 'nickname', $nickname );
	}

	bp_xprofile_update_display_name( $user_id );
}

Changelog

Changelog
Version Description
BuddyPress 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.