bp_dd_import_users()

Importer engine – USERS

Description

Source

File: bp-core/bp-core-tools-default-data.php

function bp_dd_import_users() {
	$users = array();

	$users_data = require( BP_DEFAULT_DATA_DIR . 'data/users.php' );

	$image_url         = BP_DEFAULT_DATA_URL . 'data/images/members/';
	$cover_image_url   = $image_url . 'cover/';
	$avatars_image_url = $image_url . 'avatars/';

	foreach ( $users_data as $user ) {
		$user_id = wp_insert_user( array(
			'user_login'      => $user['login'],
			'display_name'    => $user['display_name'],
			'first_name'      => $user['first_name'],
			'last_name'       => $user['last_name'],
			'user_email'      => $user['email'],
			'user_registered' => bp_dd_get_random_date( 45, 1 ),
			'user_pass'       => wp_generate_password( 8, false ),
		) );

		if ( bp_is_active( 'xprofile' ) ) {
			xprofile_set_field_data( 1, $user_id, $user['display_name'] );
		}
		//$name = explode( ' ', $user['display_name'] );
		//update_user_meta( $user_id, 'first_name', $name[0] );
		//update_user_meta( $user_id, 'last_name', isset( $name[1] ) ? $name[1] : '' );

		bp_update_user_last_activity( $user_id, bp_dd_get_random_date( 5 ) );

		bp_update_user_meta( $user_id, 'notification_messages_new_message', 'no' );
		bp_update_user_meta( $user_id, 'notification_friends_friendship_request', 'no' );
		bp_update_user_meta( $user_id, 'notification_friends_friendship_accepted', 'no' );

		if ( ! empty( $user['avatars'] ) ) {
			bp_update_user_meta( $user_id, 'avatars', $avatars_image_url . $user['avatars'] );
		}

		if ( ! empty( $user['cover-image'] ) ) {
			bp_update_user_meta( $user_id, 'cover-image', $cover_image_url . $user['cover-image'] );
		}


		$users[] = $user_id;
	}

	if ( ! empty( $users ) ) {
		/** @noinspection PhpParamsInspection */
		bp_update_option( 'bp_dd_imported_user_ids', $users );
	}

	return $users;
}

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.