xprofile_sync_wp_profile( int $user_id )

Syncs Xprofile data to the standard built in WordPress profile data.


Parameters Parameters

$user_id

(int) (Required) ID of the user to sync.


Top ↑

Return Return

(bool)


Source Source

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

function 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 );
	$space    = strpos( $fullname, ' ' );

	if ( false === $space ) {
		$firstname = $fullname;
		$lastname = '';
	} else {
		$firstname = substr( $fullname, 0, $space );
		$lastname = trim( substr( $fullname, $space, strlen( $fullname ) ) );
	}

	bp_update_user_meta( $user_id, 'nickname',   $fullname  );
	bp_update_user_meta( $user_id, 'first_name', $firstname );
	bp_update_user_meta( $user_id, 'last_name',  $lastname  );

	wp_update_user( array( 'ID' => $user_id, 'display_name' => $fullname ) );
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.