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

		$id = empty( $this->reusable_blocks[ $block_id ] ) ? false : $this->reusable_blocks[ $block_id ];
		if ( ! $id ) {

			// If the block already exists, don't create it again.
			$existing = get_post( $block_id );
			if ( $existing && 'wp_block' === $existing->post_type && $block['title'] === $existing->post_title && $block['content'] === $existing->post_content ) {
				return false;
			}

			$id = $this->insert_resuable_block( $block_id, $block );
		}

		// Don't return 0 if `wp_insert_post()` fails.
		return $id ? $id : false;

	}

	/**
	 * Create a new WP_User from raw data
	 *
	 * @since 4.7.0
	 *
	 * @param array $raw Raw data.
	 * @return int|WP_Error WP_User ID on success or error on failure.
	 */
	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


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.