Silence notices when WP_DEBUG is true

Setting WP_DEBUG to true in wp-config.php turns on errors, warnings, and notices so you can see all the places your code needs attention. This is fine as far as it goes, but WordPress makes it very cumbersome to modify the error reporting level so only errors and warnings are displayed while notices are silenced.

However, after much trial-and-error I figured it out. In a nutshell, you need to create a PHP file in /wp-content/mu-plugins/ that contains the following:

<?php
error_reporting( E_ALL ^ (E_NOTICE | E_USER_NOTICE) );

Setting this in php.ini and wp-config.php never worked, I believe, because WordPress would override the value when it saw that WP_DEBUG was set to true.

But by setting the error_reporting level by way of a “must use” plugin, it happens late enough in the request cycle to actually make a difference.

Refs: https://wycks.wordpress.com/2013/12/05/how-to-remove-error-notices-using-wordpresss-wp_debug/

(I came across the above article early in the debugging process, but it didn’t seem to work at the time. Only once I remembered it and tried after about an hour of debugging did it work.)

Making changes to php.ini FPM

A big chunk of the time I spent debugging the above issue was because I couldn’t get the php.ini config file inside Homestead to pick up any changes I made to it.

Long story short: sudo kill <pid of php-fpm master process> did the trick.