Skip to content

Commit

Permalink
Merge pull request #7 from vidmantaskiro/send_contact_fix2
Browse files Browse the repository at this point in the history
Send contact fix
  • Loading branch information
greta-mik authored Oct 21, 2024
2 parents bea48f8 + c08b29d commit 34395cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '' ) );
Expand All @@ -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'] ) );
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 34395cb

Please sign in to comment.