-1 ) ) as $form ) { $fields = array(); $seen = array(); foreach ( $form->scan_form_tags() as $tag ) { if ( '' === (string) $tag->name || isset( $seen[ $tag->name ] ) || $this->skip_type( $tag->basetype ) ) { continue; } $seen[ $tag->name ] = true; $fields[] = array( 'key' => (string) $tag->name, 'label' => $this->label( (string) $tag->name ), 'type' => (string) $tag->basetype, ); } $forms[ (string) $form->id() ] = array( 'title' => (string) $form->title(), 'fields' => $fields, ); } return $forms; } public function listen() { add_action( 'wpcf7_submit', array( $this, 'on_submit' ), 10, 2 ); } /** * Only real submissions: sent, or valid but the site's email failed. Not spam / invalid / aborted. */ public function on_submit( $form, $result ) { if ( ! in_array( $result['status'] ?? '', array( 'mail_sent', 'mail_failed' ), true ) ) { return; } $submission = WPCF7_Submission::get_instance(); if ( ! $submission ) { return; } $answers = array(); foreach ( (array) $submission->get_posted_data() as $key => $value ) { $answers[ (string) $key ] = $this->text( $value ); } Beon_Notify_Forms::submitted( $this->key(), (string) $form->id(), $answers, (string) $form->title(), $submission ); } /** "your-name" → "Your name (your-name)" — CF7 fields have no labels. */ private function label( $name ) { $pretty = ucfirst( trim( str_replace( array( '-', '_' ), ' ', $name ) ) ); return $pretty === $name ? $name : $pretty . ' (' . $name . ')'; } }