How do I hide “headers already sent” warnings in my PHP script?

I have written the below script (snipped) that includes the WordPress functions, however it appears one of the plugins is trying to start a session when it has already been started:

<?php
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');

...
?>

I get the following in my php errors log:

Read More
<b>Warning</b>:  session_start(): Cannot send session cookie - headers already sent in <b>/home/sp32/public_html/wp-content/plugins/woocommerce-abandon-cart-pro/woocommerce-ac.php</b> on line <b>44</b><br />
<br />
<b>Warning</b>:  session_start(): Cannot send session cache limiter - headers already sent in <b>/home/sp32/public_html/wp-content/plugins/woocommerce-abandon-cart-pro/woocommerce-ac.php</b> on line <b>44</b><br />

I’m assuming this is an error in the plugin itself, however I want to prevent these warnings from showing in my log file for my specific script. How would I go about that? Ideally I don’t want to hide all warnings, just this one.

Note that is not a duplicate- I am not asking how to fix the issue (because the issue lies in a 3rd party plugin), I am asking how to suppress the warning messages.

Related posts

Leave a Reply

1 comment

  1. There are three options I see here:

    1. Fix the offending code. As you have mentioned, this may not be optimal with 3rd party code.

    2. Ask for a refund, and replace this plugin with something well written; specifically, something that abides by an accepted coding standard such as PSR-2, or pear.

    3. Find where the offending files are included (or offending functions are called and wrap them in calls to change the error reporting level (code below). The downside to this is that your sessions will not work, since the headers have already been sent by the plugin; this prevents a session cookie from being set, making the browser unrecognized by php sessions.

       $previousErrorLevel = error_reporting();
      error_reporting(E_ERROR);
       //offending code inclusion or call here
      error_reporting($previousErrorLevel);