LLMS_Abstract_Generator_Posts::create_user( array $raw )

Create a new WP_User from raw data


Parameters Parameters

$raw

(array) (Required) Raw data.


Top ↑

Return Return

(int|WP_Error) WP_User ID on success or error on failure.


Top ↑

Source Source

File: includes/abstracts/llms-abstract-generator-posts.php

	protected function create_user( $raw ) {

		/**
		 * Filter the default role used to create a new user during generator imports
		 *
		 * This role is used a role isn't supplied in the raw data.
		 *
		 * @since 4.7.0
		 *
		 * @param string $role WP_User role. Default role is 'administrator'.
		 * @param array  $raw  Original raw author data.
		 */
		$raw['role'] = empty( $raw['role'] ) ? apply_filters( 'llms_generator_new_user_default_role', 'administrator', $raw ) : $raw['role'];

		$data = array(
			'role'       => $raw['role'],
			'user_email' => $raw['email'],
			'user_login' => LLMS_Person_Handler::generate_username( $raw['email'] ),
			'user_pass'  => wp_generate_password(),
		);

		if ( isset( $raw['first_name'] ) && isset( $raw['last_name'] ) ) {
			$data['display_name'] = $raw['first_name'] . ' ' . $raw['last_name'];
			$data['first_name']   = $raw['first_name'];
			$data['last_name']    = $raw['last_name'];
		}

		if ( isset( $raw['description'] ) ) {
			$data['description'] = $raw['description'];
		}

		/**
		 * Filter user data used to create a new user during generator imports
		 *
		 * @since Unknown
		 *
		 * @param array $data Prepared user data to be passed to `wp_insert_user()`.
		 * @param array $raw  Original raw author data.
		 */
		$data      = apply_filters( 'llms_generator_new_author_data', $data, $raw );
		$author_id = wp_insert_user( $data );

		if ( ! is_wp_error( $author_id ) ) {
			/**
			 * Action fired after creation of a new user during generation
			 *
			 *  @since 4.7.0
			 *
			 * @param int   $author_id WP_User ID.
			 * @param array $data      User creation data passed to `wp_insert_user()`.
			 * @param array $raw       Original raw author data.
			 */
			do_action( 'llms_generator_new_user', $author_id, $data, $raw );
		}

		return $author_id;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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