.3 * * @return array */ private function prepare_contact_data(): array { $field_mapping = new FieldMapping( $this->connection, $this->fields ); if ( $this->connection['action'] === 'subscribe' ) { return array_filter( [ 'email_address' => $field_mapping->get_field( 'email' ), 'first_name' => $field_mapping->get_meta_field( 'first_name' ), 'last_name' => $field_mapping->get_meta_field( 'last_name' ), 'job_title' => $field_mapping->get_meta_field( 'job_title' ), 'company_name' => $field_mapping->get_meta_field( 'company_name' ), 'phone_number' => $field_mapping->get_meta_field( 'phone' ), 'street_address' => $field_mapping->get_street_address(), 'list_memberships' => [ $field_mapping->get_list_id() ], 'custom_fields' => $field_mapping->get_custom_fields( $this->api->get_custom_fields( 'type', 'custom_field_id' ) ), ] ); } if ( $this->connection['action'] === 'unsubscribe' ) { return [ 'email_address' => $field_mapping->get_field( 'email' ), 'opt_out_reason' => $field_mapping->get_field( 'opt_out_reason' ), ]; } return [ 'email_address' => $field_mapping->get_field( 'email' ), ]; } /** * Get task meta data. * * @since 1.9.3 * * @param int $meta_id Task meta ID. * * @return array */ private function get_task_meta( int $meta_id ): array { $task_meta = new Meta(); $meta = $task_meta->get( $meta_id ); // We should actually receive something. if ( empty( $meta ) || empty( $meta->data ) ) { return []; } return (array) $meta->data; } /** * Get the API client based on connection and provider options. * * @since 1.9.3 * * @return Api * * @throws RuntimeException If account ID is missing or account doesn't exist. */ private function get_api_client(): Api { if ( empty( $this->connection['account_id'] ) ) { throw new RuntimeException( 'Account ID is missing in connection.' ); } $provider_settings = wpforms_get_providers_options( $this->core->slug ); return new Api( $provider_settings[ $this->connection['account_id'] ] ?? [] ); } /** * Log an API-related error with all the data. * * @since 1.9.3 * * @param string $error_message Error message. */ private function log_errors( string $error_message ) { wpforms_log( 'Submission Constant Contact failed (#' . $this->entry_id . ')', [ 'message' => $error_message, 'connection' => $this->connection, ], [ 'type' => [ 'provider', 'error' ], 'parent' => $this->entry_id, 'form_id' => $this->form_data['id'], ] ); } }