__( 'Lead/Form Submitted (site-wide)', 'advanced-form-integration' ), ); } // Get Depicter Fields function adfoin_depicter_get_form_fields( $form_provider, $form_id ) { if ( $form_provider !== 'depicter' || $form_id !== 'leadCreated' ) { return; } return array( 'lead_id' => __( 'Lead ID', 'advanced-form-integration' ), 'source_id' => __( 'Source ID (which popup/slider)', 'advanced-form-integration' ), 'content_id' => __( 'Content ID (which page/post it was on)', 'advanced-form-integration' ), 'email' => __( 'Email (best-effort, from a field literally named "email")', 'advanced-form-integration' ), 'all_fields_json' => __( 'All Submitted Fields (JSON, for fields not listed above)', 'advanced-form-integration' ), ); } // Handle Lead Created function adfoin_depicter_handle_lead_created( $leadId, $sourceId, $contentId ) { $integration = new Advanced_Form_Integration_Integration(); $saved_records = $integration->get_by_trigger( 'depicter', 'leadCreated' ); if ( empty( $saved_records ) ) { return; } $all_fields = array(); $email = ''; if ( method_exists( '\Depicter', 'leadFieldRepository' ) ) { try { $fields = \Depicter::leadFieldRepository()->select( array( 'name', 'value' ) )->where( 'lead_id', '=', $leadId )->findAll()->get(); $fields_arr = $fields ? $fields->toArray() : array(); foreach ( $fields_arr as $field ) { $name = isset( $field['name'] ) ? $field['name'] : ''; if ( '' === $name ) { continue; } $value = isset( $field['value'] ) ? $field['value'] : ''; $all_fields[ $name ] = $value; if ( 'email' === strtolower( $name ) ) { $email = $value; } } } catch ( \Exception $e ) { // Leave $all_fields empty rather than fail the whole dispatch. } } $posted_data = array( 'lead_id' => $leadId, 'source_id' => $sourceId, 'content_id' => $contentId, 'email' => $email, 'all_fields_json' => wp_json_encode( $all_fields ), ); adfoin_dispatch_integrations( $saved_records, $posted_data ); }