0

There is an error whenever I try to update a post and have WP_DEBUG set to true in config.php. I am running wordpress 4.5 with and underscores based theme i'm developing. It appears to come from the core files but I don't see how that's possible. Any ideas what might be causing the problem? I was editing without debug on for awhile so I cannot tell at which point the problem started showing up.

Warning: Cannot modify header information - headers already sent by (output started at /Users/Blake_Eric/Projects/wp-test-site/wp-content/plugins/wordpress-importer/wordpress-importer.php:38) in /Users/Blake_Eric/Projects/wp-test-site/wp-admin/post.php on line 197

Here is the code this refers to

// Session cookie flag that the post was saved
if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
    setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
}

Warning: Cannot modify header information - headers already sent by (output started at /Users/Blake_Eric/Projects/wp-test-site/wp-content/plugins/wordpress-importer/wordpress-importer.php:38) in /Users/Blake_Eric/Projects/wp-test-site/wp-includes/pluggable.php on line 1171

refers to

    $location = apply_filters( 'wp_redirect', $location, $status );

/**
 * Filter the redirect status code.
 *
 * @since 2.3.0
 *
 * @param int    $status   Status code to use.
 * @param string $location The path to redirect to.
 */
$status = apply_filters( 'wp_redirect_status', $status, $location );

if ( ! $location )
    return false;

$location = wp_sanitize_redirect($location);

if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' )
    status_header($status); // This causes problems on IIS and some FastCGI setups

header("Location: $location", true, $status);

return true;

I deleted the referenced plugin and the error still occurs

Any advice would be much appreciated.

BlakeEric
  • 19
  • 3
  • Try to replace `wp-includes` & `wp-admin` folders from fresh WordPress 4.5. It should solve this issue. – Milap Apr 14 '16 at 06:56
  • Generally comes from where something is throwing an error, you are outputting something with print_r. Looks like that might be trying to set a cookie but something else was already outputted. – weaveoftheride Dec 09 '16 at 13:50

2 Answers2

0

How to Fix Warning: Cannot modify header information in WordPress.

  • Too many spaces before, in between or after the beginning PHP tags
  • There are too many unneeded spaces or blank lines in a specific part of a document
  • Incorrect PHP Encoding Format.
  • -

1. Open wp-config with editor, and remove all spaces before “<?php” and after “?>“

enter image description here

enter image description here

RïshïKêsh Kümar
  • 4,734
  • 1
  • 24
  • 36
-2

Thank you to the other two suggested answers!

\wp-admin\post.php on line 231 is where I had my error.

I build my own plugin some time back -- and sure enough, it was missing ?> (the PHP closing part) a the very end of one of the files.

So if it is missing all together, add it.


Update - PHP closing tag ?> should be omitted at end

Please disregard my above suggestion. I left it there as reference point. And thank you Vijay Hardaha for informing me about that fact!

I had another look at my file and found this at the end


*************** */


I changed the above to this, and now my plugin works.


*************** 
*/


Note: PHP 8.1.1 did not have that problem, it is after upgrading to 8.1.10 that my plugin stopped working.

MeSo2
  • 450
  • 1
  • 7
  • 18
  • `?>` closing php tag from the end of the file should be left alone. if you close the tag and after that, you have empty lines you'll end up in the `modify header` warning. – Vijay Hardaha Sep 09 '22 at 00:17
  • @VijayHardaha I have no empty lines after the `?>` PHP closing tag. Would this still be considered OK? Having added that tag at the end of my plugin sure make my WordPress work again. – MeSo2 Sep 09 '22 at 00:31
  • I think whom ever downgraded me did not read the details of my post. It is my very own plugin (my-pluginfile-metabox.php) in which I forgot to close the PHP tag -- and it is not the `post.php` file I closed! – MeSo2 Sep 09 '22 at 00:58
  • 2
    I am guessing, you never used WPCS, and you don't follow the WPCS. Just for your knowledge, please check this old trac ticket https://core.trac.wordpress.org/ticket/10633, Also check this guideline https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#remove-trailing-spaces and in future, if you ever started to use PHPCS/WPCS then you'll understand it better – Vijay Hardaha Sep 09 '22 at 02:57