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

Description #

Handle create user request.

Parameters #

  • $values
    array (Required) Form values.
  • $args
    array (Required) Form arguments.
  • $manual
    bool (Required) Is this manually submitted.

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' => array( '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.

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

Add your comment