Unusual 'Headers already sent' error. No w

2019-07-22 17:55发布

Before you start telling me there are already 10000000 posts on this error, I know.

I am working on a wordpress plugin and am recieving the following error when submitting my edit pages:

Warning: Cannot modify header information - headers already sent by (output started at ***\wp-content\plugins\***\meta-class-load.php:1067) in ***\wp-includes\pluggable.php on line 934

What's different about this error is the line it references does not interface with the header, nor output content before. I have checked for whitespace surrounding php tags, and there is none :P

This is the contents (and surrounds) of line 1067:

        $name = $field['id'];
        $type = $field['type'];
        $old  = $this->get_meta($post->ID, $field); // THIS IS THE LINE
        $new = isset($_POST[$name]) ? $_POST[$name] : ($field['multiple'] ? array() : '');

Any ideas or solutions would be helpful. Thanks!

3条回答
再贱就再见
2楼-- · 2019-07-22 18:02

Never output anything before sending the HEADER, if you do so you will not be able to send the header and it will throw an error !
It's also a good practice to set error_reporting(0) on production server to make sure that no error gets shown before header

查看更多
祖国的老花朵
3楼-- · 2019-07-22 18:05

No output can be sent before all headers are sent. One of the files listed in the error, or possibly a file included by one of those files, is outputting something. It could be something intentional, a stray bit of white space, a warning or an error message.

To prevent the error you can try calling either ob_clean(); or ob_end_clean(); to clear the output buffer right before your header call. ob_end_clean(); is almost always successful in these cases.

查看更多
做个烂人
4楼-- · 2019-07-22 18:21

1067 is the line that outputs content. Line 934 is the one setting the header. I think you have them backwards.

查看更多
登录 后发表回答