Support » Plugin: Export Users With Meta » Warning: Headers Already Sent

  • Resolved cleewp

    (@cleewp)


    Thank you so much for this plug-in, extremely helpful!

    Quick suggestion. When I first ran the export, I was getting a page of users, along with an error/warning that Headers had already been sent.

    I simply moved

    $this->send_file_stream_http_headers();

    To the first thing in the try function, so the headers were the first thing to write to the page (as opposed to the CSV).

    So, the try at line 209 is now

    try {
    			$this->send_file_stream_http_headers();
    			$csv = ( new CSV() )
    				->set_filename( 'php://output' )
    				->set_columns( $columns )
    				->set_delimiter( $delimiter_char )
    				->set_enclosure( $enclosure_char )
    				->set_allowlist( $allowlist )
    				->set_denylist( $denylist );
    

    And it works like a dream. Not sure if that would have far reaching effects or not — but so far, have not seen any issues.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Daniel Loureiro

    (@loureirorg)

    Nice catch, cleewp!

    I got amazed when I moved the send...headers to after the data sending and didn’t get the “headers already sent” error. But as it had worked, I moved on. I was fixing another issue: some errors generated by the CSV library were not being displayed to the user, for example, the message “Delimiter and Separator characters can’t be the same” was being sent as the CSV file instead of showing on the screen. That’s why the send...headers has been moved to after all the exceptions have a chance to be triggered. But I guess it has only worked on my tests due to some of my local settings (ex. “output_buffer: on”).

    Thank you for informing this error and taking some time finding the source. I really apreaciate it. I will work on a solution that fixes both issues and also add some tests for these scenarios, so it won’t happen again.

    Plugin Author Daniel Loureiro

    (@loureirorg)

    Fixed on 0.6.7.

    Thread Starter cleewp

    (@cleewp)

    Outstanding! Thank you!

    Plugin Author Daniel Loureiro

    (@loureirorg)

    Many thanks for the donation!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Warning: Headers Already Sent’ is closed to new replies.