uploaded_files() ) : array(); $fields = array(); foreach ( (array) $sub->get_posted_data() as $name => $value ) { if ( in_array( $name, $files, true ) || 0 === strpos( (string) $name, '_' ) || false !== strpos( (string) $name, 'captcha' ) ) { continue; } $fields[ self::label_from_name( $name ) ] = $value; } $title = is_object( $form ) && method_exists( $form, 'title' ) ? $form->title() : ''; self::send( 'Contact Form 7', $title, $fields ); } /** * WPForms. * * @param array $fields Submitted fields. * @param array $entry Raw entry. * @param array $form_data Form settings. */ public static function wpforms( $fields, $entry, $form_data ) { $out = array(); foreach ( (array) $fields as $f ) { if ( ! is_array( $f ) || self::skip( isset( $f['type'] ) ? $f['type'] : '' ) ) { continue; } $out[ isset( $f['name'] ) ? $f['name'] : '' ] = isset( $f['value'] ) ? $f['value'] : ''; } $title = isset( $form_data['settings']['form_title'] ) ? $form_data['settings']['form_title'] : ''; self::send( 'WPForms', $title, $out ); } /** * Elementor Pro forms. * * @param object $record Form record. */ public static function elementor( $record ) { if ( ! is_object( $record ) || ! method_exists( $record, 'get' ) ) { return; } $out = array(); foreach ( (array) $record->get( 'fields' ) as $id => $f ) { if ( ! is_array( $f ) || self::skip( isset( $f['type'] ) ? $f['type'] : '' ) ) { continue; } $label = ! empty( $f['title'] ) ? $f['title'] : self::label_from_name( $id ); $out[ $label ] = isset( $f['value'] ) ? $f['value'] : ''; } $title = method_exists( $record, 'get_form_settings' ) ? (string) $record->get_form_settings( 'form_name' ) : ''; self::send( 'Elementor', $title, $out ); } /** * Gravity Forms. * * @param array $entry Entry. * @param array $form Form. */ public static function gravity( $entry, $form ) { $out = array(); foreach ( isset( $form['fields'] ) ? (array) $form['fields'] : array() as $field ) { if ( ! is_object( $field ) || self::skip( isset( $field->type ) ? $field->type : '' ) ) { continue; } $value = method_exists( $field, 'get_value_export' ) ? $field->get_value_export( $entry ) : ( isset( $entry[ (string) $field->id ] ) ? $entry[ (string) $field->id ] : '' ); $out[ isset( $field->label ) ? $field->label : '' ] = $value; } self::send( 'Gravity Forms', isset( $form['title'] ) ? $form['title'] : '', $out ); } /** * Ninja Forms. * * @param array $form_data Submission. */ public static function ninja( $form_data ) { $out = array(); foreach ( isset( $form_data['fields'] ) ? (array) $form_data['fields'] : array() as $f ) { if ( ! is_array( $f ) || self::skip( isset( $f['type'] ) ? $f['type'] : '' ) ) { continue; } $out[ isset( $f['label'] ) ? $f['label'] : '' ] = isset( $f['value'] ) ? $f['value'] : ''; } $title = isset( $form_data['settings']['title'] ) ? $form_data['settings']['title'] : ''; self::send( 'Ninja Forms', $title, $out ); } /** * Fluent Forms. * * @param int $entry_id Entry id. * @param array $form_data Submitted values by field name. * @param object $form Form. */ public static function fluent( $entry_id, $form_data, $form ) { $out = array(); foreach ( (array) $form_data as $name => $value ) { $name = (string) $name; if ( 0 === strpos( $name, '_' ) || false !== strpos( $name, 'fluent' ) || false !== strpos( $name, 'captcha' ) ) { continue; } $out[ self::label_from_name( $name ) ] = $value; } $title = is_object( $form ) && isset( $form->title ) ? $form->title : ''; self::send( 'Fluent Forms', $title, $out ); } /** * Jetpack Forms (also the WordPress.com contact form block). * * @param int $post_id Feedback post id. * @param array $fields Field objects by id. * @param bool $is_spam Marked as spam by Akismet. */ public static function jetpack( $post_id, $fields, $is_spam = false ) { if ( $is_spam ) { return; } $out = array(); foreach ( (array) $fields as $id => $f ) { if ( ! is_object( $f ) || ! method_exists( $f, 'get_attribute' ) || self::skip( (string) $f->get_attribute( 'type' ) ) ) { continue; } $label = (string) $f->get_attribute( 'label' ); $label = '' !== $label ? $label : self::label_from_name( $id ); $out[ $label ] = isset( $f->value ) ? $f->value : ''; } $page = wp_get_referer() ? url_to_postid( wp_get_referer() ) : 0; self::send( 'Jetpack Forms', $page ? get_the_title( $page ) : '', $out ); } /** * Forminator. Runs once the submission passed Forminator's checks, just before it is saved. * * @param object $entry Entry being saved. * @param int $form_id Form id. * @param array $data Fields as { name, value }. */ public static function forminator( $entry, $form_id, $data ) { if ( is_object( $entry ) && ! empty( $entry->is_spam ) ) { return; } $out = array(); foreach ( (array) $data as $f ) { if ( ! is_array( $f ) || empty( $f['name'] ) ) { continue; } $name = (string) $f['name']; // Field names are "{type}-{n}", e.g. "email-1" or "upload-2". $type = preg_replace( '/-\d+$/', '', $name ); if ( 0 === strpos( $name, '_' ) || self::skip( $type ) || in_array( $type, array( 'gdprcheckbox', 'stripe', 'paypal', 'postdata', 'calculation', 'page-break' ), true ) ) { continue; } $label = ''; if ( class_exists( 'Forminator_API' ) && method_exists( 'Forminator_API', 'get_form_field' ) ) { $field = Forminator_API::get_form_field( $form_id, $name, true ); $label = is_array( $field ) && ! empty( $field['field_label'] ) ? (string) $field['field_label'] : ''; } $out[ '' !== $label ? $label : self::label_from_name( $type ) ] = isset( $f['value'] ) ? $f['value'] : ''; } $title = ''; if ( class_exists( 'Forminator_API' ) && method_exists( 'Forminator_API', 'get_form' ) ) { $form = Forminator_API::get_form( $form_id ); $title = is_object( $form ) && isset( $form->settings['formName'] ) ? (string) $form->settings['formName'] : ''; } self::send( 'Forminator', $title, $out ); } /** * Formidable Forms. * * @param int $entry_id Entry id. * @param int $form_id Form id. */ public static function formidable( $entry_id, $form_id ) { if ( ! class_exists( 'FrmEntry' ) || ! class_exists( 'FrmField' ) ) { return; } $entry = FrmEntry::getOne( $entry_id, true ); if ( ! is_object( $entry ) || empty( $entry->metas ) ) { return; } $out = array(); foreach ( (array) FrmField::get_all_for_form( $form_id ) as $field ) { if ( ! is_object( $field ) || self::skip( isset( $field->type ) ? $field->type : '' ) || in_array( $field->type, array( 'break', 'end_divider', 'summary', 'form', 'credit_card' ), true ) ) { continue; } if ( isset( $entry->metas[ $field->id ] ) ) { $out[ isset( $field->name ) ? $field->name : '' ] = $entry->metas[ $field->id ]; } } $form = class_exists( 'FrmForm' ) ? FrmForm::getOne( $form_id ) : null; self::send( 'Formidable Forms', is_object( $form ) && isset( $form->name ) ? $form->name : '', $out ); } /** * True for field types that are never sent. * * @param string $type Field type. * @return bool */ private static function skip( $type ) { return in_array( strtolower( (string) $type ), self::$skip_types, true ); } /** * "your-name" / "first_name" -> "Your name" / "First name". * * @param string $name Field name. * @return string */ private static function label_from_name( $name ) { $label = trim( preg_replace( '/[-_\[\]]+/', ' ', (string) $name ) ); return ucfirst( $label ); } /** * Flattens a value to text. * * @param mixed $value Value. * @return string */ private static function text( $value ) { if ( is_array( $value ) ) { $value = implode( ', ', array_map( array( __CLASS__, 'text' ), $value ) ); } if ( ! is_scalar( $value ) ) { return ''; } $value = sanitize_textarea_field( (string) $value ); return function_exists( 'mb_substr' ) ? mb_substr( $value, 0, self::MAX_VALUE ) : substr( $value, 0, self::MAX_VALUE ); } /** * Sends one submission, without waiting for the answer. * * @param string $plugin Form plugin name. * @param string $title Form title. * @param array $fields Label => value. */ private static function send( $plugin, $title, $fields ) { $status = Clientager_Frontend::known_status(); if ( ! is_array( $status ) || empty( $status['forms'] ) ) { return; } $clean = array(); foreach ( $fields as $label => $value ) { $label = sanitize_text_field( (string) $label ); $value = self::text( $value ); if ( '' === $label || '' === $value ) { continue; } $clean[ $label ] = $value; if ( count( $clean ) >= self::MAX_FIELDS ) { break; } } if ( ! $clean ) { return; } $name = sanitize_text_field( (string) $title ); Clientager_Api::request( 'POST', '/form', array( 'form' => $name ? $plugin . ' ยท ' . $name : $plugin, 'fields' => $clean, 'page_url' => esc_url_raw( (string) wp_get_referer() ), ), array( 'blocking' => false, 'timeout' => 5, ) ); } }