contact_data = $contact_data; $this->lists = $lists; $this->tags = $tags; } /** * Create or update a contact based on provided contact data. * * This method checks if the contact exists and updates it or creates a new contact. * It also handles double opt-in if configured. * * @since 3.2.0 */ public function create_or_update_contact(){ if( Helper::maybe_enabled() && !empty( $this->contact_data['email'] ) ){ $settings = get_option( '_mint_integration_settings', array( 'zero_bounce' => array( 'api_key' => '', 'email_address' => '', 'is_integrated' => false, ), ) ); $zero_bounce = isset( $settings['zero_bounce'] ) ? $settings['zero_bounce'] : array(); $api_key = isset( $zero_bounce['api_key'] ) ? $zero_bounce['api_key'] : ''; $is_integrated = isset( $zero_bounce['is_integrated'] ) ? $zero_bounce['is_integrated'] : false; if( $is_integrated ) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.zerobounce.net/v2/validate?api_key='.$api_key.'&email='.$this->contact_data['email'].'&ip_address=null'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $response = json_decode($output, true); if( isset( $response['status'] ) && 'valid' !== $response['status'] ){ return; } } $exist = ContactModel::is_contact_exist( $this->contact_data['email'] ); if( ! $exist ){ $contact = new ContactData( $this->contact_data['email'], $this->contact_data ); $this->contact_id = ContactModel::insert( $contact ); } else { // Get existing contact ID $existing_contact = ContactModel::get_contact_by_email( $this->contact_data['email'] ); if ( $existing_contact ) { $this->contact_id = $existing_contact['id']; } } if ( isset( $this->contact_data['status'] ) && 'pending' === $this->contact_data['status'] ) { MessageController::get_instance()->send_double_opt_in( $this->contact_id ); } } } /** * Add contact to specified lists. * * This method associates the contact with the provided lists. * * @since 3.2.0 */ public function add_contact_to_lists(){ if( !empty( $this->lists ) && $this->contact_id ){ ContactGroupModel::set_lists_to_contact( $this->lists, $this->contact_id ); } } /** * Add contact to specified tags. * * This method associates the contact with the provided tags. * * @since 3.2.0 */ public function add_contact_to_tags(){ if( !empty( $this->tags ) && $this->contact_id ){ ContactGroupModel::set_tags_to_contact( $this->tags, $this->contact_id ); } } }