$message, 'email' => $message, ]; } } if ( [] !== $fields ) { return new WP_Error( 'fxtr_contact_invalid', (string) reset( $fields ), [ 'status' => 400, 'fields' => $fields, ] ); } return [ 'phone' => $phone, 'email' => sanitize_email( $email ), ]; } /** * Digits with the usual separators, an optional leading +, and 6 to 15 * digits in all (E.164 tops out at 15). */ public static function phone_ok( string $phone ): bool { if ( 1 !== preg_match( '/^\+?[0-9 ().\-]+$/', $phone ) ) { return false; } $digits = strlen( (string) preg_replace( '/\D/', '', $phone ) ); return $digits >= 6 && $digits <= 15; } }