Skip to content

Commit d4ab5b9

Browse files
committed
Keep the previous method as it was
1 parent 8c58151 commit d4ab5b9

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-plugin.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected function __construct() {
216216
}
217217

218218
// 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' ) );
220220
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
221221
add_action( 'current_screen', array( $this, 'unread_count' ) );
222222
add_action( 'current_screen', array( $this, 'redirect_edit_feedback_to_jetpack_forms' ) );
@@ -2759,9 +2759,13 @@ function ( $selected ) {
27592759
/**
27602760
* Admin-post handler for CSV export
27612761
*/
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+
27632768
$feedback_ids_str = sanitize_text_field( wp_unslash( $_GET['feedback_ids'] ?? '' ) );
2764-
$post_id = sanitize_text_field( wp_unslash( $_GET['post_id'] ?? '' ) );
27652769
$nonce = sanitize_text_field( wp_unslash( $_GET['nonce'] ?? '' ) );
27662770

27672771
if ( empty( $feedback_ids_str ) || empty( $nonce ) ) {
@@ -2775,26 +2779,25 @@ public function admin_post_feedback_export() {
27752779
wp_die( esc_html__( 'Security check failed.', 'jetpack-forms' ), 403 );
27762780
}
27772781

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-
27822782
$export_data = $this->get_export_feedback_data( $feedback_ids );
27832783

27842784
if ( empty( $export_data ) ) {
27852785
wp_die( esc_html__( 'No responses found to export.', 'jetpack-forms' ), 404 );
27862786
}
27872787

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 );
27892791
}
27902792

27912793
/**
2792-
* Download exported data as CSV
2794+
* Download exported data as a CSV file.
2795+
* This forces the download of the CSV file.
27932796
*
27942797
* @param array $data Export data to generate CSV from.
27952798
* @param string $post_id Optional. Post ID for filename generation.
27962799
*/
2797-
public function download_feedback_as_csv( $data = null, $post_id = '' ) {
2800+
public function download_feedback_as_csv_export( $data = null, $post_id = '' ) {
27982801
if ( empty( $data ) ) {
27992802
return;
28002803
}

0 commit comments

Comments
 (0)