The MU forums have moved to WordPress.org

blank wp-admin page for CSV export (2 posts)

  1. mdgross
    Member
    Posted 14 years ago #

    I have a plug-in that generates a CSV file. The CSV generator script sends a few php header() commands. It looks like this:

    <?php
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"my-data.csv\"");
    echo $data;
    ?>

    The user will be accessing the CSV generator from within wp-admin. The problem is that wordpress automatically outputs its own admin header, nav, footer, etc. This causes the CSV script to fail because the header information has already been sent.

    Is it possible to call the csv generator from inside wp-admin without it trying to generate all the WordPress code too?

    I think one possible solution would be to put the csv generator file outside of WordPress but I don't want people to be able to access it outside of WordPress. Also, I don't think this would be a good idea because we're using WordPress permissions to control who gets to access the exporter.

  2. mdgross
    Member
    Posted 14 years ago #

    Figured it out...

    if(isset($_GET['export'])) {
    	add_action('admin_init', 'make_csv_file', 1);
    }
    
    function make_csv_file(){
    	header("Content-type: application/octet-stream");
    	header("Content-Disposition: attachment; filename=\"my-data.csv\"");
    	echo $data;
    	exit;
    }

About this Topic