PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 2.2.11
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v2.2.11
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 3.8.0 All 110 releases
wp-optimize / cache / file-based-page-cache.php

file-based-page-cache.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 2.2.11, at cache/file-based-page-cache.php

66 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('No direct access allowed');
4
5 /**
6 * File based page cache drop in
7 */
8 require_once(dirname(__FILE__) . '/file-based-page-cache-functions.php');
9
10 // Don't cache robots.txt or htacesss.
11 if (false !== strpos($_SERVER['REQUEST_URI'], 'robots.txt') || false !== strpos($_SERVER['REQUEST_URI'], '.htaccess')) {
12 return;
13 }
14
15 // Don't cache non-GET requests.
16 if (!isset($_SERVER['REQUEST_METHOD']) || 'GET' !== $_SERVER['REQUEST_METHOD']) return;
17
18 $file_extension = $_SERVER['REQUEST_URI'];
19 $file_extension = preg_replace('#^(.*?)\?.*$#', '$1', $file_extension);
20 $file_extension = trim(preg_replace('#^.*\.(.*)$#', '$1', $file_extension));
21
22 // Don't cache disallowed extensions. Prevents wp-cron.php, xmlrpc.php, etc.
23 if (!preg_match('#index\.php$#i', $_SERVER['REQUEST_URI']) && in_array($file_extension, array( 'php', 'xml', 'xsl' ))) {
24 return;
25 }
26
27 // Don't cache if logged in.
28 if (!empty($_COOKIE)) {
29 $wp_cookies = array( 'wordpressuser_', 'wordpresspass_', 'wordpress_sec_', 'wordpress_logged_in_' );
30
31 foreach ($_COOKIE as $key => $value) {
32 foreach ($wp_cookies as $cookie) {
33 if (strpos($key, $cookie) !== false) {
34 // Logged in!
35 return;
36 }
37 }
38 }
39
40 if (!empty($_COOKIE['wpo_commented_posts'])) {
41 foreach ($_COOKIE['wpo_commented_posts'] as $path) {
42 if (rtrim($path, '/') === rtrim($_SERVER['REQUEST_URI'], '/')) {
43 // User commented on this post.
44 return;
45 }
46 }
47 }
48 }
49
50 // Deal with optional cache exceptions.
51 if (!empty($GLOBALS['wpo_cache_config']['cache_exception_urls'])) {
52 $exceptions = preg_split('#(\n|\r)#', $GLOBALS['wpo_cache_config']['cache_exception_urls']);
53 $regex = !empty($GLOBALS['wpo_cache_config']['enable_url_exemption_regex']);
54
55 foreach ($exceptions as $exception) {
56 if (wpo_url_exception_match($exception, $regex)) {
57 // Exception match.
58 return;
59 }
60 }
61 }
62
63 wpo_serve_cache();
64
65 ob_start('wpo_cache');
66