prop( $field, 'type' ); if ( $this->skip_type( $type ) || in_array( $type, array( 'page', 'captcha' ), true ) ) { continue; } $id = (string) $this->prop( $field, 'id' ); $fields[] = array( 'key' => $id, /* translators: %s: field id */ 'label' => wp_strip_all_tags( (string) $this->prop( $field, 'label' ) ) ?: sprintf( __( 'Field %s', 'beon-chat' ), $id ), 'type' => $type, ); } $forms[ (string) $form['id'] ] = array( 'title' => (string) ( $form['title'] ?? '' ), 'fields' => $fields, ); } return $forms; } public function listen() { add_action( 'gform_after_submission', array( $this, 'on_submit' ), 10, 2 ); } public function on_submit( $entry, $form ) { if ( 'spam' === ( $entry['status'] ?? '' ) ) { return; } $answers = array(); foreach ( (array) ( $form['fields'] ?? array() ) as $field ) { $id = (string) $this->prop( $field, 'id' ); if ( is_object( $field ) && method_exists( $field, 'get_value_export' ) ) { $value = $field->get_value_export( $entry, $id, true ); } else { $value = $entry[ $id ] ?? ''; } $answers[ $id ] = $this->text( $value ); } Beon_Notify_Forms::submitted( $this->key(), (string) ( $form['id'] ?? '' ), $answers, (string) ( $form['title'] ?? '' ), $entry ); } /** GF_Field objects and plain arrays (older add-ons) alike. */ private function prop( $field, $name ) { if ( is_object( $field ) ) { return $field->$name ?? ''; } return is_array( $field ) ? ( $field[ $name ] ?? '' ) : ''; } }