settingsDTO->getPixels() ) < 1 ) { return; } $this->setupEventListeners(); } public function setupEventListeners() { add_action( 'wpforms_process_complete', array( $this, 'contactForm' ), 10, 3 ); } public function contactForm( $fields, $entry, $form_data ) { $formSettings = $this->settingsDTO->getForm( $form_data['id'], $this->pluginName ); // Send only matched fields $eventDto = new EventDTO( EventDTO::EVENT_LEAD ); $contentDto = new ContentDTO(); foreach ( $formSettings->getMatches() as $match ) { $fieldName = $match->getFormField(); $filtered = array_filter( $fields, function ( $item ) use ( $fieldName ) { return isset( $item['type'] ) && $item['type'] === $fieldName; } ); $val = ! empty( $filtered ) ? reset( $filtered )['value'] : null; $this->assignMatchedValue( $val, $match, $eventDto, $contentDto ); } $this->sendEvent( $eventDto ); } public function getForms() { if ( ! function_exists( 'wpforms' ) || ! function_exists( 'wpforms_decode' ) ) { return; } $forms = array(); foreach ( wpforms()->form->get() as $form ) { $form_data = wpforms_decode( $form->post_content ); $fields = array(); foreach ( $form_data['fields'] as $field ) { $fields[] = array( 'name' => $field['type'], 'label' => $field['label'], 'type' => null, ); } $forms[] = array( 'id' => $form_data['id'], 'title' => $form_data['settings']['form_title'], 'plugin' => $this->pluginName, 'fields' => $fields, ); } return $forms; } } }