Automattic\WooCommerce\Internal\StockNotifications\Frontend

SignupService::parse_user_data │ private │ WC 1.0

Parse the user data from the source data.

Метод класса: SignupService{}

Хуков нет.

Возвращает

array|\WP_Error. The parsed user data, or a WP_Error if the user data is invalid.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->parse_user_data( $source );
$source(массив) (обязательный)
The source data, e.g. $_POST or $_REQUEST.

Код SignupService::parse_user_data() WC 11.2.2

private function parse_user_data( array $source ) {
	$data = array();

	$is_logged_in = \is_user_logged_in();
	if ( ! $is_logged_in && Config::requires_account() ) {
		return new \WP_Error( self::ERROR_REQUIRES_ACCOUNT );
	}

	if ( ! $is_logged_in ) {
		$posted_email = isset( $source['wc_bis_email'] ) && is_string( $source['wc_bis_email'] ) ? sanitize_email( wp_unslash( $source['wc_bis_email'] ) ) : '';
		$email        = is_email( $posted_email ) ? EmailNormalizer::normalize( $posted_email ) : '';
		if ( '' === $email ) {
			return new \WP_Error( self::ERROR_INVALID_EMAIL );
		}

		// A guest sign-up stays unlinked until the customer verifies the email: an address typed
		// into a form proves nothing about who owns the matching account.
		$data['user_id']    = 0;
		$data['user_email'] = $email;
	} else {
		$user = wp_get_current_user();
		if ( ! $user ) {
			return new \WP_Error( self::ERROR_INVALID_USER );
		}

		$data['user_id']    = $user->ID;
		$data['user_email'] = EmailNormalizer::normalize( $user->user_email );
	}

	return $data;
}