Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 64 additions & 3 deletions App/Admin/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@
*/
class Notices {

/**
* Array of patterns to match WP Rocket related errors in debug.log.
*
* @var array
*/
private $debug_log_patterns = [
'/plugins/wp-rocket/',
'wpr_rucss_used_css',
'wpr_rocket_cache',
'WP_Rocket',
];

/**
* Array of WP Rocket related error patterns to exclude.
*
* @var array
*/
private $debug_log_exclusion_patterns = [
'wp-rocket/inc/Dependencies/Database',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this we can exclude the error-mentioned table already exist like
[01-Apr-2026 12:55:49 UTC] WordPress database error Table 'wp_wpr_lazy_render_content' already exists for query CREATE TABLE wp_wpr_lazy_render_content ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, url varchar(2000) NOT NULL default '', is_mobile tinyint(1) NOT NULL default 0, below_the_fold longtext default '', error_message longtext default '', status varchar(255) NOT NULL default '', modified timestamp NOT NULL default '0000-00-00 00:00:00', last_accessed timestamp NOT NULL default '0000-00-00 00:00:00', created_at timestamp NULL, PRIMARY KEY (id), KEY url (url(150), is_mobile), KEY modified (modified), KEY last_accessed (last_accessed), INDEX status_index (status(191)) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci made by require_once('wp-admin/admin.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Rocket\Dependencies\BerlinDB\Database\Table->maybe_upgrade, WP_Rocket\Dependencies\BerlinDB\Database\Table->install, WP_Rocket\Dependencies\BerlinDB\Database\Table->create
but we still need to capture table doesn't exist like the one here https://group-onecom.slack.com/archives/C08F4M3BBJL/p1759931109493459

'WP_Rocket(.*)Table->create',
'wp-rocket/inc/Engine/Common/Database/Queries/AbstractQuery',
'Failed opening(.*?)wp-rocket/',
];

/**
Expand All @@ -19,6 +35,8 @@ class Notices {
* @return void
*/
public function debug_log_notice() : void {
$display_error_notice = true;

if ( ! defined( 'WP_DEBUG' ) || ! defined( 'WP_DEBUG_LOG' ) || false === WP_DEBUG || false === WP_DEBUG_LOG ) {
return;
}
Expand All @@ -30,9 +48,52 @@ public function debug_log_notice() : void {
}

$content = $file_system->get_contents( WP_CONTENT_DIR . '/debug.log' );
preg_match_all( '#^\[(?<timestamp>.*?)\] (?<error>.+?)(?=\n\[|\z)#ms', $content, $matches, PREG_SET_ORDER);

// Flag errors related to WP Rocket in log.
$wpr_related_errors = [];
$patterns = implode( '|', $this->debug_log_patterns );
if ( ! preg_match( '#' . $patterns . '#', $content ) ) {

foreach( $matches as $match ) {
if ( ! preg_match( '#' . $patterns . '#', $match['error'] ) ) {
continue;
}

// Store errors.
$wpr_related_errors[] = $match['error'];
}

// Bail if no WP Rocket related error.
if ( empty( $wpr_related_errors ) ) {
return;
}

/**
* Filters WP Rocket related errors to be excluded.
*
* @param array $exclusion_patterns Array of WP Rocket related error patterns to exclude.
*/
$exclusion_patterns = apply_filters( 'rocket_e2e_error_exclusions', $this->debug_log_exclusion_patterns );

// Validate filter return.
if ( ! is_array( $exclusion_patterns ) || empty( $exclusion_patterns ) ) {
$exclusion_patterns = $this->debug_log_exclusion_patterns;
}

$exclusion_patterns = implode( '|', $exclusion_patterns );

// Check if errors should be excluded from notice.
foreach( $wpr_related_errors as $errors ) {
if ( preg_match( '#' . $exclusion_patterns . '#', $errors ) ) {
$display_error_notice = false;

continue;
}

$display_error_notice = true;
}

if ( ! $display_error_notice ) {
return;
}

Expand Down