__( 'Any Jetpack Form Submitted (site-wide)', 'advanced-form-integration' ), ); } // Get Jetpack Forms Fields function adfoin_jetpackforms_get_form_fields( $form_provider, $form_id ) { if ( $form_provider !== 'jetpackforms' || $form_id !== 'anyForm' ) { return; } // Jetpack's own default contact-form template — reliable common ground // across most installs. Fields beyond these vary per-form and aren't // enumerable in advance, so they're only available via all_fields_json. return array( 'name' => __( 'Name', 'advanced-form-integration' ), 'email' => __( 'Email', 'advanced-form-integration' ), 'subject' => __( 'Subject', 'advanced-form-integration' ), 'message' => __( 'Message', 'advanced-form-integration' ), 'post_id' => __( 'Post ID (page the form was on)', 'advanced-form-integration' ), 'feedback_post_id' => __( 'Feedback Post ID (the submission record)', 'advanced-form-integration' ), 'all_fields_json' => __( 'All Fields (JSON, for fields not listed above)', 'advanced-form-integration' ), ); } // Handle Jetpack Forms Submission add_action( 'grunion_after_feedback_post_inserted', 'adfoin_jetpackforms_handle_submission', 10, 4 ); function adfoin_jetpackforms_handle_submission( $post_id, $fields, $is_spam, $entry_values ) { if ( $is_spam ) { return; } $integration = new Advanced_Form_Integration_Integration(); $saved_records = $integration->get_by_trigger( 'jetpackforms', 'anyForm' ); if ( empty( $saved_records ) ) { return; } $contact_form_id = isset( $_POST['contact-form-id'] ) ? sanitize_text_field( wp_unslash( $_POST['contact-form-id'] ) ) : ''; $posted_data = array( 'post_id' => $entry_values['entry_page'] ?? '', 'feedback_post_id' => $post_id, ); $all_fields = array(); $name_guess = ''; $email_guess = ''; $subject_guess = ''; $message_guess = ''; if ( is_array( $fields ) ) { foreach ( $fields as $field ) { if ( ! is_object( $field ) || ! method_exists( $field, 'get_attribute' ) ) { continue; } $field_id = $field->get_attribute( 'id' ); $label = $field->get_attribute( 'label' ); $type = $field->get_attribute( 'type' ); $post_key = $contact_form_id ? ( 'g' . $contact_form_id . '-' . $field_id ) : ''; $value = ( $post_key && isset( $_POST[ $post_key ] ) ) ? adfoin_sanitize_text_or_array_field( $_POST[ $post_key ] ) : ''; if ( $label ) { $all_fields[ $label ] = $value; } // Best-effort aliasing onto the common field names, based on // Jetpack's own field type/label conventions. $label_lower = strtolower( (string) $label ); if ( 'email' === $type || false !== strpos( $label_lower, 'email' ) ) { $email_guess = $value; } elseif ( 'name' === $type || false !== strpos( $label_lower, 'name' ) ) { $name_guess = $value; } elseif ( false !== strpos( $label_lower, 'subject' ) ) { $subject_guess = $value; } elseif ( 'textarea' === $type || false !== strpos( $label_lower, 'message' ) || false !== strpos( $label_lower, 'comment' ) ) { $message_guess = $value; } } } $posted_data['name'] = $name_guess; $posted_data['email'] = $email_guess; $posted_data['subject'] = $subject_guess; $posted_data['message'] = $message_guess; $posted_data['all_fields_json'] = wp_json_encode( $all_fields ); adfoin_dispatch_integrations( $saved_records, $posted_data ); }