Silencing Errors from Certain Plugins and Themes in Query Monitor

When a PHP warning or notice occurs during the page load, Query Monitor displays a coloured notification in the admin toolbar that links to the PHP Errors panel. This is great for debugging but can be an annoyance if a third party plugin or theme continually triggers errors that aren’t your responsibility to fix.

Query Monitor allows you to silence errors from specified plugins or themes. Errors will still be shown in the PHP Errors panel but they won’t trigger a coloured notification in the admin toolbar.

Here’s how you hide PHP notices from a plugin named foo:

add_filter( 'qm/collect/php_error_levels', function( array $levels ) {
	$levels['plugin']['foo'] = ( E_ALL & ~E_NOTICE );
	return $levels;
} );

This code hooks into the qm/collect/php_error_levels filter and specifies the error levels which should get reported by Query Monitor for the specified plugin. The error levels are specified using the same bitmask syntax used for PHP’s error_reporting() function, and in this example is telling Query Monitor to report all errors except notices.

The name to use for the plugin array’s index is what Query Monitor shows as the name for the “Component”, for example “Plugin: foo” ends up as “foo”.

You could also tell Query Monitor to only report warnings from your child theme, and completely silence errors from its parent theme (probably not a good idea):

add_filter( 'qm/collect/php_error_levels', function( array $levels ) {
	$levels['theme']['stylesheet'] = ( E_WARNING & E_USER_WARNING );
	$levels['theme']['template']   = ( 0 );
	return $levels;
} );

Any plugin or theme which doesn’t have an error level specified via this filter is assumed to have the default level of E_ALL, which shows all errors.

To silence deprecated errors from WordPress core:

add_filter( 'qm/collect/php_error_levels', function( $levels ) {
	$levels['core']['core'] = ( E_ALL & ~E_DEPRECATED );
	return $levels;
} );

Finally, if you have special PHP error handling in place on your site and you don’t want Query Monitor to handle errors at all, you can disable the error handling functionality completely:

define( 'QM_DISABLE_ERROR_HANDLER', true );

6 thoughts on “Silencing Errors from Certain Plugins and Themes in Query Monitor”

  1. Since updating Query Monitor Version 3.6.1 To Version 3.6.4
    Compatibility with WordPress 5.5: 100% (according to its author)
    I having an Issue with Query Monitor
    I am now getting a PHP Warning Notice.

    Let’s Got to the beginning.
    I use Siteground Hosting
    I currently have a “Real Cron Job configured”

    So naturally, I have WordPress Cron Disabled Using the following: define(‘DISABLE_WP_CRON’, false);

    For The Real Cron Job I Use the following: define(‘DISABLE_WP_CRON’, true);

    Below Is The Query Monitor Notice:

    Notice Constant DISABLE_WP_CRON already defined 1 wp-config.php:77 Unknown

    Is there a fix?

  2. In the above graphic I’m not clear what 13Q means. Is it an absolute number or a rate?
    My WordPress site limits Queries to 15000/hour. I seem to be hitting that limit but I only see 50Q?

  3. Yes but only on a per-plugin or per-theme basis. For example:

    add_filter( 'qm/collect/php_error_levels', function( array $levels ) {
    	$levels['plugin']['foo'] = ( E_ALL & ~E_DEPRECATED );
    	$levels['theme']['stylesheet'] = ( E_ALL & ~E_DEPRECATED );
    	return $levels;
    } );

Leave a comment