id ?? 0 ) : 0; $title = is_object( $form ) ? (string) ( $form->title ?? '' ) : ''; $labels = $this->labels( $form ); $out = array(); foreach ( (array) $form_data as $key => $value ) { $key = (string) $key; if ( '' === $key || '_' === $key[0] || 0 === strpos( $key, 'fluentform_' ) || false !== strpos( $key, 'captcha' ) || false !== strpos( $key, 'turnstile' ) ) { continue; } $out[ $key ] = array( 'label' => $labels[ $key ] ?? $key, 'value' => $value, ); } $url = $form_id && $entry_id ? admin_url( 'admin.php?page=fluent_forms&route=entries&form_id=' . $form_id . '#/entries/' . (int) $entry_id ) : ''; $this->notify( $form_id, $title, $out, $entry_id ? (int) $entry_id : '', $url ); } /** * Field labels from the form definition, keyed by input name. * * @param object $form Form. * @return array */ private function labels( $form ) { $labels = array(); if ( ! is_object( $form ) || empty( $form->form_fields ) ) { return $labels; } $def = json_decode( (string) $form->form_fields, true ); if ( ! is_array( $def ) || empty( $def['fields'] ) ) { return $labels; } $walk = static function ( $fields ) use ( &$walk, &$labels ) { foreach ( (array) $fields as $field ) { if ( ! is_array( $field ) ) { continue; } $name = $field['attributes']['name'] ?? ''; $label = $field['settings']['label'] ?? ( $field['settings']['admin_field_label'] ?? '' ); if ( $name && $label ) { $labels[ (string) $name ] = wp_strip_all_tags( (string) $label ); } if ( ! empty( $field['columns'] ) ) { foreach ( (array) $field['columns'] as $column ) { $walk( $column['fields'] ?? array() ); } } } }; $walk( $def['fields'] ); return $labels; } }