Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable WordPress "PHP Deprecated:" messages from debug.log

Tags:

wordpress

I have searched & tried various solutions to this problem, none of them work.

It looks like WordPress ignores the following and logs Deprecated messages anyway:

error_reporting(E_ALL ^ E_DEPRECATED);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED);

My php.ini:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

My wp-config.php:

<?php
define( 'WP_CACHE', true );
error_reporting(E_ALL ^ E_DEPRECATED);

...

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Plugins are spamming my debug.log file with PHP Deprecated: ... log messages. Several GB generated each day. Makes debug.log unusable.

I report to Plugin developers, but some do not fix in timely manner. I cannot fix myself, as Plugin update overwrite my changes.

What is the solution to disable these?

Server:

  • Running Bitnami/Wordpress on AWS Lightsail (2gb 2vcpu)
  • Linux 5.10.0-25-cloud-amd64 x86_64
  • PHP ver.8.2.10
like image 812
Martin Avatar asked May 15 '26 06:05

Martin


1 Answers

UPDATE
I've created a WordPress plugin to add, remove and control the MU plugin from the comfort of your admin panel.

Original post
No matter what you set for error_reporting() inside the wp-config.php and no matter what's in the php.ini, it will be overwritten by WordPress in function wp_debug_mode() (in wp-includes/load.php called by wp-settings.php) as follows:

if ( WP_DEBUG ) {
    error_reporting( E_ALL );
    //...
} else {
    error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
}

You could, of course, change E_ALL to E_ALL ^ E_DEPRECATED inside wp-includes/load.php, but that is (eventually) going to be overwritten with WordPress updates.

Another (persistent) option is to use a must use plugin to reset error_reporting (again). This however will not mute deprecation warnings resulting from the WordPress core. To do that anyway, create the directory wp-content/mu-plugins if it doesn't exist. Inside that directory add __error_reporting.php with the following contents:

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

Must use plugins will be loaded in alphabetical order before all other plugins (hence the __ prefix).

like image 151
volkerschulz Avatar answered May 19 '26 05:05

volkerschulz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!