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 | includes/class-wpo-page-optimizer.php +23 -4 4.6.1 → 4.7.0 View file →
@@ -12,8 +12,15 @@
12 12 */
13 13 private static $instance = null;
14 14
15 15 /**
16 + * Whether the page should be cached
17 + *
18 + * @var bool|array
19 + */
20 + private $should_cache_page;
21 +
22 + /**
16 23 * Constructor
17 24 */
18 25 private function __construct() {
19 26 // Initialize WP_Optimize_Minify_Config to make available wp_optimize_minify_config()
@@ -31,8 +38,10 @@
31 38 * @return string
32 39 */
33 40 private function optimize($buffer, $flags): string {
34 41 $buffer = apply_filters('wp_optimize_buffer', $buffer, $flags);
42 +
43 + $this->should_cache_page = WP_Optimize()->get_page_cache()->should_cache_page();
35 44
36 45 if (WP_Optimize_Utils::is_valid_html($buffer)) {
37 46 $buffer = $this->maybe_host_google_fonts_locally($buffer);
38 47 $buffer = $this->maybe_remove_unused_css($buffer);
@@ -54,10 +63,19 @@
54 63 * @return string
55 64 */
56 65 private function maybe_cache_page($buffer, $flags) {
57 66
58 - if (!$this->is_wp_cli() && WP_Optimize()->get_page_cache()->should_cache_page()) {
59 - return wpo_cache($buffer, $flags);
67 + if (!$this->is_wp_cli()) {
68 + $wpo_page_cache = WP_Optimize()->get_page_cache();
69 +
70 + // If an array with the reasons why the page isn't cached is returned
71 + if (is_array($this->should_cache_page)) {
72 + do_action('wpo_page_not_cached', $this->should_cache_page);
73 +
74 + $wpo_page_cache->maybe_add_no_cache_because_info($this->should_cache_page);
75 + }
76 +
77 + if (true === $this->should_cache_page) return wpo_cache($buffer, $flags);
60 78 }
61 79
62 80 return $buffer;
63 81 }
@@ -99,10 +117,11 @@
99 117 */
100 118 private function maybe_remove_unused_css($buffer) {
101 119
102 120 if (is_user_logged_in()) return $buffer;
103 -
104 - if (WP_Optimize::is_premium() && wp_optimize_minify_config()->get('enable_unused_css')) {
121 +
122 + // Remove unused CSS available in Premium and only when the page cache is enabled
123 + if (WP_Optimize::is_premium() && wp_optimize_minify_config()->get('enable_unused_css') && true === $this->should_cache_page) {
105 124 $unused_css_class = WP_Optimize_Minify_Unused_Css::get_instance();
106 125 return $unused_css_class->remove_unused_css($buffer);
107 126 }
108 127 return $buffer;