LLMS_Abstract_Generator_Posts::create_user( array $raw )
Create a new WP_User from raw data
Parameters Parameters
- $raw
-
(array) (Required) Raw data.
Return Return
(int|WP_Error) WP_User ID on success or error on failure.
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 the value of the `default_role` option (typically 'subscriber').
* @param array $raw Original raw author data.
*/
$raw['role'] = empty( $raw['role'] ) ? apply_filters( 'llms_generator_new_user_default_role', get_option( 'default_role', 'subscriber' ), $raw ) : $raw['role'];
// Ensure the importing user is allowed to assign the requested role.
$authorized = $this->authorize_new_user_role( $raw['role'] );
if ( is_wp_error( $authorized ) ) {
return $authorized;
}
$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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |