Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 96 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | if ( ! function_exists( 'wp_cache_phase2' ) ) { |
| 4 | require_once __DIR__. '/wp-cache-phase2.php'; |
| 5 | } |
| 6 | |
| 7 | // error_reporting(E_ERROR | E_PARSE); // uncomment to debug this file! |
| 8 | // directory where the configuration file lives. |
| 9 | if ( !defined( 'WPCACHECONFIGPATH' ) ) { |
| 10 | define( 'WPCACHECONFIGPATH', WP_CONTENT_DIR ); |
| 11 | } |
| 12 | |
| 13 | if ( ! @include WPCACHECONFIGPATH . '/wp-cache-config.php' ) { |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | // points at the wp-super-cache plugin directory because sometimes file paths are weird. Edge cases, |
| 18 | if ( ! defined( 'WPCACHEHOME' ) ) { |
| 19 | define( 'WPCACHEHOME', __DIR__ . '/' ); |
| 20 | } |
| 21 | |
| 22 | if ( defined( 'DISABLE_SUPERCACHE' ) ) { |
| 23 | wp_cache_debug( 'DISABLE_SUPERCACHE set, super_cache disabled.' ); |
| 24 | $super_cache_enabled = 0; |
| 25 | } |
| 26 | |
| 27 | require WPCACHEHOME . 'wp-cache-base.php'; |
| 28 | |
| 29 | if ( '/' === $cache_path || empty( $cache_path ) ) { |
| 30 | define( 'WPSCSHUTDOWNMESSAGE', 'WARNING! Caching disabled. Configuration corrupted. Reset configuration on Advanced Settings page.' ); |
| 31 | add_action( 'wp_footer', 'wpsc_shutdown_message' ); |
| 32 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
| 33 | define( 'DONOTCACHEPAGE', 1 ); |
| 34 | } |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | // $blog_cache_dir is used all over the code alongside the supercache directory but at least with multisite installs it appears to do nothing. |
| 39 | // I started putting everything in cache/supercache/blogname/path/ a long time ago but never got around to removing the code that used the blogs directory. |
| 40 | if ( $blogcacheid != '' ) { |
| 41 | $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' ); |
| 42 | } else { |
| 43 | $blog_cache_dir = $cache_path; |
| 44 | } |
| 45 | |
| 46 | $wp_cache_phase1_loaded = true; |
| 47 | |
| 48 | // part of the coarse file locking which should really be removed, but there are edge cases where semaphores didn't work in the past. |
| 49 | $mutex_filename = 'wp_cache_mutex.lock'; |
| 50 | $new_cache = false; |
| 51 | |
| 52 | // write a plugin to extend wp-super-cache! |
| 53 | if ( ! isset( $wp_cache_plugins_dir ) ) { |
| 54 | $wp_cache_plugins_dir = WPCACHEHOME . 'plugins'; |
| 55 | } |
| 56 | |
| 57 | // from the secret shown on the Advanced settings page. |
| 58 | if ( isset( $_GET['donotcachepage'] ) && isset( $cache_page_secret ) && $_GET['donotcachepage'] == $cache_page_secret ) { |
| 59 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
| 60 | define( 'DONOTCACHEPAGE', 1 ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Load wp-super-cache plugins |
| 65 | $plugins = glob( $wp_cache_plugins_dir . '/*.php' ); |
| 66 | if ( is_array( $plugins ) ) { |
| 67 | foreach ( $plugins as $plugin ) { |
| 68 | if ( is_file( $plugin ) ) { |
| 69 | require_once $plugin; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // Load plugins from an array of php scripts. This needs to be documented. |
| 75 | if ( isset( $wpsc_plugins ) && is_array( $wpsc_plugins ) ) { |
| 76 | foreach( $wpsc_plugins as $plugin_file ) { |
| 77 | if ( file_exists( ABSPATH . $plugin_file ) ) { |
| 78 | include_once( ABSPATH . $plugin_file ); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // also look for plugins in wp-content/wp-super-cache-plugins/ |
| 84 | if ( |
| 85 | file_exists( WPCACHEHOME . '../wp-super-cache-plugins/' ) && |
| 86 | is_dir( WPCACHEHOME . '../wp-super-cache-plugins/' ) |
| 87 | ) { |
| 88 | $plugins = glob( WPCACHEHOME . '../wp-super-cache-plugins/*.php' ); |
| 89 | if ( is_array( $plugins ) ) { |
| 90 | foreach ( $plugins as $plugin ) { |
| 91 | if ( is_file( $plugin ) ) { |
| 92 | require_once $plugin; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // for timing purposes for the html comments |
| 99 | $wp_start_time = microtime(); |
| 100 | |
| 101 | if ( isset( $_SERVER['REQUEST_URI'] ) ) { // Cache this in case any plugin modifies it and filter out tracking parameters. |
| 102 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- none available before WordPress is loaded. Sanitized in wp_cache_postload(). |
| 103 | $wp_cache_request_uri = wpsc_remove_tracking_params_from_uri( $_SERVER['REQUEST_URI'] ); // phpcs:ignore |
| 104 | |
| 105 | // $wp_cache_request_uri is expected to be a string. If running from wp-cli it will be null. |
| 106 | if ( $wp_cache_request_uri === null ) { |
| 107 | $wp_cache_request_uri = ''; |
| 108 | } |
| 109 | } else { |
| 110 | $wp_cache_request_uri = ''; |
| 111 | } |
| 112 | |
| 113 | // don't cache in wp-admin |
| 114 | if ( wpsc_is_backend() ) { |
| 115 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
| 116 | define( 'DONOTCACHEPAGE', 1 ); |
| 117 | } |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | // if a cookie is found that we don't like then don't serve/cache the page |
| 122 | if ( wpsc_is_rejected_cookie() ) { |
| 123 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
| 124 | define( 'DONOTCACHEPAGE', 1 ); |
| 125 | } |
| 126 | wp_cache_debug( 'Caching disabled because rejected cookie found.' ); |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | if ( wpsc_is_caching_user_disabled() ) { |
| 131 | wp_cache_debug( 'Caching disabled for logged in users on settings page.' ); |
| 132 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
| 133 | define( 'DONOTCACHEPAGE', 1 ); |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | // make logged in users anonymous so they are shown logged out pages. |
| 139 | if ( isset( $wp_cache_make_known_anon ) && $wp_cache_make_known_anon ) { |
| 140 | wp_supercache_cache_for_admins(); |
| 141 | } |
| 142 | |
| 143 | // an init action wpsc plugins can hook on to. |
| 144 | do_cacheaction( 'cache_init' ); |
| 145 | |
| 146 | if ( ! $cache_enabled ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- set by configuration or cache_init action |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | // don't cache or serve cached files for various URLs, including the Customizer. |
| 151 | if ( isset( $_SERVER['REQUEST_METHOD'] ) && in_array( $_SERVER['REQUEST_METHOD'], array( 'POST', 'PUT', 'DELETE' ), true ) ) { |
| 152 | wp_cache_debug( 'Caching disabled for non GET request.' ); |
| 153 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
| 154 | define( 'DONOTCACHEPAGE', 1 ); |
| 155 | } |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | if ( isset( $_GET['customize_changeset_uuid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 160 | wp_cache_debug( 'Caching disabled for customizer.' ); |
| 161 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
| 162 | define( 'DONOTCACHEPAGE', 1 ); |
| 163 | } |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | $file_expired = false; |
| 168 | $cache_filename = ''; |
| 169 | $meta_file = ''; |
| 170 | $wp_cache_gzip_encoding = ''; |
| 171 | |
| 172 | $gzipped = 0; |
| 173 | $gzsize = 0; |
| 174 | |
| 175 | if ( $cache_compression ) { |
| 176 | $wp_cache_gzip_encoding = gzip_accepted(); // false or 'gzip' |
| 177 | } |
| 178 | |
| 179 | // The wp_cache_check_mobile function appends "-mobile" to the cache filename if it detects a mobile visitor. |
| 180 | add_cacheaction( 'supercache_filename_str', 'wp_cache_check_mobile' ); |
| 181 | if ( function_exists( 'add_filter' ) ) { // loaded since WordPress 4.6 |
| 182 | add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' ); |
| 183 | } |
| 184 | |
| 185 | if ( defined( 'DOING_CRON' ) ) { |
| 186 | // this is required for scheduled CRON jobs. |
| 187 | extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname |
| 188 | return true; |
| 189 | } |
| 190 | |
| 191 | // late init delays serving a cache file until after the WordPress init actin has fired and (most of?) WordPress has loaded. |
| 192 | // If it's not enabled then serve a cache file now if possible. |
| 193 | if ( ! isset( $wp_super_cache_late_init ) || 0 === $wp_super_cache_late_init ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- the wp-cache-config.php include attempt may define this var |
| 194 | wp_cache_serve_cache_file(); |
| 195 | } |