settingsDTO->getPixels() ) < 1 ) { return; } $this->setupEventListeners(); } public function setupEventListeners() { add_action( 'wpcf7_submit', array( $this, 'contactForm' ), 10, 1 ); } public function contactForm( $result ) { if ( ! class_exists( 'WPCF7_Submission' ) ) { return; } try { $submission = \WPCF7_Submission::get_instance(); if ( ! $submission ) { return; } // get submission wpcf7 form settings $contact_form = $submission->get_contact_form(); $formSettings = $this->settingsDTO->getForm( $contact_form->id(), $this->pluginName ); // Send only matched fields $posted_data = $submission->get_posted_data(); $eventDto = new EventDTO( EventDTO::EVENT_LEAD ); $contentDto = new ContentDTO(); foreach ( $formSettings->getMatches() as $match ) { $val = $posted_data[ $match->getFormField() ]; $this->assignMatchedValue( $val, $match, $eventDto, $contentDto ); } $this->sendEvent( $eventDto ); } catch ( \Exception $e ) { } } public function getForms() { $forms = array(); $uselessTypes = array( 'submit', 'button' ); foreach ( \WPCF7_ContactForm::find() as $form ) { $fields = array(); foreach ( $form->scan_form_tags() as $field ) { if ( in_array( $field['basetype'], $uselessTypes ) ) { continue; } $fields[] = array( 'name' => $field['name'], 'label' => $field['name'], 'type' => $field['basetype'], ); } $forms[] = array( 'id' => $form->id(), 'title' => $form->title(), 'plugin' => $this->pluginName, 'fields' => $fields, ); } return $forms; } } }