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 | cache/file-based-page-cache.php +3 -130 3.6.0 → 4.7.0 View file →
@@ -8,14 +8,8 @@
8 8 require_once(dirname(__FILE__) . '/file-based-page-cache-functions.php');
9 9
10 10 if (!defined('WPO_CACHE_DIR')) define('WPO_CACHE_DIR', untrailingslashit(WP_CONTENT_DIR) . '/wpo-cache');
11 11
12 -if (wpo_is_activity_stream_requested()) return;
13 -if (wpo_is_robots_txt_requested()) return;
14 -
15 -// Fix for compatibility issue with Jetpack's infinity scroll feature
16 -if (isset($_GET['infinity']) && 'scrolling' === $_GET['infinity']) return;
17 -
18 12 /**
19 13 * Load extensions.
20 14 */
21 15 wpo_cache_load_extensions();
@@ -22,130 +16,9 @@
22 16
23 17 /**
24 18 * Action triggered when the cache extensions are all loaded. Allows to execute code depending on an other extension, without knowing the order in which the files are loaded.
25 19 */
26 -if (function_exists('do_action')) {
27 - do_action('wpo_cache_extensions_loaded');
28 -}
20 +do_action('wpo_cache_extensions_loaded');
29 21
30 -$no_cache_because = array();
31 -
32 -// check if we want to cache current page.
33 -if (function_exists('add_filter') && function_exists('apply_filters')) {
34 - add_filter('wpo_restricted_cache_page_type', 'wpo_restricted_cache_page_type');
35 - add_filter('wpo_url_in_conditional_tags_exceptions', 'wpo_url_in_conditional_tags_exceptions');
36 - $restricted_cache_page_type = apply_filters('wpo_restricted_cache_page_type', false);
37 - $conditional_tag_exceptions = wpo_url_in_conditional_tags_exceptions();
38 -} else {
39 - // On old WP versions, you can't filter the result
40 - $restricted_cache_page_type = wpo_restricted_cache_page_type(false);
41 - $conditional_tag_exceptions = wpo_url_in_conditional_tags_exceptions();
22 +if (true === wpo_can_serve_from_cache()) {
23 + wpo_serve_cache();
42 24 }
43 -
44 -if ($restricted_cache_page_type) {
45 - $no_cache_because[] = $restricted_cache_page_type;
46 -}
47 -
48 -if ($conditional_tag_exceptions) {
49 - $no_cache_because[] = $conditional_tag_exceptions;
50 -}
51 -
52 -// Don't cache non-GET requests.
53 -$is_cache_page_forced = function_exists('apply_filters') ? apply_filters('wpo_cache_page_force', false) : false;
54 -$is_get_request = isset($_SERVER['REQUEST_METHOD']) && 'GET' === $_SERVER['REQUEST_METHOD'];
55 -
56 -if (!$is_cache_page_forced && !$is_get_request) {
57 - $no_cache_because[] = 'The request method was not GET ('.(isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '-').')';
58 -}
59 -
60 -$file_extension = $_SERVER['REQUEST_URI'];
61 -$file_extension = preg_replace('#^(.*?)\?.*$#', '$1', $file_extension);
62 -$file_extension = trim(preg_replace('#^.*\.(.*)$#', '$1', $file_extension));
63 -
64 -// Don't cache disallowed extensions. Prevents wp-cron.php, xmlrpc.php, etc.
65 -if (!preg_match('#index\.php$#i', $_SERVER['REQUEST_URI']) && preg_match('#sitemap([a-zA-Z0-9_-]+)?\.xml$#i', $_SERVER['REQUEST_URI']) && in_array($file_extension, array('php', 'xml', 'xsl'))) {
66 - $no_cache_because[] = 'The request extension is not suitable for caching';
67 -}
68 -
69 -// Don't cache if logged in.
70 -if (!empty($_COOKIE)) {
71 - $wp_cookies = array('wordpressuser_', 'wordpresspass_', 'wordpress_sec_', 'wordpress_logged_in_');
72 -
73 - if (!wpo_cache_loggedin_users()) {
74 - foreach ($_COOKIE as $key => $value) {
75 - foreach ($wp_cookies as $cookie) {
76 - if (false !== strpos($key, $cookie)) {
77 - $no_cache_because[] = 'WordPress login cookies were detected';
78 - break(2);
79 - }
80 - }
81 - }
82 - }
83 -
84 - if (!empty($_COOKIE['wpo_commented_post'])) {
85 - $no_cache_because[] = 'The user has commented on a post (comment cookie set)';
86 - }
87 -
88 - // get cookie exceptions from options.
89 - $cache_exception_cookies = !empty($GLOBALS['wpo_cache_config']['cache_exception_cookies']) ? $GLOBALS['wpo_cache_config']['cache_exception_cookies'] : array();
90 - // filter cookie exceptions, since WP 4.6
91 - $cache_exception_cookies = function_exists('apply_filters') ? apply_filters('wpo_cache_exception_cookies', $cache_exception_cookies) : $cache_exception_cookies;
92 -
93 - // check if any cookie exists from exception list.
94 - if (!empty($cache_exception_cookies)) {
95 - foreach ($_COOKIE as $key => $value) {
96 - foreach ($cache_exception_cookies as $cookie) {
97 - if ('' != trim($cookie) && false !== strpos($key, $cookie)) {
98 - $no_cache_because[] = 'An excepted cookie was set ('.$key.')';
99 - break 2;
100 - }
101 - }
102 - }
103 - }
104 -}
105 -
106 -// check in not disabled current user agent
107 -if (!empty($_SERVER['HTTP_USER_AGENT']) && false === wpo_is_accepted_user_agent($_SERVER['HTTP_USER_AGENT'])) {
108 - $no_cache_because[] = "In the settings, caching is disabled for matches for this request's user agent";
109 -}
110 -
111 -// Deal with optional cache exceptions.
112 -if (wpo_url_in_exceptions(wpo_current_url())) {
113 - $no_cache_because[] = 'In the settings, caching is disabled for matches for the current URL';
114 -}
115 -
116 -if (!empty($_GET)) {
117 - // get variables used for building filename.
118 - $get_variable_names = wpo_cache_query_variables();
119 -
120 - $get_variables = wpo_cache_maybe_ignore_query_variables(array_keys($_GET));
121 -
122 - // if GET variables include one or more undefined variable names then we don't cache.
123 - $get_variables_diff = array_diff($get_variables, $get_variable_names);
124 - if (!empty($get_variables_diff)) {
125 - $no_cache_because[] = "In the settings, caching is disabled for matches for one of the current request's GET parameters";
126 - }
127 -}
128 -
129 -if (!empty($no_cache_because)) {
130 - $no_cache_because_message = implode(', ', $no_cache_because);
131 -
132 - // Add http header
133 - if (!defined('DOING_CRON') || !DOING_CRON) {
134 - wpo_cache_add_nocache_http_header_with_send_headers_action($no_cache_because_message);
135 - }
136 -
137 - if ((!defined('DOING_CRON') || !DOING_CRON)) {
138 - $not_cached_details = "";
139 -
140 - // Output the reason only when the user has turned on debugging
141 - if (((defined('WP_DEBUG') && WP_DEBUG) || isset($_GET['wpo_cache_debug']))) {
142 - $not_cached_details = "because: ".htmlspecialchars($no_cache_because_message);
143 - }
144 - wpo_cache_add_footer_output(sprintf("Page not served from cache %s", $not_cached_details));
145 - }
146 - return;
147 -}
148 -
149 -wpo_serve_cache();
150 -
151 -ob_start('wpo_cache');