AP_Form_Hooks::create_user( $values,  $args,  $manual )

Description #

Source #

File: includes/class-form-hooks.php

	public static function create_user( &$values, &$args, $manual ) {
		$email = $values['email']['value'];
		$user_id = wp_insert_user( array(
			'user_email'   => $email,
			'user_login'   => $email,
			'user_pass'    => wp_generate_password(),
			'display_name' => ! empty(  $values['anonymous_name']['value'] ) ? $values['anonymous_name']['value'] : '',
		) );

		if ( is_wp_error( $user_id ) ) {
			if ( false === $manual ) {
				ap_ajax_json( array(
					'success'  => false,
					'snackbar' => [ 'message' => $user_id->get_error_message() ],
				) );
			} else {
				return $user_id;
			}
		}

		// Send the notification.
		wp_new_user_notification( $user_id, null, 'both' );

		$args['post_author'] = $user_id;
	}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment