Skip to content

Commit 233fb69

Browse files
committed
Use Feedback class for export data consistency
Instead of raw meta queries, use the same Feedback class that DataViews uses to ensure consistent data formatting and proper field population.
1 parent 37ffcc4 commit 233fb69

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

projects/packages/forms/src/contact-form/class-contact-form-endpoint.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,22 +1197,25 @@ public function export_responses( $request ) {
11971197
$all_fields = array();
11981198

11991199
foreach ( $feedback_posts as $post ) {
1200+
$feedback = Feedback::get( $post->ID );
1201+
if ( ! $feedback ) {
1202+
continue;
1203+
}
1204+
12001205
$post_data = array(
12011206
'ID' => $post->ID,
12021207
'Date' => get_the_date( 'Y-m-d H:i:s', $post ),
1203-
'Author Name' => get_post_meta( $post->ID, '_feedback_author', true ),
1204-
'Author Email' => get_post_meta( $post->ID, '_feedback_author_email', true ),
1205-
'Author URL' => get_post_meta( $post->ID, '_feedback_author_url', true ),
1206-
'IP Address' => get_post_meta( $post->ID, '_feedback_ip', true ),
1208+
'Author Name' => $feedback->get_author(),
1209+
'Author Email' => $feedback->get_author_email(),
1210+
'Author URL' => $feedback->get_author_url(),
1211+
'IP Address' => $feedback->get_ip(),
12071212
'Contact Form' => get_the_title( $post->post_parent ),
12081213
);
12091214

1210-
$all_meta = get_post_meta( $post->ID );
1211-
foreach ( $all_meta as $key => $value ) {
1212-
if ( strpos( $key, '_' ) === 0 ) {
1213-
continue;
1214-
}
1215-
$post_data[ $key ] = is_array( $value ) && count( $value ) === 1 ? $value[0] : ( is_array( $value ) ? implode( ', ', $value ) : $value );
1215+
// Add all form fields from the feedback
1216+
$form_fields = $feedback->get_all_fields();
1217+
foreach ( $form_fields as $field => $value ) {
1218+
$post_data[ $field ] = $value;
12161219
}
12171220

12181221
$all_fields = array_merge( $all_fields, array_keys( $post_data ) );

0 commit comments

Comments
 (0)