@@ -216,7 +216,7 @@ protected function __construct() {
216
216
}
217
217
218
218
// Admin-post action for CSV export
219
- add_action ( 'admin_post_feedback_export ' , array ( $ this , 'admin_post_feedback_export ' ) );
219
+ add_action ( 'admin_post_feedback_export ' , array ( $ this , 'download_feedback_as_csv ' ) );
220
220
add_action ( 'admin_menu ' , array ( $ this , 'admin_menu ' ) );
221
221
add_action ( 'current_screen ' , array ( $ this , 'unread_count ' ) );
222
222
add_action ( 'current_screen ' , array ( $ this , 'redirect_edit_feedback_to_jetpack_forms ' ) );
@@ -2759,9 +2759,13 @@ function ( $selected ) {
2759
2759
/**
2760
2760
* Admin-post handler for CSV export
2761
2761
*/
2762
- public function admin_post_feedback_export () {
2762
+ public function download_feedback_as_csv () {
2763
+
2764
+ if ( ! current_user_can ( 'export ' ) ) {
2765
+ wp_die ( esc_html__ ( 'You do not have permission to export form responses. ' , 'jetpack-forms ' ), 403 );
2766
+ }
2767
+
2763
2768
$ feedback_ids_str = sanitize_text_field ( wp_unslash ( $ _GET ['feedback_ids ' ] ?? '' ) );
2764
- $ post_id = sanitize_text_field ( wp_unslash ( $ _GET ['post_id ' ] ?? '' ) );
2765
2769
$ nonce = sanitize_text_field ( wp_unslash ( $ _GET ['nonce ' ] ?? '' ) );
2766
2770
2767
2771
if ( empty ( $ feedback_ids_str ) || empty ( $ nonce ) ) {
@@ -2775,26 +2779,25 @@ public function admin_post_feedback_export() {
2775
2779
wp_die ( esc_html__ ( 'Security check failed. ' , 'jetpack-forms ' ), 403 );
2776
2780
}
2777
2781
2778
- if ( ! current_user_can ( 'export ' ) ) {
2779
- wp_die ( esc_html__ ( 'You do not have permission to export form responses. ' , 'jetpack-forms ' ), 403 );
2780
- }
2781
-
2782
2782
$ export_data = $ this ->get_export_feedback_data ( $ feedback_ids );
2783
2783
2784
2784
if ( empty ( $ export_data ) ) {
2785
2785
wp_die ( esc_html__ ( 'No responses found to export. ' , 'jetpack-forms ' ), 404 );
2786
2786
}
2787
2787
2788
- $ this ->download_feedback_as_csv ( $ export_data , $ post_id );
2788
+ $ post_id = sanitize_text_field ( wp_unslash ( $ _GET ['post_id ' ] ?? '' ) );
2789
+
2790
+ $ this ->download_feedback_as_csv_export ( $ export_data , $ post_id );
2789
2791
}
2790
2792
2791
2793
/**
2792
- * Download exported data as CSV
2794
+ * Download exported data as a CSV file.
2795
+ * This forces the download of the CSV file.
2793
2796
*
2794
2797
* @param array $data Export data to generate CSV from.
2795
2798
* @param string $post_id Optional. Post ID for filename generation.
2796
2799
*/
2797
- public function download_feedback_as_csv ( $ data = null , $ post_id = '' ) {
2800
+ public function download_feedback_as_csv_export ( $ data = null , $ post_id = '' ) {
2798
2801
if ( empty ( $ data ) ) {
2799
2802
return ;
2800
2803
}
0 commit comments