[wp-trac] [WordPress Trac] #63501: wp_iframe sends output before send_headers hook causing PHP headers sent notice

WordPress Trac noreply at wordpress.org
Thu May 29 07:07:21 UTC 2025


#63501: wp_iframe sends output before send_headers hook causing PHP headers sent
notice
--------------------------+-----------------------------
 Reporter:  kkmuffme      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 /wp-admin/media-upload.php?post_id=1234&type=image&TB_iframe=1&tab=library

 {{{#!php
 <?php
 add_action( 'send_headers', function() { header( 'X-Foo: bar' ); }, 10, 0
 );
 }}}

 will report a PHP notice for headers already sent.

 media_upload_library() => wp_iframe() => media_upload_library_form() =>
 wp_edit_attachments_query() executes the main query, which calls the
 send_headers hook

 However wp_iframe has already started output at that point.

 The easy fix is to just ob_start() buffer the whole thing, however, since
 this is media, this has massive performance drawbacks both on the server
 (memory consumption, nginx potentially buffering to file if output exceeds
 buffer size) and the user (loading is delayed until whole page is loaded
 instead of incrementally)
 The correct fix would be to ensure we run the main query early before
 wp_iframe starts output

 Secondly, I think adding a wp doing it wrong in send_headers if
 headers_sent() would make sense to prevent similar issues in the future
 and to warn other people of making a similar mistake.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63501>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list