resync_wordpress_xprofile_fields()

Resync WordPress profile data to BuddyBoss.

Description

Source

File: bp-core/admin/bp-core-admin-tools.php

function resync_wordpress_xprofile_fields() {
	$users = get_users( [
		'fields' => [ 'ID', 'user_nicename' ]
	] );

	foreach ( $users as $user ) {
		xprofile_set_field_data( bp_xprofile_firstname_field_id(), $user->ID, get_user_meta( $user->ID, 'first_name', true ) );
		xprofile_set_field_data( bp_xprofile_lastname_field_id(), $user->ID, get_user_meta( $user->ID, 'last_name', true ) );

		// make sure nickname is valid
		$nickname = get_user_meta( $user->ID, 'nickname', true );
		$nickname = sanitize_title( $nickname );
		$invalid  = bp_xprofile_validate_nickname_value( '', bp_xprofile_nickname_field_id(), $nickname, $user->ID );

		// or use the user_nicename
		if ( ! $nickname || $invalid ) {
			$nickname = $user->user_nicename;
		}

		bp_update_user_meta( $user->ID, 'nickname', $nickname );
		xprofile_set_field_data( bp_xprofile_nickname_field_id(), $user->ID, $nickname );
	}

	$statement = __( 'Re-sync user WordPress data to BuddyBoss profile fields; %s', 'buddyboss' );

	return array( 0, sprintf( $statement, __( 'Complete!', 'buddyboss' ) ) );
}

Changelog

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