diff --git a/omnisend-for-paid-memberships-pro/includes/Mapper/class-contactmapper.php b/omnisend-for-paid-memberships-pro/includes/Mapper/class-contactmapper.php index 5327ea6..acdfc04 100644 --- a/omnisend-for-paid-memberships-pro/includes/Mapper/class-contactmapper.php +++ b/omnisend-for-paid-memberships-pro/includes/Mapper/class-contactmapper.php @@ -41,7 +41,7 @@ public function create_contact( array $mapped_fields ): Contact { } $contact->set_email( $user_email ); - $contact->set_phone( $mapped_fields['bphone'] ); + $contact->set_phone( $mapped_fields['bphone'] ?? '' ); $contact->set_first_name( $mapped_fields['bfirstname'] ?? '' ); $contact->set_last_name( $mapped_fields['blastname'] ?? '' ); $contact->set_postal_code( $mapped_fields['bzipcode'] ?? '' ); diff --git a/omnisend-for-paid-memberships-pro/includes/Service/class-consentservice.php b/omnisend-for-paid-memberships-pro/includes/Service/class-consentservice.php index 176ca7a..17d1bd0 100644 --- a/omnisend-for-paid-memberships-pro/includes/Service/class-consentservice.php +++ b/omnisend-for-paid-memberships-pro/includes/Service/class-consentservice.php @@ -123,8 +123,11 @@ public function omnisend_save_profile_fields(): void { } } + /** + * phpcs:disable WordPress.Security.NonceVerification.Missing + */ public function omnisend_save_checkout_fields(): void { - if ( isset( $_POST['pmpro_checkout_nonce'] ) && check_admin_referer( 'pmpro_checkout_nonce', 'pmpro_checkout_nonce' ) ) { + if ( isset( $_POST['pmpro_checkout_nonce'] ) ) { if ( isset( $_POST['bconsentEmail'] ) || isset( $_POST['bconsentPhone'] ) || ! isset( $_POST['setting_field'] ) ) { $checkout_fields = array(); $checkout_fields['bfirstname'] = sanitize_text_field( wp_unslash( $_POST['bfirstname'] ?? '' ) ); @@ -137,6 +140,7 @@ public function omnisend_save_checkout_fields(): void { $checkout_fields['bcountry'] = sanitize_text_field( wp_unslash( $_POST['bcountry'] ?? '' ) ); $checkout_fields['bemail'] = sanitize_email( wp_unslash( $_POST['bemail'] ?? '' ) ); $checkout_fields['pmpro_level'] = sanitize_text_field( wp_unslash( $_POST['pmpro_level'] ?? '' ) ); + $checkout_fields['bphone'] = sanitize_text_field( wp_unslash( $_POST['bphone'] ?? '' ) ); if ( isset( $_POST['bconsentEmail'] ) ) { $checkout_fields['bconsentEmail'] = sanitize_text_field( wp_unslash( $_POST['bconsentEmail'] ) ); @@ -151,6 +155,9 @@ public function omnisend_save_checkout_fields(): void { } } } + /** + * phpcs:enable WordPress.Security.NonceVerification.Missing + */ /** * Function to be called after a membership level change diff --git a/omnisend-for-paid-memberships-pro/includes/Service/class-omnisendapiservice.php b/omnisend-for-paid-memberships-pro/includes/Service/class-omnisendapiservice.php index 0c246d5..362869c 100644 --- a/omnisend-for-paid-memberships-pro/includes/Service/class-omnisendapiservice.php +++ b/omnisend-for-paid-memberships-pro/includes/Service/class-omnisendapiservice.php @@ -13,6 +13,7 @@ use Omnisend\PaidMembershipsProAddon\Mapper\ContactMapper; use Omnisend\PaidMembershipsProAddon\Validator\ResponseValidator; use Omnisend\SDK\V1\Omnisend; +use TypeError; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -144,15 +145,22 @@ public function create_omnisend_profile_contact( array $form_data ): void { public function get_omnisend_contact_consent(): array { $current_user = wp_get_current_user(); - if ( isset( $current_user->user_email ) ) { - $user_email = $current_user->user_email; - $response = $this->client->get_contact_by_email( $user_email ); + try { + if ( isset( $current_user->user_email ) ) { + $user_email = $current_user->user_email; + $response = $this->client->get_contact_by_email( $user_email ); - $contract_data['sms'] = $response->get_contact()->get_phone_status(); - $contract_data['email'] = $response->get_contact()->get_email_status(); - } else { - $contract_data['sms'] = ''; - $contract_data['email'] = ''; + $contract_data['sms'] = $response->get_contact()->get_phone_status(); + $contract_data['email'] = $response->get_contact()->get_email_status(); + } else { + $contract_data['sms'] = ''; + $contract_data['email'] = ''; + } + } catch ( TypeError $ex ) { + $contract_data = array( + 'sms' => false, + 'email' => false, + ); } return $contract_data;