Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kcristiano/eb07c59c6f1ed785d7c2bc5ecb7e8168 to your computer and use it in GitHub Desktop.
Save kcristiano/eb07c59c6f1ed785d7c2bc5ecb7e8168 to your computer and use it in GitHub Desktop.
A WordPress plugin that suppresses warnings created by various plugins and themes in WordPress.
<?php
/**
* Plugin Name: Suppress Log Warnings
* Plugin URI: https://gist.github.com/christianwach/7d2bb481f9efe185f2b8
* Description: Suppresses annoying warnings generated by various plugins.
* Version: 1.0
*
* Put this plugin in /wp-content/mu-plugins/
*
* @package CMW_Suppress_Log_Warnings
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Suppress Warnings Class.
*
* A class that holds plugin functionality.
*
* @since 1.0
*/
class CMW_Suppress_Log_Warnings {
/**
* Constructor.
*
* @since 1.0
*/
public function __construct() {
// Selectively suppress warnings.
set_error_handler( [ &$this, 'errors_suppress' ] );
// Suppress Akismet logging.
add_filter( 'akismet_debug_log', [ $this, 'akismet_suppress' ] );
// Disable Query Monitor's error handling.
if ( ! defined( 'QM_DISABLE_ERROR_HANDLER' ) ) {
define( 'QM_DISABLE_ERROR_HANDLER', true );
}
}
/**
* Suppress errors generated by specified plugins.
*
* @since 1.0
*
* @param int $errno The error number.
* @param string $errstr The error message.
* @param string $errfile Path to the file that caused the error.
* @return bool True to suppress error reporting; false to use default error handler.
*/
public function errors_suppress( $errno, $errstr, $errfile = '' ) {
// Return true to disable all strict notices.
if ( E_STRICT == $errno ) {
//return true;
}
// Do not display these notices:
$patterns = [
// Annoying CiviCRM Smarty notices.
'uploads/civicrm/templates_c',
'files/civicrm/templates_c',
// Older BuddyPress Group extensions.
'Group_Extension::display',
// Annoying BuddyPress notices.
'bp_setup_current_user was called',
'bp_setup_current_user wurde', // in German
// Annoying bbPress notices.
'bbp_setup_current_user was called',
'bbp_setup_current_user wurde', // in German
// Suppress older widget notices. Comment out to debug.
'The called constructor method for WP_Widget',
'WP_Widget ist seit Version 4.3.0', // in German
// All in one Event Calendar
'All-in-One Event Calendar: preg_match',
'All-in-One Event Calendar: preg_split',
'All-in-One Event Calendar: Automatic conversion',
'All-in-One Event Calendar: Return type of Ai1ec_Abstract_Query',
'All-in-One Event Calendar: Trying to access array offset',
'All-in-One Event Calendar:',
];
foreach ( $patterns as $pattern ) {
$pattern = str_replace( [ '/', '\\' ], DIRECTORY_SEPARATOR, $pattern );
if ( false !== strpos( $errstr, $pattern ) ) {
return true;
}
if ( false !== strpos( $errfile, $pattern ) ) {
return true;
}
}
// The path was not found, so report the error.
return false;
}
/**
* Suppress debug logging generated by the Akismet plugin.
*
* @since 1.0
*
* @return bool True to allow error reporting; false to disallow.
*/
public function akismet_suppress() {
return false;
}
}
/**
* Gets a reference to this plugin.
*
* @since 1.0
*
* @return CMW_Suppress_Log_Warnings $plugin The plugin reference.
*/
function cmw_suppress_log_warnings() {
// Return instance.
static $plugin;
if ( ! isset( $plugin ) ) {
$plugin = new CMW_Suppress_Log_Warnings();
}
return $plugin;
}
// Bootstrap plugin.
cmw_suppress_log_warnings();
@kcristiano
Copy link
Author

[05-May-2024 14:56:39 UTC] All-in-One Event Calendar: preg_match(): Passing null to parameter #4 ($flags) of type int is deprecated @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/vendor/twig/Lexer.php:235 #8192
[05-May-2024 14:56:39 UTC] All-in-One Event Calendar: preg_match(): Passing null to parameter #4 ($flags) of type int is deprecated @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/vendor/twig/Lexer.php:209 #8192
[05-May-2024 14:56:40 UTC] All-in-One Event Calendar: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/lib/query/helper.php:160 #8192
[05-May-2024 14:56:43 UTC] All-in-One Event Calendar: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/lib/query/helper.php:160 #8192
[05-May-2024 14:56:43 UTC] All-in-One Event Calendar: Return type of Ai1ec_Abstract_Query::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/lib/http/request/abstract.php:198 #8192
[05-May-2024 14:56:43 UTC] All-in-One Event Calendar: Return type of Ai1ec_Abstract_Query::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/lib/http/request/abstract.php:208 #8192
[05-May-2024 14:56:43 UTC] All-in-One Event Calendar: Return type of Ai1ec_Abstract_Query::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/lib/http/request/abstract.php:215 #8192
[05-May-2024 14:56:43 UTC] All-in-One Event Calendar: Return type of Ai1ec_Abstract_Query::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/lib/http/request/abstract.php:222 #8192
[05-May-2024 14:56:44 UTC] All-in-One Event Calendar: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated @ /home/aauwca/public_html/wp-content/plugins/all-in-one-event-calendar/lib/query/helper.php:160 #8192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment