title: Export CSV file from custom WP_List_Table class
body: <p>Im trying to export data from bulk action in custom WP_List_Table class. I have following function for exporting data but I get "headers already sent" errors all the time i want to export data. Could you please point what I'm doing wrong?</p>
  
  <pre><code>public static function export_mailings ($data) {
  
      if ( !current_user_can( 'manage_options') ) {
         return;
      }
  
      global $wpdb;
      $filename = 'mailings-' . date('d-M-Y') . '.csv';
  
      $sql = "SELECT * FROM {$wpdb-&gt;prefix}wpsml WHERE `id` IN (" . implode(',', array_map('intval', $data)) . ")";
      $results = $wpdb-&gt;get_results($sql);
  
      $csv_headers = array();
      $csv_headers[] = 'Date';
      $csv_headers[] = 'Name';
      $csv_headers[] = 'Email';
  
      $filename = 'export' . date('d-M-Y');
      $output_handle = fopen('php://output', 'w');
  
      header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
      header( 'Content-Description: File Transfer' );
      header( 'Content-type: text/csv' );
      header( 'Content-Disposition: attachment; filename=' . $output_filename );
      header( 'Expires: 0' );
      header( 'Pragma: public' );
  
      fputcsv($output_handle, $csv_headers);
  
      foreach ($results as $result) {
          fputcsv($output_handle, (array)$result);
      }
  
      fclose($output_handle);
      die();
  }
  </code></pre>