[wp-trac] [WordPress Trac] #52725: WP5.7-RC2-50494 Warning: Cannot modify header information

WordPress Trac noreply at wordpress.org
Mon Mar 8 14:15:05 UTC 2021


#52725: WP5.7-RC2-50494 Warning: Cannot modify header information
----------------------------+-----------------------------
 Reporter:  mitfi           |       Owner:  (none)
     Type:  defect (bug)    |      Status:  closed
 Priority:  normal          |   Milestone:
Component:  Administration  |     Version:  trunk
 Severity:  normal          |  Resolution:  invalid
 Keywords:                  |     Focuses:  administration
----------------------------+-----------------------------
Changes (by hellofromTonya):

 * keywords:  reporter-feedback =>
 * status:  new => closed
 * resolution:   => invalid
 * milestone:  Awaiting Review =>


Comment:

 Hello @mitfi,

 Thank you for providing more information including a link to your plugin
 that has the problem.

 The above gif shows the Emergency Management plugin running on WordPress
 5.6.2 and PHP 5.6. Notice the `"Warning: Cannot modify header information
 - headers already sent"` PHP warning when navigating to `Users` > `EM -
 Reset SALTs & Sessions` submenu.

 Why is this warning appearing?

 tl;dr

 The plugin is attempting to redirect after web page's `header` and HTML
 output have already started being sent out to the browser. It's too late
 to do a redirect.

 Longer explanation:

 The callback that is registered to the
 [https://developer.wordpress.org/reference/functions/add_submenu_page/
 `add_submenu_page`]'s function argument is used to **output** that menu's
 admin page.

 >$function
 >(callable) (Optional) The function to be called to output the content for
 this page.

 By the time the callback runs, the admin area's HTML output around it has
 already been sent outputted. What admin content? The admin top and sidebar
 menus. Then the specific menu's content area is rendered by the callback
 registered to `add_submenu_page`.

 In the plugin, `mfem_warning_saltsform_handler_pre` is the registered
 callback to render the submenu's page content. That callback then invokes
 `mfem_warning_saltsform_handler` which then invokes `wp_redirect`. It's
 too late to do a `wp_redirect` here because the admin page's header and
 HTML have already started being outputted for the browser.

 The problem experienced is not due to WordPress 5.7 or 5.6.2, but rather
 because of when the redirect is happening in the plugin.

 Closing this ticket as it's not a WordPress core issue. For further help
 on how to implement the redirect logic, please try the support forums:
 https://wordpress.org/support/forums/

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52725#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list