• After following the example in this post:
    EXAMPLE

    I have created a custom WP_List_Table and the above example is to add an ‘Export selected items to CSV’ to the Bulk Actions.

    I am plagued by the following error for every header set to make the file download:

    Warning: Cannot modify header information - headers already sent by (output started at /home/wvnla15/public_html/events/wp-admin/includes/template.php:1981) in /home/wvnla15/public_html/events/wp-content/plugins/wvnla-registrations/wvnla-registrations.php on line 149

    I’ve read thread after thread stating that whitespace can cause this, but editing a core file (/wp-admin/includes/template.php) isn’t really an option. The line in question in the one that starts with ‘<html’ below:

    <!DOCTYPE html>
    <!--[if IE 8]>
    <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php
    	/**
    	 * Fires inside the HTML tag in the admin header.
    	 *
    	 * @since 2.2.0
    	 */
    	do_action( 'admin_xml_ns' );

    So I found another example that offered another clue:

    // Important - Note this is not stored in a function, this is just in the main
    // file, if we ran it through a function headers would already get set.
    if (isset($_GET['page']) && $_GET['page'] === 'my_csv_download') {
        // Just setting some headers for our download
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private", false);
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment; filename=\"my_csv.csv\";" );
        header("Content-Transfer-Encoding: binary");
        echo csv(); // Your CSV goes here.
        exit;
    }

    This shows how to created a menu item that triggers the download by loading a page called ‘my_csv_download’. It suggests that you cannot include headers inside a function. In my code example, the headers are being set inside ‘function process_bulk_action()’.

    I’m having trouble adapting the above code to work with Bulk Actions. Any guidance would be appreciated.

    full code here .

The topic ‘Cannot Modify Header in /wp-admin/includes/template.php’ is closed to new replies.