Automattic\WooCommerce\Internal\StockNotifications\Frontend
SignupService::parse_user_data
Parse the user data from the source data.
Method of the class: SignupService{}
No Hooks.
Returns
Array|\WP_Error. The parsed user data, or a WP_Error if the user data is invalid.
Usage
// private - for code of main (parent) class only $result = $this->parse_user_data( $source );
- $source(array) (required)
- The source data, e.g. $_POST or $_REQUEST.
SignupService::parse_user_data() SignupService::parse user data code WC 10.3.6
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 );
}
// Check for valid privacy terms.
if ( ! $is_logged_in && Config::creates_account_on_signup() && ! Config::requires_account() ) {
$opt_in = isset( $source['wc_bis_opt_in'] ) ? wc_clean( wp_unslash( $source['wc_bis_opt_in'] ) ) : false;
if ( 'on' !== $opt_in ) {
return new \WP_Error( self::ERROR_INVALID_OPT_IN );
}
}
if ( ! $is_logged_in ) {
$email = isset( $source['wc_bis_email'] ) ? sanitize_email( wp_unslash( $source['wc_bis_email'] ) ) : false;
if ( ! $email ) {
return new \WP_Error( self::ERROR_INVALID_EMAIL );
}
if ( ! is_email( $email ) ) {
return new \WP_Error( self::ERROR_INVALID_EMAIL );
}
$data['user_id'] = 0;
$data['user_email'] = $email;
// Check if user exists with this email.
$user = get_user_by( 'email', $email );
if ( $user ) {
$data['user_id'] = $user->ID;
}
} else {
$user = wp_get_current_user();
if ( ! $user ) {
return new \WP_Error( self::ERROR_INVALID_USER );
}
$data['user_id'] = $user->ID;
$data['user_email'] = $user->user_email;
}
return $data;
}