I am currently writing a plugin that contains a report based on a mysql query. I would like to export this query information to CSV. Simple enough, I've done it many times outside of WordPress.
I'm currently receiving an error regarding headers already sent. I know what causes this error, but cannot find in my code where the issue is.
I have tried removing all other plugins, and even tried other plugins that also export CSV. The plugins that export CSV work just fine, and when my plugin is the only one activated, the error is still thrown so I am pretty sure it's an error on my part.
Also need to include that this is on a multisite network activated plugin.
The error points to the first header line:
if (isset($_POST['txtExport'])) {
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=birts.csv");
header("Pragma: no-cache");
header("Expires: 0");
foreach ($incidentReport as $vals) {
echo "\"".$vals->student_id."\",\"".$vals->incident_desc."\",\"".$vals->incident_time."\",\"".$vals->incident_rating."\",\"".$vals->reported_by."\"\n<br/>";
}
exit;
}
Below is the actual triggered error: Warning: Cannot modify header information - headers already sent by (output started at /home/plumwd/public_html/multisite/wp-admin/admin-header.php:28) in /home/plumwd/public_html/multisite/wp-content/plugins/bart/birts_dashboard.php on line 20
I have WP_DEBUG set to true and am showing no other errors.
Thanks!