Disabling Strict Standards Errors in WordPress 3.7 with PHP 5.4

10,535

In Wordpress 3.7, the function wp_debug_mode (defined in wp-includes/load.php, and called from wp-setings.php) sets error_reporting( E_ALL ).

Since wp-settings.php is itself loaded at the end of wp-config.php, you cannot change this setting from wp-config.php (or rather, you can, but it will be overridden).

A solution is to create a "Must Use plugin", that is to say a .php file located in the /wp-content/mu-plugins/ folder containing :

<?php
if (WP_DEBUG && WP_DEBUG_DISPLAY) 
{
   ini_set('error_reporting', E_ALL & ~E_STRICT & ~E_DEPRECATED);
}
Share:
10,535
jeremyzilar
Author by

jeremyzilar

Director of Digital.gov at the General Services Administration + Strategist @ 18F. Formerly, editorial strategist at the NYTimes.

Updated on July 24, 2022

Comments

  • jeremyzilar
    jeremyzilar almost 2 years

    I am trying to disable STRICT Error reporting in WordPress 3.7 via my php.ini file after updating my computer to OS X 10.9. I am running PHP Version 5.4.17, the one that ships with Mavericks.

    In my wp-config.php file, I have enabled define('WP_DEBUG', true); which was on a working fine before upgrading my OS and as a result, PHP.

    In the php.ini file, I have tried setting error_reporting to:

    error_reporting = E_ALL
    

    or

    error_reporting = E_ALL & ~E_STRICT
    

    or

    error_reporting = E_ALL & ~E_DEPRECATED
    

    even

    error_reporting = 0
    

    But the errors still appear.

    display_errors is set to Off:

    display_errors = Off
    

    After each change to the file, I am restarting apache and httpd with these two commands:

    httpd -k restart
    apachectl restart
    

    The php.ini file I am editing is the same one being pointed to in phpinfo() AND just to make sure changes are going through, I have been editing the error_prepend_string value:

    error_prepend_string = "<span style='color: #ff0000'>ERROR: "
    

    and those changes are coming through in the error.

    Any thoughts on how to debug this would be much appreciated.

  • frnhr
    frnhr over 10 years
    This works partially, because some error happen before functions.php gets loaded. +1 for the idea however :)
  • adelval
    adelval over 10 years
    I didn't see any errors in my (limited) testing, though I suppose it can happen when loading plugins. Looking at Wordpress load order, maybe a solution is to create a very simple plugin to set error_reporting, making sure it is loaded before any other plugin (by default they are loaded in alphabetical order).
  • Radley Sustaire
    Radley Sustaire about 10 years
    For best results, use the solution provided by adelval, but put it in a .php file such as: /wp-content/mu-plugins/errorreporting.php. "mu" stands for "must-use" and will be loaded before the theme and plugins, but after the error reporting has been set. You don't have to activate it, either, since they are "must-use".
  • adelval
    adelval over 8 years
    Thanks @Alexandre for the edit, it improves the answer by incorporating the comment by RadGH
  • Kim Steinhaug
    Kim Steinhaug about 6 years
    This didnt help me either as the deprecated error message is done before it even gets to the mu-plugin. In my case the problem is in wp-db.php, where the error is: Deprecated: mysql_connect()
  • Martin Eckleben
    Martin Eckleben over 5 years
    THIS! - Thank you so much for it