PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | compatibility/class-wp-optimize-server-compatibility.php +29 -8 4.5.4 → 4.7.0 View file →
@@ -7,8 +7,17 @@
7 7 */
8 8 class WP_Optimize_Server_Compatibility {
9 9
10 10 /**
11 + * Cached result of the Kinsta server detection.
12 + *
13 + * Null until first evaluation, then bool for subsequent calls.
14 + *
15 + * @var bool|null
16 + */
17 + private $is_kinsta_server = null;
18 +
19 + /**
11 20 * Returns singleton instance
12 21 *
13 22 * @return WP_Optimize_Server_Compatibility
14 23 */
@@ -31,12 +40,11 @@
31 40
32 41 /**
33 42 * Detects whether the server supports table optimization.
34 43 *
35 - * Some servers prevent table optimization
36 - * because InnoDB engine does not optimize table
37 - * instead it drops tables and recreates them,
38 - * which results in elevated disk write operations
44 + * Some servers prevent table optimization because the InnoDB engine
45 + * does not optimize tables — instead it drops and recreates them,
46 + * resulting in elevated disk write operations.
39 47 *
40 48 * @return bool
41 49 */
42 50 public function does_server_allow_table_optimization(): bool {
@@ -52,13 +60,20 @@
52 60 return !$this->is_kinsta();
53 61 }
54 62
55 63 /**
56 - * Detects if the platform is Kinsta or not
64 + * Detects if the platform is Kinsta or not.
57 65 *
66 + * Results are cached after the first call to ensure consistency
67 + * and avoid redundant filter applications within a single request.
68 + *
58 69 * @return bool Returns true if it is a Kinsta platform, otherwise returns false
59 70 */
60 71 private function is_kinsta(): bool {
72 + if (null !== $this->is_kinsta_server) {
73 + return $this->is_kinsta_server;
74 + }
75 +
61 76 $is_kinsta = isset($_SERVER['KINSTA_CACHE_ZONE']);
62 77
63 78 /**
64 79 * Filter whether the server is detected as Kinsta.
@@ -67,14 +82,20 @@
67 82 * Kinsta changes environment variables or for edge cases.
68 83 *
69 84 * @param bool $is_kinsta Detected Kinsta status.
70 85 */
71 - return (bool) apply_filters('wpo_is_kinsta_server', $is_kinsta);
86 + $this->is_kinsta_server = (bool) apply_filters('wpo_is_kinsta_server', $is_kinsta);
87 +
88 + return $this->is_kinsta_server;
72 89 }
73 90
74 91 /**
75 - * Disable table optimization if the server does not allow it.
92 + * Disables automatic table optimization when the server does not allow it.
76 93 *
94 + * Checks the current server capabilities and, if table optimization is
95 + * unsupported, updates the "auto" option to disable it. This prevents
96 + * scheduled or automatic optimizations from running on incompatible hosts.
97 + *
77 98 * @return void
78 99 */
79 100 public function maybe_disable_unsupported_table_optimization(): void {
80 101
@@ -88,9 +109,9 @@
88 109 if (empty($auto_options) || !is_array($auto_options)) {
89 110 return;
90 111 }
91 112
92 - if (!empty($auto_options['optimize']) && 'true' === $auto_options['optimize']) {
113 + if (isset($auto_options['optimize']) && 'true' === $auto_options['optimize']) {
93 114 $auto_options['optimize'] = 'false';
94 115 $options->update_option('auto', $auto_options);
95 116 }
96 117 }