I have a method that creates a downloadable CSV on the fly when a button is clicked:
header( 'Content-type: text/csv' );
header( 'Cache-Control: no-store, no-cache' );
header( 'Content-Disposition: attachment; filename="email_list.csv"' );
$outstream = fopen( 'php://output', 'w' );
fputcsv( $outstream, $csv->header );
foreach ( $csv->rows as $row ) {
fputcsv( $outstream, $row );
}
fclose( $outstream );
exit();
When I run the class file through PHP Code Sniffer I get the following warnings:
63 | WARNING | File operations should use WP_Filesystem methods instead of
| | direct PHP filesystem calls. Found: fopen()
71 | WARNING | File operations should use WP_Filesystem methods instead of
| | direct PHP filesystem calls. Found: fclose()
As I understand it WP_Filesystem
is necessary when dealing with files on the server. I would like to know if it is necessary when creating downloadable files on the fly like my example above. If so, why?