bp_xprofile_sync_wp_profile( int $user_id, array $posted_field_ids, bool $errors, array $old_values, array $new_values )

Sync the standard built in xprofile data to WordPress data.

Description

Parameters

$user_id

(Required) ID for the user whose profile is being saved.

$posted_field_ids

(Required) Array of field IDs that were edited.

$errors

(Required) Whether or not any errors occurred.

$old_values

(Required) Array of original values before update.

$new_values

(Required) Array of newly saved values after update.

Return

(void)

Source

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

function bp_xprofile_sync_wp_profile( $user_id, $posted_field_ids, $errors, $old_values, $new_values ) {

	if ( ! empty( $errors ) ) {
		return;
	}

	foreach ( $new_values as $field_id => $new_value ) {

		// Get First, Last and Nickname field id from DB.
		$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 ) {
			bp_update_user_meta( $user_id, 'first_name', $new_value['value'] );
		}

		if ( ! $field_id || $field_id == $lastname_id ) {
			bp_update_user_meta( $user_id, 'last_name', $new_value['value'] );
		}

		if ( ! $field_id || $field_id == $nickname_id ) {
			bp_update_user_meta( $user_id, 'nickname', $new_value['value'] );
		}

	}

	bp_xprofile_update_display_name( $user_id );
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.7 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.