diff --git a/WPS-Cache/src/Admin/AdminPanelManager.php b/WPS-Cache/src/Admin/AdminPanelManager.php index 67c969a..51a8f0f 100644 --- a/WPS-Cache/src/Admin/AdminPanelManager.php +++ b/WPS-Cache/src/Admin/AdminPanelManager.php @@ -156,8 +156,8 @@ public function handleInstallObjectCache(): void if (file_exists($destination)) { $this->redirectWithNotice("Drop-in already exists.", "error"); } - if (@copy($source, $destination)) { - @chmod($destination, 0644); + if (copy($source, $destination)) { + chmod($destination, 0644); $this->redirectWithNotice( "Object Cache Drop-in installed.", "success", @@ -176,7 +176,7 @@ public function handleRemoveObjectCache(): void $file = WP_CONTENT_DIR . "/object-cache.php"; if (file_exists($file)) { - @unlink($file); + unlink($file); wp_cache_flush(); $this->redirectWithNotice("Drop-in removed.", "success"); } else { diff --git a/WPS-Cache/src/Cache/Drivers/HTMLCache.php b/WPS-Cache/src/Cache/Drivers/HTMLCache.php index e1ec89e..feb6237 100644 --- a/WPS-Cache/src/Cache/Drivers/HTMLCache.php +++ b/WPS-Cache/src/Cache/Drivers/HTMLCache.php @@ -173,7 +173,7 @@ public function processOutput(string $buffer): string libxml_use_internal_errors(true); $dom = new DOMDocument(); // Hack: force UTF-8 - @$dom->loadHTML( + $dom->loadHTML( '' . $content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD, ); @@ -185,6 +185,7 @@ public function processOutput(string $buffer): string $cssShaker = new CriticalCSSManager($this->settings); $cssShaker->processDom($dom); } catch (\Throwable $e) { + $this->logError("CriticalCSS processing failed", $e); } } @@ -197,6 +198,7 @@ public function processOutput(string $buffer): string $jsOpt = new JSOptimizer($this->settings); $jsOpt->processDom($dom); } catch (\Throwable $e) { + $this->logError("JS optimization failed", $e); } } @@ -211,6 +213,7 @@ public function processOutput(string $buffer): string $cdnManager = new CdnManager($this->settings); $content = $cdnManager->process($content); } catch (\Throwable $e) { + $this->logError("CDN rewrite failed", $e); } // 4. Font Optimization @@ -218,6 +221,7 @@ public function processOutput(string $buffer): string $fontOpt = new FontOptimizer($this->settings); $content = $fontOpt->process($content); } catch (\Throwable $e) { + $this->logError("Font optimization failed", $e); } // 5. Media Optimization @@ -225,6 +229,7 @@ public function processOutput(string $buffer): string $mediaOpt = new MediaOptimizer($this->settings); $content = $mediaOpt->process($content); } catch (\Throwable $e) { + $this->logError("Media optimization failed", $e); } // Add Timestamp & Signature diff --git a/WPS-Cache/src/Optimization/DatabaseOptimizer.php b/WPS-Cache/src/Optimization/DatabaseOptimizer.php index 3312ba5..72d4b6f 100644 --- a/WPS-Cache/src/Optimization/DatabaseOptimizer.php +++ b/WPS-Cache/src/Optimization/DatabaseOptimizer.php @@ -80,9 +80,12 @@ public function getStats(): array // Optimization: Combined "Local" and "Site" checks into one query. // This requires reading 'option_value' but does it in 1 round-trip instead of 2. $expired_count = $wpdb->get_var( - "SELECT COUNT(*) FROM $wpdb->options - WHERE (option_name LIKE '\_transient\_timeout\_%' OR option_name LIKE '\_site\_transient\_timeout\_%') - AND option_value < '$time'" + $wpdb->prepare( + "SELECT COUNT(*) FROM $wpdb->options + WHERE (option_name LIKE '\_transient\_timeout\_%' OR option_name LIKE '\_site\_transient\_timeout\_%') + AND option_value < %d", + $time + ) ); // 2. All Transients (Local + Site) @@ -201,24 +204,30 @@ public function processCleanup(array $items): int // Matches _transient_timeout_KEY and joins to _transient_KEY // _transient_timeout_ is 19 chars long. SUBSTRING is 1-based, so start at 20. $wpdb->query( - "DELETE a, b FROM $wpdb->options a - LEFT JOIN $wpdb->options b ON ( - b.option_name = CONCAT('_transient_', SUBSTRING(a.option_name, 20)) - ) - WHERE a.option_name LIKE '\_transient\_timeout\_%' - AND a.option_value < '$time'" + $wpdb->prepare( + "DELETE a, b FROM $wpdb->options a + LEFT JOIN $wpdb->options b ON ( + b.option_name = CONCAT('_transient_', SUBSTRING(a.option_name, 20)) + ) + WHERE a.option_name LIKE '\_transient\_timeout\_%' + AND a.option_value < %d", + $time + ) ); // 2. Site Transients // Matches _site_transient_timeout_KEY and joins to _site_transient_KEY // _site_transient_timeout_ is 24 chars long. Start at 25. $wpdb->query( - "DELETE a, b FROM $wpdb->options a - LEFT JOIN $wpdb->options b ON ( - b.option_name = CONCAT('_site_transient_', SUBSTRING(a.option_name, 25)) - ) - WHERE a.option_name LIKE '\_site\_transient\_timeout\_%' - AND a.option_value < '$time'" + $wpdb->prepare( + "DELETE a, b FROM $wpdb->options a + LEFT JOIN $wpdb->options b ON ( + b.option_name = CONCAT('_site_transient_', SUBSTRING(a.option_name, 25)) + ) + WHERE a.option_name LIKE '\_site\_transient\_timeout\_%' + AND a.option_value < %d", + $time + ) ); $count++; diff --git a/WPS-Cache/src/Plugin.php b/WPS-Cache/src/Plugin.php index 9af3f7a..32928fc 100644 --- a/WPS-Cache/src/Plugin.php +++ b/WPS-Cache/src/Plugin.php @@ -357,7 +357,7 @@ private function createRequiredDirectories(): void // Critical for Nginx/IIS where .htaccess is ignored. $silence = rtrim($path, "/") . "/index.php"; if (!file_exists($silence)) { - @file_put_contents($silence, "