From e4565bf36f9d81ecc34671285e1100429a1142e2 Mon Sep 17 00:00:00 2001 From: robjarsen <29106074+robjarsen@users.noreply.github.com> Date: Wed, 13 Dec 2017 15:39:36 -0500 Subject: [PATCH 1/2] PHPCS fixes for wp-cache-phase2.php --- wp-cache-phase2.php | 1424 +++++++++++++++++++++++-------------------- 1 file changed, 772 insertions(+), 652 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 32b6a625..8cbb88e2 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -1,22 +1,26 @@ $header) { + foreach ( $meta['headers'] as $t => $header ) { // godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/ - if( strpos( $header, 'Last-Modified:' ) === false ) - header($header); + if ( strpos( $header, 'Last-Modified:' ) === false ) { + header( $header ); + } } if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { header( 'X-WP-Super-Cache: Served WPCache cache file' ); @@ -226,30 +235,30 @@ function wp_cache_serve_cache_file() { // attempt to uncompress the cached file just in case it's gzipped $uncompressed = gzuncompress( $cache ); if ( $uncompressed ) { - wp_cache_debug( "Uncompressed gzipped cache file from object cache", 1 ); + wp_cache_debug( 'Uncompressed gzipped cache file from object cache', 1 ); $cache = $uncompressed; unset( $uncompressed ); } } - if ( isset( $meta[ 'dynamic' ] ) && $meta[ 'dynamic' ] ) { - wp_cache_debug( "Serving wp-cache dynamic file from object cache", 5 ); + if ( isset( $meta['dynamic'] ) && $meta['dynamic'] ) { + wp_cache_debug( 'Serving wp-cache dynamic file from object cache', 5 ); echo do_cacheaction( 'wpsc_cachedata', $cache ); } else { - wp_cache_debug( "Serving wp-cache static file from object cache", 5 ); + wp_cache_debug( 'Serving wp-cache static file from object cache', 5 ); echo $cache; } - wp_cache_debug( "exit request", 5 ); + wp_cache_debug( 'exit request', 5 ); die(); } } else { - if ( isset( $meta[ 'dynamic' ] ) ) { - wp_cache_debug( "Serving wp-cache dynamic file", 5 ); + if ( isset( $meta['dynamic'] ) ) { + wp_cache_debug( 'Serving wp-cache dynamic file', 5 ); if ( $ungzip ) { // attempt to uncompress the cached file just in case it's gzipped - $cache = wp_cache_get_legacy_cache( $cache_file ); + $cache = wp_cache_get_legacy_cache( $cache_file ); $uncompressed = @gzuncompress( $cache ); if ( $uncompressed ) { - wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 ); + wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); unset( $cache ); echo do_cacheaction( 'wpsc_cachedata', $uncompressed ); } else { @@ -259,12 +268,12 @@ function wp_cache_serve_cache_file() { echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) ); } } else { - wp_cache_debug( "Serving wp-cache static file", 5 ); + wp_cache_debug( 'Serving wp-cache static file', 5 ); if ( $ungzip ) { - $cache = wp_cache_get_legacy_cache( $cache_file ); + $cache = wp_cache_get_legacy_cache( $cache_file ); $uncompressed = gzuncompress( $cache ); if ( $uncompressed ) { - wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 ); + wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); echo $uncompressed; } else { echo $cache; @@ -273,7 +282,7 @@ function wp_cache_serve_cache_file() { echo( wp_cache_get_legacy_cache( $cache_file ) ); } } - wp_cache_debug( "exit request", 5 ); + wp_cache_debug( 'exit request', 5 ); die(); } } @@ -285,11 +294,12 @@ function wp_cache_get_legacy_cache( $cache_file ) { function wp_cache_postload() { global $cache_enabled, $wp_super_cache_late_init; - if ( !$cache_enabled ) + if ( ! $cache_enabled ) { return true; + } if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) { - wp_cache_debug( "Supercache Late Init: add wp_cache_serve_cache_file to init", 3 ); + wp_cache_debug( 'Supercache Late Init: add wp_cache_serve_cache_file to init', 3 ); add_action( 'init', 'wp_cache_late_loader', 9999 ); } else { wp_super_cache_init(); @@ -298,7 +308,7 @@ function wp_cache_postload() { } function wp_cache_late_loader() { - wp_cache_debug( "Supercache Late Loader running on init", 3 ); + wp_cache_debug( 'Supercache Late Loader running on init', 3 ); wp_cache_serve_cache_file(); wp_cache_phase2(); } @@ -311,29 +321,32 @@ function wp_cache_get_cookies_values() { return $string; } - if ( defined( 'COOKIEHASH' ) ) + if ( defined( 'COOKIEHASH' ) ) { $cookiehash = preg_quote( constant( 'COOKIEHASH' ) ); - else + } else { $cookiehash = ''; + } $regex = "/^wp-postpass_$cookiehash|^comment_author_$cookiehash"; - if ( defined( 'LOGGED_IN_COOKIE' ) ) - $regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) ); - else + if ( defined( 'LOGGED_IN_COOKIE' ) ) { + $regex .= '|^' . preg_quote( constant( 'LOGGED_IN_COOKIE' ) ); + } else { $regex .= "|^wordpress_logged_in_$cookiehash"; - $regex .= "/"; - while ($key = key($_COOKIE)) { + } + $regex .= '/'; + while ( $key = key( $_COOKIE ) ) { if ( preg_match( $regex, $key ) ) { wp_cache_debug( "wp_cache_get_cookies_values: $regex Cookie detected: $key", 5 ); - $string .= $_COOKIE[ $key ] . ","; + $string .= $_COOKIE[ $key ] . ','; } - next($_COOKIE); + next( $_COOKIE ); } - reset($_COOKIE); + reset( $_COOKIE ); // If you use this hook, make sure you update your .htaccess rules with the same conditions $string = do_cacheaction( 'wp_cache_get_cookies_values', $string ); - if ( $string != '' ) + if ( $string != '' ) { $string = md5( $string ); + } wp_cache_debug( "wp_cache_get_cookies_values: return: $string", 5 ); return $string; @@ -347,12 +360,13 @@ function add_cacheaction( $action, $func ) { function do_cacheaction( $action, $value = '' ) { global $wp_supercache_actions; - if ( !isset( $wp_supercache_actions ) || !is_array( $wp_supercache_actions ) ) + if ( ! isset( $wp_supercache_actions ) || ! is_array( $wp_supercache_actions ) ) { return $value; + } - if( array_key_exists($action, $wp_supercache_actions) && is_array( $wp_supercache_actions[ $action ] ) ) { + if ( array_key_exists( $action, $wp_supercache_actions ) && is_array( $wp_supercache_actions[ $action ] ) ) { $actions = $wp_supercache_actions[ $action ]; - foreach( $actions as $func ) { + foreach ( $actions as $func ) { $value = call_user_func_array( $func, array( $value ) ); } } @@ -362,74 +376,77 @@ function do_cacheaction( $action, $value = '' ) { function wp_cache_mobile_group( $user_agent ) { global $wp_cache_mobile_groups; - foreach( (array)$wp_cache_mobile_groups as $name => $group ) { - foreach( (array)$group as $browser ) { + foreach ( (array) $wp_cache_mobile_groups as $name => $group ) { + foreach ( (array) $group as $browser ) { $browser = trim( strtolower( $browser ) ); if ( $browser != '' && strstr( $user_agent, $browser ) ) { return $browser; } } } - return "mobile"; + return 'mobile'; } // From https://wordpress.org/plugins/wordpress-mobile-edition/ by Alex King function wp_cache_check_mobile( $cache_key ) { global $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes; - if ( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled ) + if ( ! isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled ) { return $cache_key; + } wp_cache_debug( "wp_cache_check_mobile: $cache_key" ); // allow plugins to short circuit mobile check. Cookie, extra UA checks? - switch( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) { - case "normal": - wp_cache_debug( "wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action" ); - return $cache_key; + switch ( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) { + case 'normal': + wp_cache_debug( 'wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action' ); + return $cache_key; break; - case "mobile": - wp_cache_debug( "wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action" ); - return $cache_key . "-mobile"; + case 'mobile': + wp_cache_debug( 'wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action' ); + return $cache_key . '-mobile'; break; } - if ( !isset( $_SERVER[ "HTTP_USER_AGENT" ] ) ) { + if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) { return $cache_key; } if ( do_cacheaction( 'disable_mobile_check', false ) ) { - wp_cache_debug( "wp_cache_check_mobile: disable_mobile_check disabled mobile check" ); + wp_cache_debug( 'wp_cache_check_mobile: disable_mobile_check disabled mobile check' ); return $cache_key; } - $browsers = explode( ',', $wp_cache_mobile_browsers ); + $browsers = explode( ',', $wp_cache_mobile_browsers ); $user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); - foreach ($browsers as $browser) { + foreach ( $browsers as $browser ) { if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) { - wp_cache_debug( "mobile browser detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 ); + wp_cache_debug( 'mobile browser detected: ' . $_SERVER['HTTP_USER_AGENT'], 5 ); return $cache_key . '-' . wp_cache_mobile_group( $user_agent ); } } - if (isset($_SERVER['HTTP_X_WAP_PROFILE']) ) + if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) { return $cache_key . '-' . $_SERVER['HTTP_X_WAP_PROFILE']; - if (isset($_SERVER['HTTP_PROFILE']) ) + } + if ( isset( $_SERVER['HTTP_PROFILE'] ) ) { return $cache_key . '-' . $_SERVER['HTTP_PROFILE']; + } if ( isset( $wp_cache_mobile_prefixes ) ) { $browsers = explode( ',', $wp_cache_mobile_prefixes ); - foreach ($browsers as $browser_prefix) { - if ( substr($user_agent, 0, 4) == $browser_prefix ) { - wp_cache_debug( "mobile browser (prefix) detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 ); + foreach ( $browsers as $browser_prefix ) { + if ( substr( $user_agent, 0, 4 ) == $browser_prefix ) { + wp_cache_debug( 'mobile browser (prefix) detected: ' . $_SERVER['HTTP_USER_AGENT'], 5 ); return $cache_key . '-' . $browser_prefix; } } } - $accept = isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ? strtolower( $_SERVER[ 'HTTP_ACCEPT' ] ) : ''; - if (strpos($accept, 'wap') !== false) { + $accept = isset( $_SERVER['HTTP_ACCEPT'] ) ? strtolower( $_SERVER['HTTP_ACCEPT'] ) : ''; + if ( strpos( $accept, 'wap' ) !== false ) { return $cache_key . '-' . 'wap'; } - if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) { + if ( isset( $_SERVER['ALL_HTTP'] ) && strpos( strtolower( $_SERVER['ALL_HTTP'] ), 'operamini' ) !== false ) { return $cache_key . '-' . 'operamini'; } @@ -446,26 +463,29 @@ function wp_cache_debug( $message, $level = 1 ) { global $wp_cache_debug_log, $cache_path, $wp_cache_debug_ip, $wp_super_cache_debug; // If either of the debug or log globals aren't set, then we can stop - if ( !isset($wp_super_cache_debug) - || !isset($wp_cache_debug_log) ) + if ( ! isset( $wp_super_cache_debug ) + || ! isset( $wp_cache_debug_log ) ) { return false; + } // If either the debug or log globals are false or empty, we can stop if ( $wp_super_cache_debug == false - || $wp_cache_debug_log == '' ) + || $wp_cache_debug_log == '' ) { return false; + } // If the debug_ip has been set, but it doesn't match the ip of the requester // then we can stop. - if ( isset($wp_cache_debug_ip) + if ( isset( $wp_cache_debug_ip ) && $wp_cache_debug_ip != '' - && $wp_cache_debug_ip != $_SERVER[ 'REMOTE_ADDR' ] ) + && $wp_cache_debug_ip != $_SERVER['REMOTE_ADDR'] ) { return false; + } // Log message: Date URI Message - $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL; + $log_message = date( 'H:i:s' ) . ' ' . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL; // path to the log file in the cache folder - $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); + $log_file = $cache_path . str_replace( '/', '', str_replace( '..', '', $wp_cache_debug_log ) ); if ( ! file_exists( $log_file ) && function_exists( 'wpsc_create_debug_log' ) ) { global $wp_cache_debug_username; @@ -482,7 +502,7 @@ function wp_cache_debug( $message, $level = 1 ) { function wpsc_dump_get_request() { static $string; - if ( isset( $string) ) { + if ( isset( $string ) ) { return $string; } @@ -540,7 +560,7 @@ function get_current_url_supercache_dir( $post_id = 0 ) { $DONOTREMEMBER = 0; if ( $post_id != 0 ) { - $site_url = site_url(); + $site_url = site_url(); $permalink = get_permalink( $post_id ); if ( false === strpos( $permalink, $site_url ) ) { /* @@ -563,32 +583,34 @@ function get_current_url_supercache_dir( $post_id = 0 ) { } } else { $uri = str_replace( $site_url, '', $permalink ); - if ( strpos( $uri, $wp_cache_home_path ) !== 0 ) + if ( strpos( $uri, $wp_cache_home_path ) !== 0 ) { $uri = rtrim( $wp_cache_home_path, '/' ) . $uri; + } } } else { $uri = strtolower( $wp_cache_request_uri ); } - $uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?(#.*)?$/", '', $uri ) ) ); + $uri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( '/(\?.*)?(#.*)?$/', '', $uri ) ) ); $hostname = $WPSC_HTTP_HOST; // Get hostname from wp options for wp-cron, wp-cli and similar requests. if ( empty( $hostname ) && function_exists( 'get_option' ) ) { $hostname = (string) parse_url( get_option( 'home' ), PHP_URL_HOST ); } $dir = preg_replace( '/:.*$/', '', $hostname ) . $uri; // To avoid XSS attacks - if ( function_exists( "apply_filters" ) ) { + if ( function_exists( 'apply_filters' ) ) { $dir = apply_filters( 'supercache_dir', $dir ); } else { $dir = do_cacheaction( 'supercache_dir', $dir ); } $dir = $cache_path . 'supercache/' . $dir . '/'; - if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) { + if ( is_array( $cached_direct_pages ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages ) ) { $dir = ABSPATH . $uri . '/'; } $dir = str_replace( '..', '', str_replace( '//', '/', $dir ) ); wp_cache_debug( "supercache dir: $dir", 5 ); - if ( $DONOTREMEMBER == 0 ) + if ( $DONOTREMEMBER == 0 ) { $saved_supercache_dir[ $post_id ] = $dir; + } return $dir; } @@ -611,7 +633,7 @@ function wpsc_get_realpath( $directory ) { } $original_dir = $directory; - $directory = realpath( $directory ); + $directory = realpath( $directory ); if ( ! $directory ) { wp_cache_debug( "wpsc_get_realpath: directory does not exist - $original_dir" ); @@ -631,12 +653,12 @@ function wpsc_is_in_cache_directory( $directory ) { static $rp_cache_path = ''; if ( $directory == '' ) { - wp_cache_debug( "wpsc_is_in_cache_directory: exiting as directory is blank" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: exiting as directory is blank' ); return false; } if ( $cache_path == '' ) { - wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path is blank" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: exiting as cache_path is blank' ); return false; } @@ -645,14 +667,14 @@ function wpsc_is_in_cache_directory( $directory ) { } if ( ! $rp_cache_path ) { - wp_cache_debug( "wpsc_is_in_cache_directory: exiting as cache_path directory does not exist" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: exiting as cache_path directory does not exist' ); return false; } $directory = wpsc_get_realpath( $directory ); if ( ! $directory ) { - wp_cache_debug( "wpsc_is_in_cache_directory: directory does not exist" ); + wp_cache_debug( 'wpsc_is_in_cache_directory: directory does not exist' ); return false; } @@ -668,21 +690,21 @@ function wpsc_delete_files( $dir, $delete = true ) { static $protected = ''; if ( $dir == '' ) { - wp_cache_debug( "wpsc_delete_files: directory is blank" ); + wp_cache_debug( 'wpsc_delete_files: directory is blank' ); return false; } // only do this once, this function will be called many times if ( $protected == '' ) { - $protected = array( $cache_path, $cache_path . "blogs/", $cache_path . 'supercache' ); - foreach( $protected as $id => $directory ) { + $protected = array( $cache_path, $cache_path . 'blogs/', $cache_path . 'supercache' ); + foreach ( $protected as $id => $directory ) { $protected[ $id ] = trailingslashit( wpsc_get_realpath( $directory ) ); } } $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "wpsc_delete_files: directory does not exist: " . $dir ); + wp_cache_debug( 'wpsc_delete_files: directory does not exist: ' . $dir ); return false; } @@ -692,21 +714,25 @@ function wpsc_delete_files( $dir, $delete = true ) { return false; } - if ( in_array( $dir, $protected ) ) + if ( in_array( $dir, $protected ) ) { return false; + } if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) { while ( ( $file = readdir( $dh ) ) !== false ) { - if ( $file != '.' && $file != '..' && $file != '.htaccess' && is_file( $dir . $file ) ) - if ( $delete ) + if ( $file != '.' && $file != '..' && $file != '.htaccess' && is_file( $dir . $file ) ) { + if ( $delete ) { @unlink( $dir . $file ); - else + } else { @wp_cache_rebuild_or_delete( $dir . $file ); + } + } } closedir( $dh ); - if ( $delete ) + if ( $delete ) { @rmdir( $dir ); + } } return true; } @@ -716,7 +742,7 @@ function get_all_supercache_filenames( $dir = '' ) { $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "get_all_supercache_filenames: directory does not exist" ); + wp_cache_debug( 'get_all_supercache_filenames: directory does not exist' ); return array(); } @@ -730,20 +756,21 @@ function get_all_supercache_filenames( $dir = '' ) { // open directory and look for index-*.html files if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) { while ( ( $file = readdir( $dh ) ) !== false ) { - if ( substr( $file, 0, 6 ) == 'index-' && strpos( $file, '.html' ) ) + if ( substr( $file, 0, 6 ) == 'index-' && strpos( $file, '.html' ) ) { $filenames[] = $file; + } } closedir( $dh ); } } - if ( function_exists( "apply_filters" ) ) { + if ( function_exists( 'apply_filters' ) ) { $filenames = apply_filters( 'all_supercache_filenames', $filenames ); } else { $filenames = do_cacheaction( 'all_supercache_filenames', $filenames ); } - foreach( $filenames as $file ) { + foreach ( $filenames as $file ) { $out[] = $file; $out[] = $file . '.gz'; } @@ -754,17 +781,17 @@ function get_all_supercache_filenames( $dir = '' ) { function supercache_filename() { global $cached_direct_pages; - //Add support for https and http caching - $is_https = ( ( isset( $_SERVER[ 'HTTPS' ] ) && 'on' == strtolower( $_SERVER[ 'HTTPS' ] ) ) || ( isset( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) && 'https' == strtolower( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) ) ); //Also supports https requests coming from an nginx reverse proxy + // Add support for https and http caching + $is_https = ( ( isset( $_SERVER['HTTPS'] ) && 'on' == strtolower( $_SERVER['HTTPS'] ) ) || ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' == strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ); // Also supports https requests coming from an nginx reverse proxy $extra_str = $is_https ? '-https' : ''; - if ( function_exists( "apply_filters" ) ) { + if ( function_exists( 'apply_filters' ) ) { $extra_str = apply_filters( 'supercache_filename_str', $extra_str ); } else { $extra_str = do_cacheaction( 'supercache_filename_str', $extra_str ); } - if ( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) { + if ( is_array( $cached_direct_pages ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages ) ) { $extra_str = ''; } $filename = 'index' . $extra_str . '.html'; @@ -773,18 +800,30 @@ function supercache_filename() { } function get_oc_version() { - $wp_cache_oc_key = wp_cache_get( "wp_cache_oc_key" ); + $wp_cache_oc_key = wp_cache_get( 'wp_cache_oc_key' ); if ( ! $wp_cache_oc_key ) { - $wp_cache_oc_key[ 'key' ] = reset_oc_version(); - } elseif ( $wp_cache_oc_key[ 'ts' ] < time() - 600 ) - wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $wp_cache_oc_key[ 'key' ] ) ); - return $wp_cache_oc_key[ 'key' ]; + $wp_cache_oc_key['key'] = reset_oc_version(); + } elseif ( $wp_cache_oc_key['ts'] < time() - 600 ) { + wp_cache_set( + 'wp_cache_oc_key', array( + 'ts' => time(), + 'key' => $wp_cache_oc_key['key'], + ) + ); + } + return $wp_cache_oc_key['key']; } function reset_oc_version( $version = 1 ) { - if ( $version == 1 ) + if ( $version == 1 ) { $version = mt_rand(); - wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $version ) ); + } + wp_cache_set( + 'wp_cache_oc_key', array( + 'ts' => time(), + 'key' => $version, + ) + ); return $version; } @@ -793,7 +832,7 @@ function get_oc_key( $url = false ) { global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST; if ( $url ) { - $key = intval( $_SERVER[ 'SERVER_PORT' ] ) . strtolower( preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) ) . $url; + $key = intval( $_SERVER['SERVER_PORT'] ) . strtolower( preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) ) . $url; } else { $key = get_current_url_supercache_dir(); } @@ -801,23 +840,27 @@ function get_oc_key( $url = false ) { } function wp_supercache_cache_for_admins() { - if ( isset( $_GET[ 'preview' ] ) || function_exists( "is_admin" ) && is_admin() || defined( 'DOING_AJAX' ) ) + if ( isset( $_GET['preview'] ) || function_exists( 'is_admin' ) && is_admin() || defined( 'DOING_AJAX' ) ) { return true; + } - if ( false == do_cacheaction( 'wp_supercache_remove_cookies', true ) ) + if ( false == do_cacheaction( 'wp_supercache_remove_cookies', true ) ) { return true; + } - if ( $_SERVER[ "REQUEST_METHOD" ] != 'GET' || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-json/' ) !== false ) + if ( $_SERVER['REQUEST_METHOD'] != 'GET' || strpos( $_SERVER['REQUEST_URI'], '/wp-json/' ) !== false ) { return true; + } $cookie_keys = array( 'wordpress_logged_in', 'comment_author_' ); - if ( defined( 'LOGGED_IN_COOKIE' ) ) + if ( defined( 'LOGGED_IN_COOKIE' ) ) { $cookie_keys[] = constant( 'LOGGED_IN_COOKIE' ); + } reset( $_COOKIE ); - foreach( $_COOKIE as $cookie => $val ) { + foreach ( $_COOKIE as $cookie => $val ) { reset( $cookie_keys ); - foreach( $cookie_keys as $key ) { - if ( strpos( $cookie, $key ) !== FALSE ) { + foreach ( $cookie_keys as $key ) { + if ( strpos( $cookie, $key ) !== false ) { wp_cache_debug( 'Removing auth from $_COOKIE to allow caching for logged in user (' . $cookie . ')', 5 ); unset( $_COOKIE[ $cookie ] ); } @@ -832,7 +875,7 @@ function wp_cache_confirm_delete( $dir ) { $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { - wp_cache_debug( "wp_cache_confirm_delete: directory does not exist" ); + wp_cache_debug( 'wp_cache_confirm_delete: directory does not exist' ); return false; } @@ -851,8 +894,8 @@ function wp_cache_confirm_delete( $dir ) { $dir == '' || $dir == $rp_cache_path || $dir == wpsc_get_realpath( $blog_cache_dir ) || - $dir == wpsc_get_realpath( $blog_cache_dir . "meta/" ) || - $dir == wpsc_get_realpath( $cache_path . "supercache" ) + $dir == wpsc_get_realpath( $blog_cache_dir . 'meta/' ) || + $dir == wpsc_get_realpath( $cache_path . 'supercache' ) ) { return false; } else { @@ -874,16 +917,18 @@ function wpsc_deep_replace( $search, $subject ) { function wpsc_get_protected_directories() { global $cache_path, $blog_cache_dir; - return apply_filters( 'wpsc_protected_directories', array( - $cache_path . '.htaccess', - $cache_path . "index.html", - $blog_cache_dir, - $blog_cache_dir . "index.html", - $blog_cache_dir . 'meta', - $blog_cache_dir . 'meta/index.html', - $cache_path . 'supercache/index.html', - $cache_path . 'supercache' ) - ); + return apply_filters( + 'wpsc_protected_directories', array( + $cache_path . '.htaccess', + $cache_path . 'index.html', + $blog_cache_dir, + $blog_cache_dir . 'index.html', + $blog_cache_dir . 'meta', + $blog_cache_dir . 'meta/index.html', + $cache_path . 'supercache/index.html', + $cache_path . 'supercache', + ) + ); } function wpsc_create_debug_log( $filename = '', $username = '' ) { @@ -891,7 +936,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { if ( $filename != '' ) { $wp_cache_debug_log = $filename; } else { - $wp_cache_debug_log = md5( time() + mt_rand() ) . ".php"; + $wp_cache_debug_log = md5( time() + mt_rand() ) . '.php'; } if ( $username != '' ) { $wp_cache_debug_username = $username; @@ -900,17 +945,17 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { } $msg = ' -if ( !isset( $_SERVER[ "PHP_AUTH_USER" ] ) || ( $_SERVER[ "PHP_AUTH_USER" ] != "' . $wp_cache_debug_username . '" && $_SERVER[ "PHP_AUTH_PW" ] != "' . $wp_cache_debug_username . '" ) ) { +if ( !isset( $_SERVER["PHP_AUTH_USER"] ) || ( $_SERVER["PHP_AUTH_USER"] != "' . $wp_cache_debug_username . '" && $_SERVER["PHP_AUTH_PW"] != "' . $wp_cache_debug_username . '" ) ) { header( "WWW-Authenticate: Basic realm=\"WP-Super-Cache Debug Log\"" ); - header( $_SERVER[ "SERVER_PROTOCOL" ] . " 401 Unauthorized" ); + header( $_SERVER["SERVER_PROTOCOL"] . " 401 Unauthorized" ); echo "You must login to view the debug log"; exit; }' . PHP_EOL; - $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' ); + $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' ); if ( $fp ) { fwrite( $fp, '<' . "?php\n" ); fwrite( $fp, $msg ); - fwrite( $fp, '?' . ">
" . PHP_EOL );
+ fwrite( $fp, '?' . '>' . PHP_EOL );
fwrite( $fp, '<' . '?php // END HEADER ?' . '>' . PHP_EOL );
fclose( $fp );
wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
@@ -918,7 +963,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
}
$fp = fopen( $cache_path . 'view_' . $wp_cache_debug_log, 'w' );
if ( $fp ) {
- fwrite( $fp, '<' . "?php" . PHP_EOL );
+ fwrite( $fp, '<' . '?php' . PHP_EOL );
$msg .= '$debug_log = file( "./' . $wp_cache_debug_log . '" );
$start_log = 1 + array_search( "<" . "?php // END HEADER ?" . ">" . PHP_EOL, $debug_log );
if ( $start_log > 1 ) {
@@ -928,15 +973,15 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
$checks = array( "wp-admin", "exclude_filter", "wp-content", "wp-json" );
foreach( $checks as $check ) {
- if ( isset( $_GET[ $check ] ) ) {
+ if ( isset( $_GET[$check] ) ) {
$$check = 1;
} else {
$$check = 0;
}
}
-if ( isset( $_GET[ "filter" ] ) ) {
- $filter = htmlspecialchars( $_GET[ "filter" ] );
+if ( isset( $_GET["filter"] ) ) {
+ $filter = htmlspecialchars( $_GET["filter"] );
} else {
$filter = "";
}
@@ -976,7 +1021,10 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
fclose( $fp );
}
- return array( 'wp_cache_debug_log' => $wp_cache_debug_log, 'wp_cache_debug_username' => $wp_cache_debug_username );
+ return array(
+ 'wp_cache_debug_log' => $wp_cache_debug_log,
+ 'wp_cache_debug_username' => $wp_cache_debug_username,
+ );
}
function wpsc_delete_url_cache( $url ) {
@@ -999,7 +1047,6 @@ function wpsc_delete_url_cache( $url ) {
function is_writeable_ACLSafe( $path ) {
// PHP's is_writable does not work with Win32 NTFS
-
if ( $path[ strlen( $path ) - 1 ] == '/' ) { // recursively return a temporary file path
return is_writeable_ACLSafe( $path . uniqid( mt_rand() ) . '.tmp' );
} elseif ( is_dir( $path ) ) {
@@ -1008,9 +1055,10 @@ function is_writeable_ACLSafe( $path ) {
// check tmp file for read/write capabilities
$rm = file_exists( $path );
- $f = @fopen( $path, 'a' );
- if ( $f === false )
+ $f = @fopen( $path, 'a' );
+ if ( $f === false ) {
return false;
+ }
fclose( $f );
if ( ! $rm ) {
unlink( $path );
@@ -1038,16 +1086,16 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
if ( @is_file( $my_file ) == false ) {
return false;
}
- if (!is_writeable_ACLSafe($my_file)) {
+ if ( ! is_writeable_ACLSafe( $my_file ) ) {
trigger_error( "Error: file $my_file is not writable." );
return false;
}
- $found = false;
+ $found = false;
$loaded = false;
- $c = 0;
- $lines = array();
- while( ! $loaded ) {
+ $c = 0;
+ $lines = array();
+ while ( ! $loaded ) {
$lines = file( $my_file );
if ( ! empty( $lines ) && is_array( $lines ) ) {
$loaded = true;
@@ -1059,21 +1107,21 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
}
}
}
- foreach( (array) $lines as $line ) {
- if ( preg_match("/$old/", $line)) {
+ foreach ( (array) $lines as $line ) {
+ if ( preg_match( "/$old/", $line ) ) {
$found = true;
break;
}
}
$tmp_file = dirname( $my_file ) . '/' . mt_rand() . '.php';
- $fd = fopen( $tmp_file, 'w' );
+ $fd = fopen( $tmp_file, 'w' );
if ( ! $fd ) {
trigger_error( "wp_cache_replace_line: Error - could not write to $tmp_file" );
return false;
}
if ( $found ) {
- foreach( (array) $lines as $line ) {
+ foreach ( (array) $lines as $line ) {
if ( ! preg_match( "/$old/", $line ) ) {
fputs( $fd, $line );
} elseif ( $new != '' ) {
@@ -1082,12 +1130,12 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
}
} else {
$done = false;
- foreach( (array) $lines as $line ) {
+ foreach ( (array) $lines as $line ) {
if ( $done || ! preg_match( '/^(if\ \(\ \!\ )?define|\$|\?>/', $line ) ) {
- fputs($fd, $line);
+ fputs( $fd, $line );
} else {
- fputs($fd, "$new\n");
- fputs($fd, $line);
+ fputs( $fd, "$new\n" );
+ fputs( $fd, $line );
$done = true;
}
}
@@ -1095,7 +1143,7 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
fclose( $fd );
@rename( $tmp_file, $my_file );
- if ( function_exists( "opcache_invalidate" ) ) {
+ if ( function_exists( 'opcache_invalidate' ) ) {
opcache_invalidate( $my_file );
}
@@ -1106,17 +1154,17 @@ function wp_cache_phase2() {
global $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files, $cache_enabled, $wp_cache_gmt_offset, $wp_cache_blog_charset;
if ( $cache_enabled == false ) {
- wp_cache_debug( "Caching disabled! quiting!", 1 );
+ wp_cache_debug( 'Caching disabled! quiting!', 1 );
return false;
}
wp_cache_debug( 'In WP Cache Phase 2', 5 );
- $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. https://wordpress.org/support/topic/224349
+ $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. https://wordpress.org/support/topic/224349
$wp_cache_blog_charset = get_option( 'blog_charset' );
wp_cache_mutex_init();
- if(function_exists('add_action') && ( !defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) {
+ if ( function_exists( 'add_action' ) && ( ! defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) {
wp_cache_debug( 'Setting up WordPress actions', 5 );
add_action( 'template_redirect', 'wp_super_cache_query_vars' );
@@ -1124,22 +1172,22 @@ function wp_cache_phase2() {
add_filter( 'status_header', 'wpsc_catch_status_header', 10, 2 );
// Post ID is received
- add_action('wp_trash_post', 'wp_cache_post_edit', 0);
- add_action('publish_post', 'wp_cache_post_edit', 0);
- add_action('edit_post', 'wp_cache_post_change', 0); // leaving a comment called edit_post
- add_action('delete_post', 'wp_cache_post_edit', 0);
- add_action('publish_phone', 'wp_cache_post_edit', 0);
+ add_action( 'wp_trash_post', 'wp_cache_post_edit', 0 );
+ add_action( 'publish_post', 'wp_cache_post_edit', 0 );
+ add_action( 'edit_post', 'wp_cache_post_change', 0 ); // leaving a comment called edit_post
+ add_action( 'delete_post', 'wp_cache_post_edit', 0 );
+ add_action( 'publish_phone', 'wp_cache_post_edit', 0 );
// Coment ID is received
- add_action('trackback_post', 'wp_cache_get_postid_from_comment', 99);
- add_action('pingback_post', 'wp_cache_get_postid_from_comment', 99);
- add_action('comment_post', 'wp_cache_get_postid_from_comment', 99);
- add_action('edit_comment', 'wp_cache_get_postid_from_comment', 99);
- add_action('wp_set_comment_status', 'wp_cache_get_postid_from_comment', 99, 2);
+ add_action( 'trackback_post', 'wp_cache_get_postid_from_comment', 99 );
+ add_action( 'pingback_post', 'wp_cache_get_postid_from_comment', 99 );
+ add_action( 'comment_post', 'wp_cache_get_postid_from_comment', 99 );
+ add_action( 'edit_comment', 'wp_cache_get_postid_from_comment', 99 );
+ add_action( 'wp_set_comment_status', 'wp_cache_get_postid_from_comment', 99, 2 );
// No post_id is available
- add_action('switch_theme', 'wp_cache_no_postid', 99);
- add_action('edit_user_profile_update', 'wp_cache_no_postid', 99);
+ add_action( 'switch_theme', 'wp_cache_no_postid', 99 );
+ add_action( 'edit_user_profile_update', 'wp_cache_no_postid', 99 );
add_action( 'wp_update_nav_menu', 'wp_cache_clear_cache_on_menu' );
- add_action('wp_cache_gc','wp_cache_gc_cron');
+ add_action( 'wp_cache_gc', 'wp_cache_gc_cron' );
add_action( 'clean_post_cache', 'wp_cache_post_edit' );
add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' );
add_action( 'wp_cache_gc_watcher', 'wp_cache_gc_watcher' );
@@ -1158,19 +1206,21 @@ function wp_cache_phase2() {
$super_cache_enabled = false;
}
- if($wp_cache_gzip_encoding)
- header('Vary: Accept-Encoding, Cookie');
- else
- header('Vary: Cookie');
+ if ( $wp_cache_gzip_encoding ) {
+ header( 'Vary: Accept-Encoding, Cookie' );
+ } else {
+ header( 'Vary: Cookie' );
+ }
ob_start( 'wp_cache_ob_callback' );
wp_cache_debug( 'Created output buffer', 4 );
// restore old supercache file temporarily
- if ( ( $_SERVER["REQUEST_METHOD"] != 'POST' && empty( $_POST ) ) && $super_cache_enabled && $cache_rebuild_files ) {
+ if ( ( $_SERVER['REQUEST_METHOD'] != 'POST' && empty( $_POST ) ) && $super_cache_enabled && $cache_rebuild_files ) {
$user_info = wp_cache_get_cookies_values();
- $do_cache = apply_filters( 'do_createsupercache', $user_info );
- if( $user_info == '' || $do_cache === true )
+ $do_cache = apply_filters( 'do_createsupercache', $user_info );
+ if ( $user_info == '' || $do_cache === true ) {
wpcache_do_rebuild( get_current_url_supercache_dir() );
+ }
}
schedule_wp_gc();
@@ -1180,14 +1230,14 @@ function wpcache_do_rebuild( $dir ) {
global $do_rebuild_list, $cache_path, $wpsc_file_mtimes;
wp_cache_debug( "wpcache_do_rebuild: doing rebuild for $dir" );
- if ( !is_dir( $dir ) ) {
+ if ( ! is_dir( $dir ) ) {
wp_cache_debug( "wpcache_do_rebuild: exiting as directory is not a directory: $dir" );
return false;
}
$dir = wpsc_get_realpath( $dir );
if ( ! $dir ) {
- wp_cache_debug( "wpcache_do_rebuild: exiting as directory does not exist." );
+ wp_cache_debug( 'wpcache_do_rebuild: exiting as directory does not exist.' );
return false;
}
@@ -1197,7 +1247,7 @@ function wpcache_do_rebuild( $dir ) {
}
$protected = wpsc_get_protected_directories();
- foreach( $protected as $id => $directory ) {
+ foreach ( $protected as $id => $directory ) {
$protected[ $id ] = wpsc_get_realpath( $directory );
}
@@ -1211,7 +1261,7 @@ function wpcache_do_rebuild( $dir ) {
return false;
}
- if ( !is_dir( $dir ) ) {
+ if ( ! is_dir( $dir ) ) {
wp_cache_debug( "wpcache_do_rebuild: exiting as directory is not a directory: $dir" );
return false;
}
@@ -1222,7 +1272,7 @@ function wpcache_do_rebuild( $dir ) {
return false;
}
- $dir = trailingslashit( $dir );
+ $dir = trailingslashit( $dir );
$wpsc_file_mtimes = array();
while ( ( $file = readdir( $dh ) ) !== false ) {
if ( $file == '.' || $file == '..' || false == is_file( $dir . $file ) ) {
@@ -1234,7 +1284,6 @@ function wpcache_do_rebuild( $dir ) {
// if the rebuild file is less than 10 seconds old then remove the ".needs-rebuild"
// extension so index.html can be served to other visitors temporarily
// until index.html is generated again at the end of this page.
-
if ( substr( $cache_file, -14 ) != '.needs-rebuild' ) {
wp_cache_debug( "wpcache_do_rebuild: base file found: $cache_file" );
continue;
@@ -1256,7 +1305,7 @@ function wpcache_do_rebuild( $dir ) {
@unlink( $cache_file );
wp_cache_debug( "wpcache_do_rebuild: rebuild file rename failed. Deleted rebuild file: $cache_file" );
} else {
- $do_rebuild_list[ $dir ] = 1;
+ $do_rebuild_list[ $dir ] = 1;
$wpsc_file_mtimes[ $base_file ] = $mtime;
wp_cache_debug( "wpcache_do_rebuild: rebuild file renamed: $base_file" );
}
@@ -1274,72 +1323,78 @@ function wpcache_logged_in_message() {
function wp_cache_user_agent_is_rejected() {
global $cache_rejected_user_agent;
- if (!function_exists('apache_request_headers')) return false;
+ if ( ! function_exists( 'apache_request_headers' ) ) {
+ return false;
+ }
$headers = apache_request_headers();
- if (!isset($headers["User-Agent"])) return false;
- if ( false == is_array( $cache_rejected_user_agent ) )
+ if ( ! isset( $headers['User-Agent'] ) ) {
return false;
- foreach ($cache_rejected_user_agent as $expr) {
- if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
+ }
+ if ( false == is_array( $cache_rejected_user_agent ) ) {
+ return false;
+ }
+ foreach ( $cache_rejected_user_agent as $expr ) {
+ if ( strlen( $expr ) > 0 && stristr( $headers['User-Agent'], $expr ) ) {
return true;
+ }
}
return false;
}
function wp_cache_get_response_headers() {
static $known_headers = array(
- 'Access-Control-Allow-Origin',
- 'Accept-Ranges',
- 'Age',
- 'Allow',
- 'Cache-Control',
- 'Connection',
- 'Content-Encoding',
- 'Content-Language',
- 'Content-Length',
- 'Content-Location',
- 'Content-MD5',
- 'Content-Disposition',
- 'Content-Range',
- 'Content-Type',
- 'Date',
- 'ETag',
- 'Expires',
- 'Last-Modified',
- 'Link',
- 'Location',
- 'P3P',
- 'Pragma',
- 'Proxy-Authenticate',
- "Referrer-Policy",
- 'Refresh',
- 'Retry-After',
- 'Server',
- 'Status',
- 'Strict-Transport-Security',
- 'Trailer',
- 'Transfer-Encoding',
- 'Upgrade',
- 'Vary',
- 'Via',
- 'Warning',
- 'WWW-Authenticate',
- 'X-Frame-Options',
- 'Public-Key-Pins',
- 'X-XSS-Protection',
- 'Content-Security-Policy',
- "X-Pingback",
- 'X-Content-Security-Policy',
- 'X-WebKit-CSP',
- 'X-Content-Type-Options',
- 'X-Powered-By',
- 'X-UA-Compatible',
- 'X-Robots-Tag',
- );
+ 'Access-Control-Allow-Origin',
+ 'Accept-Ranges',
+ 'Age',
+ 'Allow',
+ 'Cache-Control',
+ 'Connection',
+ 'Content-Encoding',
+ 'Content-Language',
+ 'Content-Length',
+ 'Content-Location',
+ 'Content-MD5',
+ 'Content-Disposition',
+ 'Content-Range',
+ 'Content-Type',
+ 'Date',
+ 'ETag',
+ 'Expires',
+ 'Last-Modified',
+ 'Link',
+ 'Location',
+ 'P3P',
+ 'Pragma',
+ 'Proxy-Authenticate',
+ 'Referrer-Policy',
+ 'Refresh',
+ 'Retry-After',
+ 'Server',
+ 'Status',
+ 'Strict-Transport-Security',
+ 'Trailer',
+ 'Transfer-Encoding',
+ 'Upgrade',
+ 'Vary',
+ 'Via',
+ 'Warning',
+ 'WWW-Authenticate',
+ 'X-Frame-Options',
+ 'Public-Key-Pins',
+ 'X-XSS-Protection',
+ 'Content-Security-Policy',
+ 'X-Pingback',
+ 'X-Content-Security-Policy',
+ 'X-WebKit-CSP',
+ 'X-Content-Type-Options',
+ 'X-Powered-By',
+ 'X-UA-Compatible',
+ 'X-Robots-Tag',
+ );
$known_headers = apply_filters( 'wpsc_known_headers', $known_headers );
- if ( ! isset( $known_headers[ 'age' ] ) ) {
+ if ( ! isset( $known_headers['age'] ) ) {
$known_headers = array_map( 'strtolower', $known_headers );
}
@@ -1349,16 +1404,16 @@ function wp_cache_get_response_headers() {
}
if ( empty( $headers ) && function_exists( 'headers_list' ) ) {
$headers = array();
- foreach( headers_list() as $hdr ) {
+ foreach ( headers_list() as $hdr ) {
$header_parts = explode( ':', $hdr, 2 );
$header_name = isset( $header_parts[0] ) ? trim( $header_parts[0] ) : '';
$header_value = isset( $header_parts[1] ) ? trim( $header_parts[1] ) : '';
- $headers[$header_name] = $header_value;
+ $headers[ $header_name ] = $header_value;
}
}
- foreach( $headers as $key => $value ) {
+ foreach ( $headers as $key => $value ) {
if ( ! in_array( strtolower( $key ), $known_headers ) ) {
unset( $headers[ $key ] );
}
@@ -1367,19 +1422,22 @@ function wp_cache_get_response_headers() {
return $headers;
}
-function wp_cache_is_rejected($uri) {
+function wp_cache_is_rejected( $uri ) {
global $cache_rejected_uri;
$auto_rejected = array( '/wp-admin/', 'xmlrpc.php', 'wp-app.php' );
- foreach( $auto_rejected as $u ) {
- if( strstr( $uri, $u ) )
+ foreach ( $auto_rejected as $u ) {
+ if ( strstr( $uri, $u ) ) {
return true; // we don't allow caching of wp-admin for security reasons
+ }
}
- if ( false == is_array( $cache_rejected_uri ) )
+ if ( false == is_array( $cache_rejected_uri ) ) {
return false;
+ }
foreach ( $cache_rejected_uri as $expr ) {
- if( $expr != '' && @preg_match( "~$expr~", $uri ) )
+ if ( $expr != '' && @preg_match( "~$expr~", $uri ) ) {
return true;
+ }
}
return false;
}
@@ -1387,18 +1445,20 @@ function wp_cache_is_rejected($uri) {
function wp_cache_mutex_init() {
global $mutex, $wp_cache_mutex_disabled, $use_flock, $blog_cache_dir, $mutex_filename, $sem_id;
- if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
+ if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) {
return true;
+ }
- if( !is_bool( $use_flock ) ) {
- if(function_exists('sem_get'))
+ if ( ! is_bool( $use_flock ) ) {
+ if ( function_exists( 'sem_get' ) ) {
$use_flock = false;
- else
+ } else {
$use_flock = true;
+ }
}
$mutex = false;
- if ($use_flock ) {
+ if ( $use_flock ) {
setup_blog_cache_dir();
wp_cache_debug( "Created mutex lock on filename: {$blog_cache_dir}{$mutex_filename}", 5 );
$mutex = @fopen( $blog_cache_dir . $mutex_filename, 'w' );
@@ -1411,20 +1471,21 @@ function wp_cache_mutex_init() {
function wp_cache_writers_entry() {
global $mutex, $wp_cache_mutex_disabled, $use_flock;
- if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
+ if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) {
return true;
+ }
- if( !$mutex ) {
- wp_cache_debug( "(writers entry) mutex lock not created. not caching.", 2 );
+ if ( ! $mutex ) {
+ wp_cache_debug( '(writers entry) mutex lock not created. not caching.', 2 );
return false;
}
if ( $use_flock ) {
- wp_cache_debug( "grabbing lock using flock()", 5 );
- flock($mutex, LOCK_EX);
+ wp_cache_debug( 'grabbing lock using flock()', 5 );
+ flock( $mutex, LOCK_EX );
} else {
- wp_cache_debug( "grabbing lock using sem_acquire()", 5 );
- @sem_acquire($mutex);
+ wp_cache_debug( 'grabbing lock using sem_acquire()', 5 );
+ @sem_acquire( $mutex );
}
return true;
@@ -1433,79 +1494,92 @@ function wp_cache_writers_entry() {
function wp_cache_writers_exit() {
global $mutex, $wp_cache_mutex_disabled, $use_flock;
- if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
+ if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) {
return true;
+ }
- if( !$mutex ) {
- wp_cache_debug( "(writers exit) mutex lock not created. not caching.", 2 );
+ if ( ! $mutex ) {
+ wp_cache_debug( '(writers exit) mutex lock not created. not caching.', 2 );
return false;
}
if ( $use_flock ) {
- wp_cache_debug( "releasing lock using flock()", 5 );
- flock( $mutex, LOCK_UN );
+ wp_cache_debug( 'releasing lock using flock()', 5 );
+ flock( $mutex, LOCK_UN );
} else {
- wp_cache_debug( "releasing lock using sem_release() and sem_remove()", 5 );
+ wp_cache_debug( 'releasing lock using sem_release() and sem_remove()', 5 );
@sem_release( $mutex );
- if ( defined( "WPSC_REMOVE_SEMAPHORE" ) )
+ if ( defined( 'WPSC_REMOVE_SEMAPHORE' ) ) {
@sem_remove( $mutex );
+ }
}
}
function wp_super_cache_query_vars() {
global $wp_super_cache_query;
- if ( is_search() )
- $wp_super_cache_query[ 'is_search' ] = 1;
- if ( is_page() )
- $wp_super_cache_query[ 'is_page' ] = 1;
- if ( is_archive() )
- $wp_super_cache_query[ 'is_archive' ] = 1;
- if ( is_tag() )
- $wp_super_cache_query[ 'is_tag' ] = 1;
- if ( is_single() )
- $wp_super_cache_query[ 'is_single' ] = 1;
- if ( is_category() )
- $wp_super_cache_query[ 'is_category' ] = 1;
- if ( is_front_page() )
- $wp_super_cache_query[ 'is_front_page' ] = 1;
- if ( is_home() )
- $wp_super_cache_query[ 'is_home' ] = 1;
- if ( is_author() )
- $wp_super_cache_query[ 'is_author' ] = 1;
+ if ( is_search() ) {
+ $wp_super_cache_query['is_search'] = 1;
+ }
+ if ( is_page() ) {
+ $wp_super_cache_query['is_page'] = 1;
+ }
+ if ( is_archive() ) {
+ $wp_super_cache_query['is_archive'] = 1;
+ }
+ if ( is_tag() ) {
+ $wp_super_cache_query['is_tag'] = 1;
+ }
+ if ( is_single() ) {
+ $wp_super_cache_query['is_single'] = 1;
+ }
+ if ( is_category() ) {
+ $wp_super_cache_query['is_category'] = 1;
+ }
+ if ( is_front_page() ) {
+ $wp_super_cache_query['is_front_page'] = 1;
+ }
+ if ( is_home() ) {
+ $wp_super_cache_query['is_home'] = 1;
+ }
+ if ( is_author() ) {
+ $wp_super_cache_query['is_author'] = 1;
+ }
// REST API
- if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
- ( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
- ( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST )
+ if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
+ ( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
+ ( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST )
) {
- $wp_super_cache_query[ 'is_rest' ] = 1;
+ $wp_super_cache_query['is_rest'] = 1;
}
// Feeds, sitemaps and robots.txt
if ( is_feed() ) {
- $wp_super_cache_query[ 'is_feed' ] = 1;
+ $wp_super_cache_query['is_feed'] = 1;
if ( get_query_var( 'feed' ) == 'sitemap' ) {
- $wp_super_cache_query[ 'is_sitemap' ] = 1;
+ $wp_super_cache_query['is_sitemap'] = 1;
}
} elseif ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) {
- $wp_super_cache_query[ 'is_feed' ] = 1;
- $wp_super_cache_query[ 'is_sitemap' ] = 1;
+ $wp_super_cache_query['is_feed'] = 1;
+ $wp_super_cache_query['is_sitemap'] = 1;
} elseif ( is_robots() ) {
- $wp_super_cache_query[ 'is_robots' ] = 1;
+ $wp_super_cache_query['is_robots'] = 1;
}
// Reset everything if it's 404
- if ( is_404() )
+ if ( is_404() ) {
$wp_super_cache_query = array( 'is_404' => 1 );
+ }
return $wp_super_cache_query;
}
function wpsc_catch_status_header( $status_header, $code ) {
- if ( $code != 200 )
+ if ( $code != 200 ) {
wpsc_catch_http_status_code( $code );
+ }
return $status_header;
}
@@ -1514,11 +1588,11 @@ function wpsc_catch_http_status_code( $status ) {
global $wp_super_cache_query;
if ( in_array( intval( $status ), array( 301, 302, 303, 307 ) ) ) {
- $wp_super_cache_query[ 'is_redirect' ] = 1;
+ $wp_super_cache_query['is_redirect'] = 1;
} elseif ( $status == 304 ) {
- $wp_super_cache_query[ 'is_304' ] = 1;
+ $wp_super_cache_query['is_304'] = 1;
} elseif ( $status == 404 ) {
- $wp_super_cache_query[ 'is_404' ] = 1;
+ $wp_super_cache_query['is_404'] = 1;
}
return $status;
@@ -1532,7 +1606,7 @@ function wpsc_is_fatal_error() {
}
if ( $error['type'] & ( E_ERROR | E_CORE_ERROR | E_PARSE | E_COMPILE_ERROR | E_USER_ERROR ) ) {
- $wp_super_cache_query[ 'is_fatal_error' ] = 1;
+ $wp_super_cache_query['is_fatal_error'] = 1;
return true;
}
@@ -1541,7 +1615,7 @@ function wpsc_is_fatal_error() {
function wp_cache_ob_callback( $buffer ) {
global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_object_cache, $wp_cache_request_uri, $do_rebuild_list, $wpsc_file_mtimes, $wpsc_save_headers, $super_cache_enabled;
- $script = basename( $_SERVER[ 'PHP_SELF' ] );
+ $script = basename( $_SERVER['PHP_SELF'] );
// All the things that can stop a page being cached
$cache_this_page = true;
@@ -1549,7 +1623,7 @@ function wp_cache_ob_callback( $buffer ) {
if ( wpsc_is_fatal_error() ) {
wp_cache_debug( 'wp_cache_ob_callback: PHP Fatal error occurred. Not caching incomplete page.' );
$cache_this_page = false;
- } elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && is_object( $wp_query ) && method_exists( $wp_query, 'get' ) ) {
+ } elseif ( empty( $wp_super_cache_query ) && ! empty( $buffer ) && is_object( $wp_query ) && method_exists( $wp_query, 'get' ) ) {
$wp_super_cache_query = wp_super_cache_query_vars();
} elseif ( empty( $wp_super_cache_query ) && function_exists( 'http_response_code' ) ) {
wpsc_catch_http_status_code( http_response_code() );
@@ -1561,78 +1635,79 @@ function wp_cache_ob_callback( $buffer ) {
wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
$cache_this_page = false;
} elseif ( $wp_cache_no_cache_for_get && ! empty( $_GET ) ) {
- wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . wpsc_dump_get_request(), 1 );
+ wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 );
$cache_this_page = false;
- } elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
+ } elseif ( $_SERVER['REQUEST_METHOD'] == 'POST' || ! empty( $_POST ) || get_option( 'gzipcompression' ) ) {
wp_cache_debug( 'Not caching POST request.', 5 );
$cache_this_page = false;
- } elseif ( $_SERVER["REQUEST_METHOD"] == 'PUT' ) {
+ } elseif ( $_SERVER['REQUEST_METHOD'] == 'PUT' ) {
wp_cache_debug( 'Not caching PUT request.', 5 );
$cache_this_page = false;
- } elseif ( $_SERVER["REQUEST_METHOD"] == 'DELETE' ) {
+ } elseif ( $_SERVER['REQUEST_METHOD'] == 'DELETE' ) {
wp_cache_debug( 'Not caching DELETE request.', 5 );
$cache_this_page = false;
- } elseif ( $wp_cache_object_cache && !empty( $_GET ) ) {
+ } elseif ( $wp_cache_object_cache && ! empty( $_GET ) ) {
wp_cache_debug( 'Not caching GET request while object cache storage enabled.', 5 );
$cache_this_page = false;
- } elseif ( isset( $_GET[ 'preview' ] ) ) {
+ } elseif ( isset( $_GET['preview'] ) ) {
wp_cache_debug( 'Not caching preview post.', 2 );
$cache_this_page = false;
- } elseif ( !in_array( $script, (array) $cache_acceptable_files ) && wp_cache_is_rejected( $wp_cache_request_uri ) ) {
+ } elseif ( ! in_array( $script, (array) $cache_acceptable_files ) && wp_cache_is_rejected( $wp_cache_request_uri ) ) {
wp_cache_debug( 'URI rejected. Not Caching', 2 );
$cache_this_page = false;
} elseif ( wp_cache_user_agent_is_rejected() ) {
wp_cache_debug( "USER AGENT ({$_SERVER[ 'HTTP_USER_AGENT' ]}) rejected. Not Caching", 4 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'single' ] ) && $wp_cache_pages[ 'single' ] == 1 && isset( $wp_super_cache_query[ 'is_single' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['single'] ) && $wp_cache_pages['single'] == 1 && isset( $wp_super_cache_query['is_single'] ) ) {
wp_cache_debug( 'Not caching single post.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'pages' ] ) && $wp_cache_pages[ 'pages' ] == 1 && isset( $wp_super_cache_query[ 'is_page' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['pages'] ) && $wp_cache_pages['pages'] == 1 && isset( $wp_super_cache_query['is_page'] ) ) {
wp_cache_debug( 'Not caching single page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'archives' ] ) && $wp_cache_pages[ 'archives' ] == 1 && isset( $wp_super_cache_query[ 'is_archive' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['archives'] ) && $wp_cache_pages['archives'] == 1 && isset( $wp_super_cache_query['is_archive'] ) ) {
wp_cache_debug( 'Not caching archive page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'tag' ] ) && $wp_cache_pages[ 'tag' ] == 1 && isset( $wp_super_cache_query[ 'is_tag' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['tag'] ) && $wp_cache_pages['tag'] == 1 && isset( $wp_super_cache_query['is_tag'] ) ) {
wp_cache_debug( 'Not caching tag page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'category' ] ) && $wp_cache_pages[ 'category' ] == 1 && isset( $wp_super_cache_query[ 'is_category' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['category'] ) && $wp_cache_pages['category'] == 1 && isset( $wp_super_cache_query['is_category'] ) ) {
wp_cache_debug( 'Not caching category page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'frontpage' ] ) && $wp_cache_pages[ 'frontpage' ] == 1 && isset( $wp_super_cache_query[ 'is_front_page' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['frontpage'] ) && $wp_cache_pages['frontpage'] == 1 && isset( $wp_super_cache_query['is_front_page'] ) ) {
wp_cache_debug( 'Not caching front page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'home' ] ) && $wp_cache_pages[ 'home' ] == 1 && isset( $wp_super_cache_query[ 'is_home' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['home'] ) && $wp_cache_pages['home'] == 1 && isset( $wp_super_cache_query['is_home'] ) ) {
wp_cache_debug( 'Not caching home page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'search' ] ) && $wp_cache_pages[ 'search' ] == 1 && isset( $wp_super_cache_query[ 'is_search' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['search'] ) && $wp_cache_pages['search'] == 1 && isset( $wp_super_cache_query['is_search'] ) ) {
wp_cache_debug( 'Not caching search page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'author' ] ) && $wp_cache_pages[ 'author' ] == 1 && isset( $wp_super_cache_query[ 'is_author' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['author'] ) && $wp_cache_pages['author'] == 1 && isset( $wp_super_cache_query['is_author'] ) ) {
wp_cache_debug( 'Not caching author page.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_cache_pages[ 'feed' ] ) && $wp_cache_pages[ 'feed' ] == 1 && isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
+ } elseif ( isset( $wp_cache_pages['feed'] ) && $wp_cache_pages['feed'] == 1 && isset( $wp_super_cache_query['is_feed'] ) ) {
wp_cache_debug( 'Not caching feed.', 2 );
$cache_this_page = false;
- } elseif ( isset( $wp_super_cache_query[ 'is_rest' ] ) ) {
+ } elseif ( isset( $wp_super_cache_query['is_rest'] ) ) {
wp_cache_debug( 'REST API detected. Caching disabled.' );
$cache_this_page = false;
- } elseif ( isset( $wp_super_cache_query[ 'is_robots' ] ) ) {
+ } elseif ( isset( $wp_super_cache_query['is_robots'] ) ) {
wp_cache_debug( 'robots.txt detected. Caching disabled.' );
$cache_this_page = false;
- } elseif ( isset( $wp_super_cache_query[ 'is_redirect' ] ) ) {
+ } elseif ( isset( $wp_super_cache_query['is_redirect'] ) ) {
wp_cache_debug( 'Redirect detected. Caching disabled.' );
$cache_this_page = false;
- } elseif ( isset( $wp_super_cache_query[ 'is_304' ] ) ) {
+ } elseif ( isset( $wp_super_cache_query['is_304'] ) ) {
wp_cache_debug( 'HTTP 304 (Not Modified) sent. Caching disabled.' );
$cache_this_page = false;
- } elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && apply_filters( 'wpsc_only_cache_known_pages', 1 ) ) {
+ } elseif ( empty( $wp_super_cache_query ) && ! empty( $buffer ) && apply_filters( 'wpsc_only_cache_known_pages', 1 ) ) {
wp_cache_debug( 'wp_cache_ob_callback: wp_super_cache_query is empty. Not caching unknown page type. Return 0 to the wpsc_only_cache_known_pages filter to cache this page.' );
$cache_this_page = false;
}
- if ( isset( $wpsc_save_headers ) && $wpsc_save_headers )
+ if ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {
$super_cache_enabled = false; // use standard caching to record headers
+ }
if ( $cache_this_page ) {
@@ -1641,8 +1716,8 @@ function wp_cache_ob_callback( $buffer ) {
$buffer = wp_cache_get_ob( $buffer );
wp_cache_shutdown_callback();
- if ( !empty( $wpsc_file_mtimes ) && is_array( $wpsc_file_mtimes ) ) {
- foreach( $wpsc_file_mtimes as $cache_file => $old_mtime ) {
+ if ( ! empty( $wpsc_file_mtimes ) && is_array( $wpsc_file_mtimes ) ) {
+ foreach ( $wpsc_file_mtimes as $cache_file => $old_mtime ) {
if ( $old_mtime == @filemtime( $cache_file ) ) {
wp_cache_debug( "wp_cache_ob_callback deleting unmodified rebuilt cache file: $cache_file" );
if ( wp_cache_confirm_delete( $cache_file ) ) {
@@ -1653,8 +1728,8 @@ function wp_cache_ob_callback( $buffer ) {
}
return $buffer;
} else {
- if ( !empty( $do_rebuild_list ) && is_array( $do_rebuild_list ) ) {
- foreach( $do_rebuild_list as $dir => $n ) {
+ if ( ! empty( $do_rebuild_list ) && is_array( $do_rebuild_list ) ) {
+ foreach ( $do_rebuild_list as $dir => $n ) {
if ( wp_cache_confirm_delete( $dir ) ) {
wp_cache_debug( 'wp_cache_ob_callback clearing rebuilt files in ' . $dir );
wpsc_delete_files( $dir );
@@ -1669,13 +1744,15 @@ function wp_cache_append_tag( &$buffer ) {
global $wp_cache_gmt_offset, $wp_super_cache_comments;
global $cache_enabled, $super_cache_enabled;
- if ( false == isset( $wp_super_cache_comments ) )
+ if ( false == isset( $wp_super_cache_comments ) ) {
$wp_super_cache_comments = 1;
+ }
- if ( $wp_super_cache_comments == 0 )
+ if ( $wp_super_cache_comments == 0 ) {
return false;
+ }
- $timestamp = gmdate('Y-m-d H:i:s', (time() + ( $wp_cache_gmt_offset * 3600)));
+ $timestamp = gmdate( 'Y-m-d H:i:s', ( time() + ( $wp_cache_gmt_offset * 3600 ) ) );
if ( $cache_enabled || $super_cache_enabled ) {
$msg = "Cached page generated by WP-Super-Cache on $timestamp";
} else {
@@ -1683,7 +1760,7 @@ function wp_cache_append_tag( &$buffer ) {
}
if ( strpos( $buffer, '|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) {
+ if ( ! preg_match( apply_filters( 'wp_cache_eof_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) {
$new_cache = false;
- if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
- wp_cache_debug( "No closing html tag. Not caching.", 2 );
- wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme." );
+ if ( isset( $GLOBALS['wp_super_cache_debug'] ) && $GLOBALS['wp_super_cache_debug'] ) {
+ wp_cache_debug( 'No closing html tag. Not caching.', 2 );
+ wp_cache_add_to_buffer( $buffer, 'Page not cached by WP Super Cache. No closing HTML tag. Check your theme.' );
}
}
- if( !$new_cache )
+ if ( ! $new_cache ) {
return wp_cache_maybe_dynamic( $buffer );
+ }
- $duration = wp_cache_microtime_diff($wp_start_time, microtime());
- $duration = sprintf("%0.3f", $duration);
+ $duration = wp_cache_microtime_diff( $wp_start_time, microtime() );
+ $duration = sprintf( '%0.3f', $duration );
wp_cache_add_to_buffer( $buffer, "Dynamic page generated in $duration seconds." );
- if( !wp_cache_writers_entry() ) {
- wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Could not get mutex lock." );
- wp_cache_debug( "Could not get mutex lock. Not caching.", 1 );
+ if ( ! wp_cache_writers_entry() ) {
+ wp_cache_add_to_buffer( $buffer, 'Page not cached by WP Super Cache. Could not get mutex lock.' );
+ wp_cache_debug( 'Could not get mutex lock. Not caching.', 1 );
return wp_cache_maybe_dynamic( $buffer );
}
- if ( $wp_cache_not_logged_in && isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
- wp_cache_debug( "Feed detected. Writing wpcache cache files.", 5 );
+ if ( $wp_cache_not_logged_in && isset( $wp_super_cache_query['is_feed'] ) ) {
+ wp_cache_debug( 'Feed detected. Writing wpcache cache files.', 5 );
$wp_cache_not_logged_in = false;
}
$home_url = parse_url( trailingslashit( get_bloginfo( 'url' ) ) );
- $dir = get_current_url_supercache_dir();
- $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]);
- if ( ! empty( $_GET ) || isset( $wp_super_cache_query[ 'is_feed' ] ) || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) {
- wp_cache_debug( "Supercache disabled: GET or feed detected or disabled by config.", 2 );
+ $dir = get_current_url_supercache_dir();
+ $supercachedir = $cache_path . 'supercache/' . preg_replace( '/:.*$/', '', $home_url['host'] );
+ if ( ! empty( $_GET ) || isset( $wp_super_cache_query['is_feed'] ) || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) {
+ wp_cache_debug( 'Supercache disabled: GET or feed detected or disabled by config.', 2 );
$super_cache_enabled = false;
}
$tmp_wpcache_filename = $cache_path . uniqid( mt_rand(), true ) . '.tmp';
$supercacheonly = false;
- if( $super_cache_enabled ) {
+ if ( $super_cache_enabled ) {
if ( wp_cache_get_cookies_values() == '' && empty( $_GET ) ) {
- wp_cache_debug( "Anonymous user detected. Only creating Supercache file.", 3 );
+ wp_cache_debug( 'Anonymous user detected. Only creating Supercache file.', 3 );
$supercacheonly = true;
}
}
@@ -1804,40 +1886,42 @@ function wp_cache_get_ob(&$buffer) {
$cache_error = '';
if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() != '' ) {
$super_cache_enabled = false;
- $cache_enabled = false;
- $cache_error = 'Not caching requests by known users. (See Advanced Settings page)';
+ $cache_enabled = false;
+ $cache_error = 'Not caching requests by known users. (See Advanced Settings page)';
wp_cache_debug( 'Not caching for known user.', 5 );
}
if ( $wp_cache_object_cache ) { // half on mode when using the object cache
if ( wp_cache_get_cookies_values() != '' ) {
$cache_enabled = false;
- $cache_error = 'Known User and using object. Only anonymous users cached.';
+ $cache_error = 'Known User and using object. Only anonymous users cached.';
}
$super_cache_enabled = false;
- $supercacheonly = false;
+ $supercacheonly = false;
wp_cache_init(); // PHP5 destroys objects during shutdown
}
- if ( !$cache_enabled ) {
+ if ( ! $cache_enabled ) {
wp_cache_debug( 'Cache is not enabled. Sending buffer to browser.', 5 );
wp_cache_writers_exit();
wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Check your settings page. $cache_error" );
if ( $wp_cache_mfunc_enabled == 1 ) {
global $wp_super_cache_late_init;
- if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) )
+ if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) {
wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details.' );
+ }
}
return wp_cache_maybe_dynamic( $buffer );
}
- if( @is_dir( $dir ) == false )
+ if ( @is_dir( $dir ) == false ) {
@wp_mkdir_p( $dir );
+ }
$dir = wpsc_get_realpath( $dir );
if ( ! $dir ) {
- wp_cache_debug( "wp_cache_get_ob: not caching as directory does not exist." );
+ wp_cache_debug( 'wp_cache_get_ob: not caching as directory does not exist.' );
return $buffer;
}
@@ -1851,34 +1935,34 @@ function wp_cache_get_ob(&$buffer) {
$fr = $fr2 = $gz = false;
// Open wp-cache cache file
if ( false == $wp_cache_object_cache ) {
- if ( !$supercacheonly ) {
- $fr = @fopen($tmp_wpcache_filename, 'w');
- if (!$fr) {
- wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename, 1 );
+ if ( ! $supercacheonly ) {
+ $fr = @fopen( $tmp_wpcache_filename, 'w' );
+ if ( ! $fr ) {
+ wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $cache_path ) . $cache_filename, 1 );
wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename );
wp_cache_writers_exit();
return wp_cache_maybe_dynamic( $buffer );
}
} else {
$user_info = wp_cache_get_cookies_values();
- $do_cache = apply_filters( 'do_createsupercache', $user_info );
+ $do_cache = apply_filters( 'do_createsupercache', $user_info );
if ( $super_cache_enabled && ( $user_info == '' || $do_cache === true ) ) {
- $cache_fname = $dir . supercache_filename();
+ $cache_fname = $dir . supercache_filename();
$tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
- $fr2 = @fopen( $tmp_cache_filename, 'w' );
- if ( !$fr2 ) {
- wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 );
+ $fr2 = @fopen( $tmp_cache_filename, 'w' );
+ if ( ! $fr2 ) {
+ wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 );
wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) );
@fclose( $fr );
@unlink( $tmp_wpcache_filename );
wp_cache_writers_exit();
return wp_cache_maybe_dynamic( $buffer );
- } elseif ( ( !isset( $wp_cache_mfunc_enabled ) || $wp_cache_mfunc_enabled == 0 ) && $cache_compression ) { // don't want to store compressed files if using dynamic content
- $gz = @fopen( $tmp_cache_filename . ".gz", 'w');
- if (!$gz) {
- wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz", 1 );
- wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz" );
+ } elseif ( ( ! isset( $wp_cache_mfunc_enabled ) || $wp_cache_mfunc_enabled == 0 ) && $cache_compression ) { // don't want to store compressed files if using dynamic content
+ $gz = @fopen( $tmp_cache_filename . '.gz', 'w' );
+ if ( ! $gz ) {
+ wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz', 1 );
+ wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz' );
@fclose( $fr );
@unlink( $tmp_wpcache_filename );
@fclose( $fr2 );
@@ -1892,8 +1976,8 @@ function wp_cache_get_ob(&$buffer) {
}
$added_cache = 0;
- $oc_key = get_oc_key();
- $buffer = apply_filters( 'wpsupercache_buffer', $buffer );
+ $oc_key = get_oc_key();
+ $buffer = apply_filters( 'wpsupercache_buffer', $buffer );
wp_cache_append_tag( $buffer );
/*
@@ -1901,87 +1985,89 @@ function wp_cache_get_ob(&$buffer) {
* the wpsc_cachedata filter. Buffer is then returned to the visitor.
*/
if ( $wp_cache_mfunc_enabled == 1 ) {
- if ( preg_match( '//', $buffer ) ) { //Dynamic content
- wp_cache_debug( "mfunc/mclude/dynamic-cached-content tags have been retired. Please update your theme. See docs for updates." );
- wp_cache_add_to_buffer( $buffer, "Warning! Obsolete mfunc/mclude/dynamic-cached-content tags found. Please update your theme. See http://ocaoimh.ie/y/5b for more information." );
+ if ( preg_match( '//', $buffer ) ) { // Dynamic content
+ wp_cache_debug( 'mfunc/mclude/dynamic-cached-content tags have been retired. Please update your theme. See docs for updates.' );
+ wp_cache_add_to_buffer( $buffer, 'Warning! Obsolete mfunc/mclude/dynamic-cached-content tags found. Please update your theme. See http://ocaoimh.ie/y/5b for more information.' );
}
global $wp_super_cache_late_init;
- if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) )
+ if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) {
wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but late init not set. See the readme.txt for further details.' );
+ }
if ( $fr ) { // wpcache caching
- wp_cache_debug( "Writing dynamic buffer to wpcache file." );
- wp_cache_add_to_buffer( $buffer, "Dynamic WPCache Super Cache" );
+ wp_cache_debug( 'Writing dynamic buffer to wpcache file.' );
+ wp_cache_add_to_buffer( $buffer, 'Dynamic WPCache Super Cache' );
fputs( $fr, '' . $buffer );
} elseif ( isset( $fr2 ) ) { // supercache active
- wp_cache_debug( "Writing dynamic buffer to supercache file." );
- wp_cache_add_to_buffer( $buffer, "Dynamic Super Cache" );
+ wp_cache_debug( 'Writing dynamic buffer to supercache file.' );
+ wp_cache_add_to_buffer( $buffer, 'Dynamic Super Cache' );
fputs( $fr2, $buffer );
} elseif ( true == $wp_cache_object_cache ) {
wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time );
}
- $wp_cache_meta[ 'dynamic' ] = true;
+ $wp_cache_meta['dynamic'] = true;
if ( $wp_cache_mfunc_enabled == 1 && do_cacheaction( 'wpsc_cachedata_safety', 0 ) === 1 ) {
$buffer = do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display
}
if ( $cache_compression && $wp_cache_gzip_encoding ) {
- wp_cache_debug( "Gzipping dynamic buffer for display.", 5 );
- wp_cache_add_to_buffer( $buffer, "Compression = gzip" );
+ wp_cache_debug( 'Gzipping dynamic buffer for display.', 5 );
+ wp_cache_add_to_buffer( $buffer, 'Compression = gzip' );
$gzdata = gzencode( $buffer, 6, FORCE_GZIP );
$gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata );
}
} else {
if ( $gz || $wp_cache_gzip_encoding ) {
- wp_cache_debug( "Gzipping buffer.", 5 );
- wp_cache_add_to_buffer( $buffer, "Compression = gzip" );
+ wp_cache_debug( 'Gzipping buffer.', 5 );
+ wp_cache_add_to_buffer( $buffer, 'Compression = gzip' );
$gzdata = gzencode( $buffer, 6, FORCE_GZIP );
$gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata );
- $wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
- $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie';
+ $wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
+ $wp_cache_meta['headers']['Vary'] = 'Vary: Accept-Encoding, Cookie';
// Return uncompressed data & store compressed for later use
if ( $fr ) {
- wp_cache_debug( "Writing gzipped buffer to wp-cache cache file.", 5 );
- fputs($fr, '' . $gzdata);
+ wp_cache_debug( 'Writing gzipped buffer to wp-cache cache file.', 5 );
+ fputs( $fr, '' . $gzdata );
} elseif ( $cache_enabled && $wp_cache_object_cache ) {
- wp_cache_set( $oc_key . ".gz", $gzdata, 'supercache', $cache_max_time );
+ wp_cache_set( $oc_key . '.gz', $gzdata, 'supercache', $cache_max_time );
$added_cache = 1;
}
} else { // no compression
- $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Cookie';
+ $wp_cache_meta['headers']['Vary'] = 'Vary: Cookie';
if ( $cache_enabled && $wp_cache_object_cache ) {
wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time );
$added_cache = 1;
} elseif ( $fr ) {
- wp_cache_debug( "Writing non-gzipped buffer to wp-cache cache file." );
- fputs($fr, '' . $buffer);
+ wp_cache_debug( 'Writing non-gzipped buffer to wp-cache cache file.' );
+ fputs( $fr, '' . $buffer );
}
}
if ( $fr2 ) {
- wp_cache_debug( "Writing non-gzipped buffer to supercache file." );
- wp_cache_add_to_buffer( $buffer, "super cache" );
- fputs($fr2, $buffer );
+ wp_cache_debug( 'Writing non-gzipped buffer to supercache file.' );
+ wp_cache_add_to_buffer( $buffer, 'super cache' );
+ fputs( $fr2, $buffer );
}
if ( isset( $gzdata ) && $gz ) {
- wp_cache_debug( "Writing gzipped buffer to supercache file." );
- fwrite($gz, $gzdata );
+ wp_cache_debug( 'Writing gzipped buffer to supercache file.' );
+ fwrite( $gz, $gzdata );
}
}
$new_cache = true;
if ( false == $wp_cache_object_cache ) {
- if( $fr ) {
+ if ( $fr ) {
$supercacheonly = false;
- fclose($fr);
+ fclose( $fr );
if ( filesize( $tmp_wpcache_filename ) == 0 ) {
wp_cache_debug( "Warning! The file $tmp_wpcache_filename was empty. Did not rename to {$dir}/{$cache_filename}", 5 );
@unlink( $tmp_wpcache_filename );
} else {
- if ( !@rename( $tmp_wpcache_filename, $dir . '/' . $cache_filename ) ) {
- if ( false == is_dir( $dir ) )
+ if ( ! @rename( $tmp_wpcache_filename, $dir . '/' . $cache_filename ) ) {
+ if ( false == is_dir( $dir ) ) {
@wp_mkdir_p( $dir );
+ }
@unlink( $dir . $cache_filename );
@rename( $tmp_wpcache_filename, $dir . '/' . $cache_filename );
}
@@ -1989,17 +2075,17 @@ function wp_cache_get_ob(&$buffer) {
$added_cache = 1;
}
}
- if( $fr2 ) {
- fclose($fr2);
- if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url[ 'path' ] . supercache_filename() && !( $wp_cache_is_home ) ) {
+ if ( $fr2 ) {
+ fclose( $fr2 );
+ if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url['path'] . supercache_filename() && ! ( $wp_cache_is_home ) ) {
wp_cache_writers_exit();
- wp_cache_debug( "Warning! Not writing another page to front page cache.", 1 );
+ wp_cache_debug( 'Warning! Not writing another page to front page cache.', 1 );
return $buffer;
} elseif ( filesize( $tmp_cache_filename ) == 0 ) {
wp_cache_debug( "Warning! The file $tmp_cache_filename was empty. Did not rename to {$cache_fname}", 5 );
@unlink( $tmp_cache_filename );
} else {
- if ( !@rename( $tmp_cache_filename, $cache_fname ) ) {
+ if ( ! @rename( $tmp_cache_filename, $cache_fname ) ) {
@unlink( $cache_fname );
@rename( $tmp_cache_filename, $cache_fname );
}
@@ -2007,13 +2093,13 @@ function wp_cache_get_ob(&$buffer) {
$added_cache = 1;
}
}
- if( $gz ) {
- fclose($gz);
+ if ( $gz ) {
+ fclose( $gz );
if ( filesize( $tmp_cache_filename . '.gz' ) == 0 ) {
wp_cache_debug( "Warning! The file {$tmp_cache_filename}.gz was empty. Did not rename to {$cache_fname}.gz", 5 );
@unlink( $tmp_cache_filename . '.gz' );
} else {
- if ( !@rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ) ) {
+ if ( ! @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ) ) {
@unlink( $cache_fname . '.gz' );
@rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' );
}
@@ -2024,49 +2110,54 @@ function wp_cache_get_ob(&$buffer) {
}
if ( $added_cache && isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
update_option( 'wpsupercache_count', ( get_option( 'wpsupercache_count' ) + 1 ) );
- $last_urls = (array)get_option( 'supercache_last_cached' );
- if ( count( $last_urls ) >= 10 )
+ $last_urls = (array) get_option( 'supercache_last_cached' );
+ if ( count( $last_urls ) >= 10 ) {
$last_urls = array_slice( $last_urls, 1, 9 );
- $last_urls[] = array( 'url' => preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] ), 'date' => date( 'Y-m-d H:i:s' ) );
+ }
+ $last_urls[] = array(
+ 'url' => preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ),
+ 'date' => date( 'Y-m-d H:i:s' ),
+ );
update_option( 'supercache_last_cached', $last_urls );
}
wp_cache_writers_exit();
- if ( !headers_sent() && $wp_cache_gzip_encoding && $gzdata) {
- wp_cache_debug( "Writing gzip content headers. Sending buffer to browser", 5 );
+ if ( ! headers_sent() && $wp_cache_gzip_encoding && $gzdata ) {
+ wp_cache_debug( 'Writing gzip content headers. Sending buffer to browser', 5 );
header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
header( 'Vary: Accept-Encoding, Cookie' );
header( 'Content-Length: ' . $gzsize );
return $gzdata;
} else {
- wp_cache_debug( "Sending buffer to browser", 5 );
+ wp_cache_debug( 'Sending buffer to browser', 5 );
return $buffer;
}
}
-function wp_cache_phase2_clean_cache($file_prefix) {
+function wp_cache_phase2_clean_cache( $file_prefix ) {
global $wpdb, $blog_cache_dir;
- if( !wp_cache_writers_entry() )
+ if ( ! wp_cache_writers_entry() ) {
return false;
+ }
wp_cache_debug( "wp_cache_phase2_clean_cache: Cleaning cache in $blog_cache_dir" );
if ( $handle = @opendir( $blog_cache_dir ) ) {
- while ( false !== ($file = @readdir($handle))) {
+ while ( false !== ( $file = @readdir( $handle ) ) ) {
if ( strpos( $file, $file_prefix ) !== false ) {
if ( strpos( $file, '.html' ) ) {
// delete old wpcache files immediately
wp_cache_debug( "wp_cache_phase2_clean_cache: Deleting obsolete wpcache cache+meta files: $file" );
- @unlink( $blog_cache_dir . $file);
+ @unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
} else {
$meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
- if ( $meta[ 'blog_id' ] == $wpdb->blogid ) {
+ if ( $meta['blog_id'] == $wpdb->blogid ) {
@unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . 'meta/' . $file );
}
}
}
}
- closedir($handle);
+ closedir( $handle );
}
wp_cache_writers_exit();
}
@@ -2075,15 +2166,15 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
// Don't prune a NULL/empty directory.
if ( null === $directory || '' === $directory ) {
- wp_cache_debug( "prune_super_cache: directory is blank" );
+ wp_cache_debug( 'prune_super_cache: directory is blank' );
return false;
}
global $cache_max_time, $cache_path, $blog_cache_dir;
- static $log = 0;
+ static $log = 0;
static $protected_directories = '';
- $dir = $directory;
+ $dir = $directory;
$directory = wpsc_get_realpath( $directory );
if ( $directory == '' ) {
wp_cache_debug( "prune_super_cache: exiting as file/directory does not exist : $dir" );
@@ -2098,8 +2189,9 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
wp_cache_debug( "prune_super_cache: exiting as file/dir does not exist: $directory" );
return $log;
}
- if( !isset( $cache_max_time ) )
+ if ( ! isset( $cache_max_time ) ) {
$cache_max_time = 3600;
+ }
$now = time();
@@ -2107,30 +2199,33 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
$protected_directories = wpsc_get_protected_directories();
}
- if (is_dir($directory)) {
- if( $dh = @opendir( $directory ) ) {
+ if ( is_dir( $directory ) ) {
+ if ( $dh = @opendir( $directory ) ) {
$directory = trailingslashit( $directory );
- while( ( $entry = @readdir( $dh ) ) !== false ) {
- if ($entry == '.' || $entry == '..')
+ while ( ( $entry = @readdir( $dh ) ) !== false ) {
+ if ( $entry == '.' || $entry == '..' ) {
continue;
+ }
$entry = $directory . $entry;
prune_super_cache( $entry, $force, $rename );
// If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date,
- if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
+ if ( is_dir( $entry ) && ! in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
// if the directory isn't empty can't delete it
- if( $handle = @opendir( $entry ) ) {
+ if ( $handle = @opendir( $entry ) ) {
$donotdelete = false;
- while( !$donotdelete && ( $file = @readdir( $handle ) ) !== false ) {
- if ($file == '.' || $file == '..')
+ while ( ! $donotdelete && ( $file = @readdir( $handle ) ) !== false ) {
+ if ( $file == '.' || $file == '..' ) {
continue;
+ }
$donotdelete = true;
wp_cache_debug( "gc: could not delete $entry as it's not empty: $file", 2 );
}
- closedir($handle);
+ closedir( $handle );
}
- if( $donotdelete )
+ if ( $donotdelete ) {
continue;
- if( !$rename ) {
+ }
+ if ( ! $rename ) {
@rmdir( $entry );
$log++;
if ( $force ) {
@@ -2143,19 +2238,19 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
wp_cache_debug( "gc: could not delete $entry as it's protected.", 2 );
}
}
- closedir($dh);
+ closedir( $dh );
}
- } elseif( is_file($directory) && ($force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
+ } elseif ( is_file( $directory ) && ( $force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
$oktodelete = true;
if ( in_array( $directory, $protected_directories ) ) {
wp_cache_debug( "gc: could not delete $directory as it's protected.", 2 );
$oktodelete = false;
}
- if( $oktodelete && !$rename ) {
+ if ( $oktodelete && ! $rename ) {
wp_cache_debug( "prune_super_cache: deleted $directory", 5 );
@unlink( $directory );
$log++;
- } elseif( $oktodelete && $rename ) {
+ } elseif ( $oktodelete && $rename ) {
wp_cache_debug( "prune_super_cache: wp_cache_rebuild_or_delete( $directory )", 5 );
wp_cache_rebuild_or_delete( $directory );
$log++;
@@ -2171,9 +2266,9 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
function wp_cache_rebuild_or_delete( $file ) {
global $cache_rebuild_files, $cache_path, $file_prefix;
-
- if ( strpos( $file, '?' ) !== false )
+ if ( strpos( $file, '?' ) !== false ) {
$file = substr( $file, 0, strpos( $file, '?' ) );
+ }
$file = wpsc_get_realpath( $file );
@@ -2188,7 +2283,7 @@ function wp_cache_rebuild_or_delete( $file ) {
}
$protected = wpsc_get_protected_directories();
- foreach( $protected as $id => $directory ) {
+ foreach ( $protected as $id => $directory ) {
$protected[ $id ] = wpsc_get_realpath( $directory );
}
@@ -2213,8 +2308,8 @@ function wp_cache_rebuild_or_delete( $file ) {
wp_cache_debug( "rebuild_or_gc: file has disappeared: $file" );
return false;
}
- if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
- if( @rename($file, $file . '.needs-rebuild') ) {
+ if ( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
+ if ( @rename( $file, $file . '.needs-rebuild' ) ) {
@touch( $file . '.needs-rebuild' );
wp_cache_debug( "rebuild_or_gc: rename file to {$file}.needs-rebuild", 2 );
} else {
@@ -2234,30 +2329,31 @@ function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) {
global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
clearstatcache();
- if( !wp_cache_writers_entry() )
+ if ( ! wp_cache_writers_entry() ) {
return false;
+ }
$now = time();
wp_cache_debug( "Cleaning expired cache files in $blog_cache_dir", 2 );
$deleted = 0;
if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
- while ( false !== ($file = readdir($handle))) {
- if ( preg_match("/^$file_prefix/", $file) &&
- (@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now ) {
+ while ( false !== ( $file = readdir( $handle ) ) ) {
+ if ( preg_match( "/^$file_prefix/", $file ) &&
+ ( @filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
@unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
wp_cache_debug( "wp_cache_phase2_clean_expired: Deleting obsolete wpcache cache+meta files: $file" );
continue;
}
- if($file != '.' && $file != '..') {
- if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $cache_max_time) <= $now ) {
+ if ( $file != '.' && $file != '..' ) {
+ if ( is_dir( $blog_cache_dir . $file ) == false && ( @filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
if ( substr( $file, -9 ) != '.htaccess' && $file != 'index.html' ) {
- @unlink($blog_cache_dir . $file);
+ @unlink( $blog_cache_dir . $file );
wp_cache_debug( "Deleting $blog_cache_dir{$file}, older than $cache_max_time seconds", 5 );
}
}
}
}
- closedir($handle);
+ closedir( $handle );
if ( false == $wp_cache_preload_on || true == $force ) {
wp_cache_debug( "Doing GC on supercache dir: {$cache_path}supercache", 2 );
$deleted = prune_super_cache( $cache_path . 'supercache', false, false );
@@ -2280,48 +2376,48 @@ function wp_cache_shutdown_callback() {
* ref: https://wordpress.org/support/topic/fatal-error-while-updating-post-or-publishing-new-one/
*/
$wpsc_feed_ttl = 1;
- wp_cache_debug( "wp_cache_shutdown_callback: Plugin not loaded. Setting feed ttl to 60 seconds." );
+ wp_cache_debug( 'wp_cache_shutdown_callback: Plugin not loaded. Setting feed ttl to 60 seconds.' );
}
-
if ( false == $new_cache ) {
- wp_cache_debug( "wp_cache_shutdown_callback: No cache file created. Returning." );
+ wp_cache_debug( 'wp_cache_shutdown_callback: No cache file created. Returning.' );
return false;
}
- $wp_cache_meta[ 'uri' ] = $WPSC_HTTP_HOST . preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $wp_cache_request_uri); // To avoid XSS attacks
- $wp_cache_meta[ 'blog_id' ] = $blog_id;
- $wp_cache_meta[ 'post' ] = wp_cache_post_id();
- $wp_cache_meta[ 'key' ] = $wp_cache_key;
- $wp_cache_meta = apply_filters( 'wp_cache_meta', $wp_cache_meta );
+ $wp_cache_meta['uri'] = $WPSC_HTTP_HOST . preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $wp_cache_request_uri ); // To avoid XSS attacks
+ $wp_cache_meta['blog_id'] = $blog_id;
+ $wp_cache_meta['post'] = wp_cache_post_id();
+ $wp_cache_meta['key'] = $wp_cache_key;
+ $wp_cache_meta = apply_filters( 'wp_cache_meta', $wp_cache_meta );
$response = wp_cache_get_response_headers();
- foreach( $response as $key => $value ) {
- $wp_cache_meta[ 'headers' ][ $key ] = "$key: $value";
+ foreach ( $response as $key => $value ) {
+ $wp_cache_meta['headers'][ $key ] = "$key: $value";
}
- wp_cache_debug( "wp_cache_shutdown_callback: collecting meta data.", 2 );
+ wp_cache_debug( 'wp_cache_shutdown_callback: collecting meta data.', 2 );
- if (!isset( $response['Last-Modified'] )) {
- $value = gmdate('D, d M Y H:i:s') . ' GMT';
- /* Dont send this the first time */
+ if ( ! isset( $response['Last-Modified'] ) ) {
+ $value = gmdate( 'D, d M Y H:i:s' ) . ' GMT';
+ /*
+ Dont send this the first time */
/* @header('Last-Modified: ' . $value); */
- $wp_cache_meta[ 'headers' ][ 'Last-Modified' ] = "Last-Modified: $value";
+ $wp_cache_meta['headers']['Last-Modified'] = "Last-Modified: $value";
}
$is_feed = false;
- if ( !isset( $response[ 'Content-Type' ] ) && !isset( $response[ 'Content-type' ] ) ) {
+ if ( ! isset( $response['Content-Type'] ) && ! isset( $response['Content-type'] ) ) {
// On some systems, headers set by PHP can't be fetched from
// the output buffer. This is a last ditch effort to set the
// correct Content-Type header for feeds, if we didn't see
// it in the response headers already. -- dougal
- if ( isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
- if ( isset( $wp_super_cache_query[ 'is_sitemap' ] ) ) {
+ if ( isset( $wp_super_cache_query['is_feed'] ) ) {
+ if ( isset( $wp_super_cache_query['is_sitemap'] ) ) {
$type = 'sitemap';
$value = 'text/xml';
} else {
$type = get_query_var( 'feed' );
- $type = str_replace('/','',$type);
- switch ($type) {
+ $type = str_replace( '/', '', $type );
+ switch ( $type ) {
case 'atom':
$value = 'application/atom+xml';
break;
@@ -2337,48 +2433,50 @@ function wp_cache_shutdown_callback() {
$is_feed = true;
if ( isset( $wpsc_feed_ttl ) && $wpsc_feed_ttl == 1 ) {
- $wp_cache_meta[ 'ttl' ] = 60;
+ $wp_cache_meta['ttl'] = 60;
}
$is_feed = true;
wp_cache_debug( "wp_cache_shutdown_callback: feed is type: $type - $value" );
- } elseif ( isset( $wp_super_cache_query[ 'is_rest' ] ) ) { // json
+ } elseif ( isset( $wp_super_cache_query['is_rest'] ) ) { // json
$value = 'application/json';
} else { // not a feed
$value = get_option( 'html_type' );
- if( $value == '' )
+ if ( $value == '' ) {
$value = 'text/html';
+ }
}
- $value .= "; charset=\"" . $wp_cache_blog_charset . "\"";
+ $value .= '; charset="' . $wp_cache_blog_charset . '"';
wp_cache_debug( "Sending 'Content-Type: $value' header.", 2 );
- @header("Content-Type: $value");
- $wp_cache_meta[ 'headers' ][ 'Content-Type' ] = "Content-Type: $value";
+ @header( "Content-Type: $value" );
+ $wp_cache_meta['headers']['Content-Type'] = "Content-Type: $value";
}
- if ( $cache_enabled && !$supercacheonly && $new_cache ) {
- if( !isset( $wp_cache_meta[ 'dynamic' ] ) && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta[ 'headers' ] ) ) {
- wp_cache_debug( "Sending gzip headers.", 2 );
- $wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
- $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie';
+ if ( $cache_enabled && ! $supercacheonly && $new_cache ) {
+ if ( ! isset( $wp_cache_meta['dynamic'] ) && $wp_cache_gzip_encoding && ! in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta['headers'] ) ) {
+ wp_cache_debug( 'Sending gzip headers.', 2 );
+ $wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
+ $wp_cache_meta['headers']['Vary'] = 'Vary: Accept-Encoding, Cookie';
}
$serial = '' . json_encode( $wp_cache_meta );
- $dir = get_current_url_supercache_dir();
- if( @is_dir( $dir ) == false )
+ $dir = get_current_url_supercache_dir();
+ if ( @is_dir( $dir ) == false ) {
@wp_mkdir_p( $dir );
+ }
- if( wp_cache_writers_entry() ) {
+ if ( wp_cache_writers_entry() ) {
wp_cache_debug( "Writing meta file: {$dir}meta-{$meta_file}", 2 );
if ( false == $wp_cache_object_cache ) {
- $tmp_meta_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
- $final_meta_filename = $dir . "meta-" . $meta_file;
- $fr = @fopen( $tmp_meta_filename, 'w');
+ $tmp_meta_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
+ $final_meta_filename = $dir . 'meta-' . $meta_file;
+ $fr = @fopen( $tmp_meta_filename, 'w' );
if ( $fr ) {
- fputs($fr, $serial);
- fclose($fr);
- @chmod( $tmp_meta_filename, 0666 & ~umask());
- if( !@rename( $tmp_meta_filename, $final_meta_filename ) ) {
+ fputs( $fr, $serial );
+ fclose( $fr );
+ @chmod( $tmp_meta_filename, 0666 & ~umask() );
+ if ( ! @rename( $tmp_meta_filename, $final_meta_filename ) ) {
@unlink( $dir . $final_meta_filename );
@rename( $tmp_meta_filename, $final_meta_filename );
}
@@ -2386,16 +2484,17 @@ function wp_cache_shutdown_callback() {
wp_cache_debug( "Problem writing meta file: {$final_meta_filename}" );
}
} elseif ( $cache_enabled ) {
- $oc_key = get_oc_key() . ".meta";
- if ( gzip_accepted() )
- $oc_key .= ".gz";
+ $oc_key = get_oc_key() . '.meta';
+ if ( gzip_accepted() ) {
+ $oc_key .= '.gz';
+ }
wp_cache_set( $oc_key, $serial, 'supercache', $cache_max_time );
}
wp_cache_writers_exit();
// record locations of archive feeds to be updated when the site is updated.
// Only record a maximum of 50 feeds to avoid bloating database.
- if ( ( isset( $wp_super_cache_query[ 'is_feed' ] ) || $is_feed ) && ! isset( $wp_super_cache_query[ 'is_single' ] ) ) {
+ if ( ( isset( $wp_super_cache_query['is_feed'] ) || $is_feed ) && ! isset( $wp_super_cache_query['is_single'] ) ) {
$wpsc_feed_list = (array) get_option( 'wpsc_feed_list' );
if ( count( $wpsc_feed_list ) <= 50 ) {
$wpsc_feed_list[] = $dir . $meta_file;
@@ -2407,14 +2506,14 @@ function wp_cache_shutdown_callback() {
wp_cache_debug( "Did not write meta file: meta-{$meta_file} *$supercacheonly* *$wp_cache_not_logged_in* *$new_cache*", 2 );
}
global $time_to_gc_cache;
- if( isset( $time_to_gc_cache ) && $time_to_gc_cache == 1 ) {
- wp_cache_debug( "Executing wp_cache_gc action.", 3 );
+ if ( isset( $time_to_gc_cache ) && $time_to_gc_cache == 1 ) {
+ wp_cache_debug( 'Executing wp_cache_gc action.', 3 );
do_action( 'wp_cache_gc' );
}
}
-function wp_cache_no_postid($id) {
- return wp_cache_post_change(wp_cache_post_id());
+function wp_cache_no_postid( $id ) {
+ return wp_cache_post_change( wp_cache_post_id() );
}
function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
@@ -2425,7 +2524,7 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
}
// Check is it "Empty Spam" or "Empty Trash"
- if ( isset( $GLOBALS[ 'pagenow' ] ) && $GLOBALS[ 'pagenow' ] === 'edit-comments.php' &&
+ if ( isset( $GLOBALS['pagenow'] ) && $GLOBALS['pagenow'] === 'edit-comments.php' &&
( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
) {
wp_cache_debug( "Delete all SPAM or Trash comments. Don't delete any cache files.", 4 );
@@ -2433,23 +2532,23 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
return;
}
- $comment = get_comment($comment_id, ARRAY_A);
+ $comment = get_comment( $comment_id, ARRAY_A );
if ( $status != 'NA' ) {
- $comment[ 'old_comment_approved' ] = $comment[ 'comment_approved' ];
- $comment[ 'comment_approved' ] = $status;
+ $comment['old_comment_approved'] = $comment['comment_approved'];
+ $comment['comment_approved'] = $status;
}
- if ( ( $status == 'trash' || $status == 'spam' ) && $comment[ 'old_comment_approved' ] != 1 ) {
+ if ( ( $status == 'trash' || $status == 'spam' ) && $comment['old_comment_approved'] != 1 ) {
// don't modify cache if moderated comments are trashed or spammed
wp_cache_debug( "Moderated comment deleted or spammed. Don't delete any cache files.", 4 );
define( 'DONOTDELETECACHE', 1 );
return wp_cache_post_id();
}
- $postid = isset( $comment[ 'comment_post_ID' ] ) ? (int) $comment[ 'comment_post_ID' ] : 0;
+ $postid = isset( $comment['comment_post_ID'] ) ? (int) $comment['comment_post_ID'] : 0;
// Do nothing if comment is not moderated
// http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
- if ( !preg_match('/wp-admin\//', $wp_cache_request_uri) ) {
- if ( $comment['comment_approved'] == 'delete' && ( isset( $comment[ 'old_comment_approved' ] ) && $comment[ 'old_comment_approved' ] == 0 ) ) { // do nothing if moderated comments are deleted
+ if ( ! preg_match( '/wp-admin\//', $wp_cache_request_uri ) ) {
+ if ( $comment['comment_approved'] == 'delete' && ( isset( $comment['old_comment_approved'] ) && $comment['old_comment_approved'] == 0 ) ) { // do nothing if moderated comments are deleted
wp_cache_debug( "Moderated comment deleted. Don't delete any cache files.", 4 );
define( 'DONOTDELETECACHE', 1 );
return $postid;
@@ -2457,13 +2556,13 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
wp_cache_debug( "Spam comment. Don't delete any cache files.", 4 );
define( 'DONOTDELETECACHE', 1 );
return $postid;
- } elseif( $comment['comment_approved'] == '0' ) {
- if ( $comment[ 'comment_type' ] == '' ) {
+ } elseif ( $comment['comment_approved'] == '0' ) {
+ if ( $comment['comment_type'] == '' ) {
wp_cache_debug( "Moderated comment. Don't delete supercache file until comment approved.", 4 );
$super_cache_enabled = 0; // don't remove the super cache static file until comment is approved
define( 'DONOTDELETECACHE', 1 );
} else {
- wp_cache_debug( "Moderated ping or trackback. Not deleting cache files..", 4 );
+ wp_cache_debug( 'Moderated ping or trackback. Not deleting cache files..', 4 );
define( 'DONOTDELETECACHE', 1 );
return $postid;
}
@@ -2472,11 +2571,11 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
// We must check it up again due to WP bugs calling two different actions
// for delete, for example both wp_set_comment_status and delete_comment
// are called when deleting a comment
- if ($postid > 0) {
+ if ( $postid > 0 ) {
wp_cache_debug( "Post $postid changed. Update cache.", 4 );
return wp_cache_post_change( $postid );
} else {
- wp_cache_debug( "Unknown post changed. Update cache.", 4 );
+ wp_cache_debug( 'Unknown post changed. Update cache.', 4 );
return wp_cache_post_change( wp_cache_post_id() );
}
}
@@ -2494,7 +2593,7 @@ function wp_cache_clear_cache( $blog_id = 0 ) {
reset_oc_version();
} else {
if ( $blog_id == 0 ) {
- wp_cache_debug( "Clearing all cached files in wp_cache_clear_cache()", 4 );
+ wp_cache_debug( 'Clearing all cached files in wp_cache_clear_cache()', 4 );
prune_super_cache( $cache_path . 'supercache/', true );
prune_super_cache( $cache_path, true );
} else {
@@ -2512,7 +2611,7 @@ function wpsc_delete_post_archives( $post ) {
}
// Taxonomies - categories, tags, custom taxonomies
- foreach( get_object_taxonomies( $post, 'objects' ) as $taxonomy ) {
+ foreach ( get_object_taxonomies( $post, 'objects' ) as $taxonomy ) {
if ( ! $taxonomy->public || ! $taxonomy->rewrite ) {
continue;
@@ -2523,7 +2622,7 @@ function wpsc_delete_post_archives( $post ) {
continue;
}
- foreach( $terms as $term ) {
+ foreach ( $terms as $term ) {
$term_url = get_term_link( $term, $taxonomy->name );
if ( is_wp_error( $term_url ) ) {
@@ -2531,7 +2630,7 @@ function wpsc_delete_post_archives( $post ) {
}
wpsc_delete_url_cache( $term_url );
- wp_cache_debug( "wpsc_delete_post_archives: deleting cache of taxonomies: " . $term_url );
+ wp_cache_debug( 'wpsc_delete_post_archives: deleting cache of taxonomies: ' . $term_url );
}
}
@@ -2546,59 +2645,61 @@ function wpsc_delete_post_archives( $post ) {
if ( $archive_url ) {
wpsc_delete_url_cache( $archive_url );
- wp_cache_debug( "wpsc_delete_post_archives: deleting cache of post type archive: " . $archive_url );
+ wp_cache_debug( 'wpsc_delete_post_archives: deleting cache of post type archive: ' . $archive_url );
}
// Author archive page
$author_url = get_author_posts_url( $post->post_author );
if ( $author_url ) {
wpsc_delete_url_cache( $author_url );
- wp_cache_debug( "wpsc_delete_post_archives: deleting cache of author archive: " . $author_url );
+ wp_cache_debug( 'wpsc_delete_post_archives: deleting cache of author archive: ' . $author_url );
}
}
function wpsc_delete_cats_tags( $post ) {
- $post = get_post($post);
- $categories = get_the_category($post->ID);
+ $post = get_post( $post );
+ $categories = get_the_category( $post->ID );
if ( $categories ) {
- $category_base = get_option( 'category_base');
- if ( $category_base == '' )
+ $category_base = get_option( 'category_base' );
+ if ( $category_base == '' ) {
$category_base = '/category/';
+ }
$category_base = trailingslashit( $category_base ); // paranoid much?
- foreach ($categories as $cat) {
- prune_super_cache ( get_supercache_dir() . $category_base . $cat->slug . '/', true );
- wp_cache_debug( "wpsc_post_transition: deleting category: " . get_supercache_dir() . $category_base . $cat->slug . '/' );
+ foreach ( $categories as $cat ) {
+ prune_super_cache( get_supercache_dir() . $category_base . $cat->slug . '/', true );
+ wp_cache_debug( 'wpsc_post_transition: deleting category: ' . get_supercache_dir() . $category_base . $cat->slug . '/' );
}
}
- $posttags = get_the_tags($post->ID);
+ $posttags = get_the_tags( $post->ID );
if ( $posttags ) {
$tag_base = get_option( 'tag_base' );
- if ( $tag_base == '' )
+ if ( $tag_base == '' ) {
$tag_base = '/tag/';
+ }
$tag_base = trailingslashit( str_replace( '..', '', $tag_base ) ); // maybe!
- foreach ($posttags as $tag) {
+ foreach ( $posttags as $tag ) {
prune_super_cache( get_supercache_dir() . $tag_base . $tag->slug . '/', true );
- wp_cache_debug( "wpsc_post_transition: deleting tag: " . get_supercache_dir() . $tag_base . $tag->slug . '/' );
+ wp_cache_debug( 'wpsc_post_transition: deleting tag: ' . get_supercache_dir() . $tag_base . $tag->slug . '/' );
}
}
}
function wpsc_post_transition( $new_status, $old_status, $post ) {
if (
- ($old_status == 'publish' && $new_status != 'publish' ) // post unpublished
+ ( $old_status == 'publish' && $new_status != 'publish' ) // post unpublished
||
- ($old_status != 'publish' && $new_status == 'publish') // post published
+ ( $old_status != 'publish' && $new_status == 'publish' ) // post published
) {
- //wpsc_delete_cats_tags( $post );
+ // wpsc_delete_cats_tags( $post );
wpsc_delete_post_archives( $post );
$post_url = get_permalink( $post->ID );
wpsc_delete_url_cache( $post_url );
- wp_cache_debug( "wpsc_post_transition: deleting cache of post: " . $post_url );
+ wp_cache_debug( 'wpsc_post_transition: deleting cache of post: ' . $post_url );
}
}
/* check if we want to clear out all cached files on post updates, otherwise call standard wp_cache_post_change() */
-function wp_cache_post_edit($post_id) {
+function wp_cache_post_edit( $post_id ) {
global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir, $wp_cache_object_cache;
static $last_post_edited = -1;
@@ -2608,19 +2709,20 @@ function wp_cache_post_edit($post_id) {
}
$post = get_post( $post_id );
- if ( is_object( $post ) == false )
+ if ( is_object( $post ) == false ) {
return $post_id;
+ }
// Some users are inexplicibly seeing this error on scheduled posts.
// define this constant to disable the post status check.
- if ( false == defined( 'WPSCFORCEUPDATE' ) && !in_array($post->post_status, array( 'publish', 'private' ) ) ) {
- wp_cache_debug( "wp_cache_post_edit: draft post, not deleting any cache files. status: " . $post->post_status, 4 );
+ if ( false == defined( 'WPSCFORCEUPDATE' ) && ! in_array( $post->post_status, array( 'publish', 'private' ) ) ) {
+ wp_cache_debug( 'wp_cache_post_edit: draft post, not deleting any cache files. status: ' . $post->post_status, 4 );
return $post_id;
}
// we want to process the post again just in case it becomes published before the second time this function is called.
$last_post_edited = $post_id;
- if( $wp_cache_clear_on_post_edit ) {
+ if ( $wp_cache_clear_on_post_edit ) {
wp_cache_debug( "wp_cache_post_edit: Clearing cache $blog_cache_dir and {$cache_path}supercache/ on post edit per config.", 2 );
if ( $wp_cache_object_cache ) {
reset_oc_version();
@@ -2637,12 +2739,14 @@ function wp_cache_post_edit($post_id) {
function wp_cache_post_id_gc( $post_id, $all = 'all' ) {
global $wp_cache_object_cache;
- if ( $wp_cache_object_cache )
+ if ( $wp_cache_object_cache ) {
reset_oc_version();
+ }
$post_id = intval( $post_id );
- if( $post_id == 0 )
+ if ( $post_id == 0 ) {
return true;
+ }
$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
if ( false !== strpos( $permalink, '?' ) ) {
@@ -2678,21 +2782,22 @@ function wp_cache_post_change( $post_id ) {
$post = get_post( $post_id );
// Some users are inexplicibly seeing this error on scheduled posts.
// define this constant to disable the post status check.
- if ( false == defined( 'WPSCFORCEUPDATE' ) && is_object( $post ) && !in_array($post->post_status, array( 'publish', 'private' ) ) ) {
- wp_cache_debug( "wp_cache_post_change: draft post, not deleting any cache files.", 4 );
+ if ( false == defined( 'WPSCFORCEUPDATE' ) && is_object( $post ) && ! in_array( $post->post_status, array( 'publish', 'private' ) ) ) {
+ wp_cache_debug( 'wp_cache_post_change: draft post, not deleting any cache files.', 4 );
return $post_id;
}
$last_processed = $post_id;
- if( !wp_cache_writers_entry() )
+ if ( ! wp_cache_writers_entry() ) {
return $post_id;
+ }
- if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only && ( strpos( $_SERVER[ 'HTTP_REFERER' ], 'edit-comments.php' ) || strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) ) {
+ if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only && ( strpos( $_SERVER['HTTP_REFERER'], 'edit-comments.php' ) || strpos( $_SERVER['REQUEST_URI'], 'wp-comments-post.php' ) ) ) {
if ( defined( 'DONOTDELETECACHE' ) ) {
wp_cache_debug( "wp_cache_post_change: comment detected and it's moderated or spam. Not deleting cached files.", 4 );
return $post_id;
} else {
- wp_cache_debug( "wp_cache_post_change: comment detected. only deleting post page.", 4 );
+ wp_cache_debug( 'wp_cache_post_change: comment detected. only deleting post page.', 4 );
$all = false;
}
} else {
@@ -2700,51 +2805,53 @@ function wp_cache_post_change( $post_id ) {
}
$all_backup = $all;
- $all = apply_filters( 'wpsc_delete_related_pages_on_edit', $all ); // return 0 to disable deleting homepage and other pages.
- if ( $all != $all_backup )
+ $all = apply_filters( 'wpsc_delete_related_pages_on_edit', $all ); // return 0 to disable deleting homepage and other pages.
+ if ( $all != $all_backup ) {
wp_cache_debug( 'wp_cache_post_change: $all changed by wpsc_delete_related_pages_on_edit filter: ' . intval( $all ) );
+ }
- if ( $wp_cache_object_cache )
+ if ( $wp_cache_object_cache ) {
reset_oc_version();
+ }
// Delete supercache files whenever a post change event occurs, even if supercache is currently disabled.
$dir = get_supercache_dir();
// make sure the front page has a rebuild file
if ( false == wp_cache_post_id_gc( $post_id, $all ) ) {
- wp_cache_debug( "wp_cache_post_change: not deleting any cache files as GC of post returned false" );
+ wp_cache_debug( 'wp_cache_post_change: not deleting any cache files as GC of post returned false' );
wp_cache_writers_exit();
return false;
}
if ( $all == true ) {
- wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $dir );
+ wp_cache_debug( 'Post change: supercache enabled: deleting cache files in ' . $dir );
wpsc_rebuild_files( $dir );
do_action( 'gc_cache', 'prune', 'homepage' );
if ( get_option( 'show_on_front' ) == 'page' ) {
- wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 );
- wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 );
+ wp_cache_debug( 'Post change: deleting page_on_front and page_for_posts pages.', 4 );
+ wp_cache_debug( 'Post change: page_on_front ' . get_option( 'page_on_front' ), 4 );
$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( get_option( 'page_for_posts' ) ) ) );
- wp_cache_debug( "Post change: Deleting files in: " . str_replace( '//', '/', $dir . $permalink ) );
+ wp_cache_debug( 'Post change: Deleting files in: ' . str_replace( '//', '/', $dir . $permalink ) );
wpsc_rebuild_files( $dir . $permalink );
do_action( 'gc_cache', 'prune', $permalink );
}
} else {
- wp_cache_debug( "wp_cache_post_change: not deleting all pages.", 4 );
+ wp_cache_debug( 'wp_cache_post_change: not deleting all pages.', 4 );
}
wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 );
$supercache_files_deleted = false;
if ( $handle = @opendir( $blog_cache_dir ) ) {
- while ( false !== ($file = readdir($handle))) {
+ while ( false !== ( $file = readdir( $handle ) ) ) {
if ( strpos( $file, $file_prefix ) !== false ) {
if ( strpos( $file, '.html' ) ) {
// delete old wpcache files immediately
wp_cache_debug( "wp_cache_post_change: Deleting obsolete wpcache cache+meta files: $file" );
- @unlink( $blog_cache_dir . $file);
+ @unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
continue;
} else {
$meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
- if( false == is_array( $meta ) ) {
+ if ( false == is_array( $meta ) ) {
wp_cache_debug( "Post change cleaning up stray file: $file", 4 );
@unlink( $blog_cache_dir . 'meta/' . $file );
@unlink( $blog_cache_dir . $file );
@@ -2752,7 +2859,7 @@ function wp_cache_post_change( $post_id ) {
}
if ( $post_id > 0 && $meta ) {
$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
- if ( $meta[ 'blog_id' ] == $blog_id && ( ( $all == true && !$meta[ 'post' ] ) || $meta[ 'post' ] == $post_id) ) {
+ if ( $meta['blog_id'] == $blog_id && ( ( $all == true && ! $meta['post'] ) || $meta['post'] == $post_id ) ) {
wp_cache_debug( "Post change: deleting post wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
@unlink( $blog_cache_dir . 'meta/' . $file );
@unlink( $blog_cache_dir . $file );
@@ -2763,39 +2870,49 @@ function wp_cache_post_change( $post_id ) {
do_action( 'gc_cache', 'rebuild', $permalink );
}
}
- } elseif ( $meta[ 'blog_id' ] == $blog_id ) {
+ } elseif ( $meta['blog_id'] == $blog_id ) {
wp_cache_debug( "Post change: deleting wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
@unlink( $blog_cache_dir . 'meta/' . $file );
@unlink( $blog_cache_dir . $file );
if ( $super_cache_enabled == true ) {
wp_cache_debug( "Post change: deleting supercache files for {$meta[ 'uri' ]}" );
- wpsc_rebuild_files( $dir . $meta[ 'uri' ] );
- do_action( 'gc_cache', 'rebuild', trailingslashit( $meta[ 'uri' ] ) );
+ wpsc_rebuild_files( $dir . $meta['uri'] );
+ do_action( 'gc_cache', 'rebuild', trailingslashit( $meta['uri'] ) );
}
}
}
}
}
- closedir($handle);
+ closedir( $handle );
}
wp_cache_writers_exit();
return $post_id;
}
-function wp_cache_microtime_diff($a, $b) {
- list($a_dec, $a_sec) = explode(' ', $a);
- list($b_dec, $b_sec) = explode(' ', $b);
- return (float)$b_sec - (float)$a_sec + (float)$b_dec - (float)$a_dec;
+function wp_cache_microtime_diff( $a, $b ) {
+ list($a_dec, $a_sec) = explode( ' ', $a );
+ list($b_dec, $b_sec) = explode( ' ', $b );
+ return (float) $b_sec - (float) $a_sec + (float) $b_dec - (float) $a_dec;
}
function wp_cache_post_id() {
global $posts, $comment_post_ID, $post_ID;
// We try hard all options. More frequent first.
- if ($post_ID > 0 ) return $post_ID;
- if ($comment_post_ID > 0 ) return $comment_post_ID;
- if (is_singular() && !empty($posts)) return $posts[0]->ID;
- if (isset( $_GET[ 'p' ] ) && $_GET['p'] > 0) return $_GET['p'];
- if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p'];
+ if ( $post_ID > 0 ) {
+ return $post_ID;
+ }
+ if ( $comment_post_ID > 0 ) {
+ return $comment_post_ID;
+ }
+ if ( is_singular() && ! empty( $posts ) ) {
+ return $posts[0]->ID;
+ }
+ if ( isset( $_GET['p'] ) && $_GET['p'] > 0 ) {
+ return $_GET['p'];
+ }
+ if ( isset( $_POST['p'] ) && $_POST['p'] > 0 ) {
+ return $_POST['p'];
+ }
return 0;
}
@@ -2817,7 +2934,7 @@ function maybe_stop_gc( $flag ) {
}
function get_gc_flag() {
global $cache_path;
- return $cache_path . strtolower( preg_replace( '!/:.*$!', '', str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'home' ) ) ) ) ) . "_wp_cache_gc.txt";
+ return $cache_path . strtolower( preg_replace( '!/:.*$!', '', str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'home' ) ) ) ) ) . '_wp_cache_gc.txt';
}
function wp_cache_gc_cron() {
@@ -2842,26 +2959,28 @@ function wp_cache_gc_cron() {
wp_cache_debug( 'Cache garbage collection.', 5 );
- if( !isset( $cache_max_time ) )
+ if ( ! isset( $cache_max_time ) ) {
$cache_max_time = 600;
+ }
$start = time();
- $num = 0;
- if( false === ( $num = wp_cache_phase2_clean_expired( $file_prefix ) ) ) {
+ $num = 0;
+ if ( false === ( $num = wp_cache_phase2_clean_expired( $file_prefix ) ) ) {
wp_cache_debug( 'Cache Expiry cron job failed. Probably mutex locked.', 1 );
update_option( 'wpsupercache_gc_time', time() - ( $cache_time_interval - 10 ) ); // if GC failed then run it again in one minute
$msg .= __( 'Cache expiry cron job failed. Job will run again in 10 seconds.', 'wp-super-cache' ) . "\n";
}
- if( time() - $start > 30 ) {
+ if ( time() - $start > 30 ) {
wp_cache_debug( "Cache Expiry cron job took more than 30 seconds to execute.\nYou should reduce the Expiry Time in the WP Super Cache admin page\nas you probably have more cache files than your server can handle efficiently.", 1 );
$msg .= __( 'Cache expiry cron job took more than 30 seconds. You should probably run the garbage collector more often.', 'wp-super-cache' ) . "\n";
}
if ( $cache_gc_email_me ) {
- if ( $msg != '' )
+ if ( $msg != '' ) {
$msg = "The following warnings were generated by the WP Super Cache Garbage Collector:\n" . $msg;
+ }
- $msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int)$num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector.";
+ $msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int) $num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector.";
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] WP Super Cache GC Report', 'wp-super-cache' ), home_url() ), $msg );
}
@@ -2873,28 +2992,31 @@ function wp_cache_gc_cron() {
function schedule_wp_gc( $forced = 0 ) {
global $cache_schedule_type, $cache_max_time, $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval;
- if ( false == isset( $cache_time_interval ) )
+ if ( false == isset( $cache_time_interval ) ) {
$cache_time_interval = 3600;
+ }
if ( false == isset( $cache_schedule_type ) ) {
- $cache_schedule_type = 'interval';
+ $cache_schedule_type = 'interval';
$cache_schedule_interval = $cache_max_time;
}
if ( $cache_schedule_type == 'interval' ) {
- if ( !isset( $cache_max_time ) )
+ if ( ! isset( $cache_max_time ) ) {
$cache_max_time = 600;
- if ( $cache_max_time == 0 )
+ }
+ if ( $cache_max_time == 0 ) {
return false;
- $last_gc = get_option( "wpsupercache_gc_time" );
+ }
+ $last_gc = get_option( 'wpsupercache_gc_time' );
- if ( !$last_gc ) {
+ if ( ! $last_gc ) {
update_option( 'wpsupercache_gc_time', time() );
- $last_gc = get_option( "wpsupercache_gc_time" );
+ $last_gc = get_option( 'wpsupercache_gc_time' );
}
if ( $forced || ( $last_gc < ( time() - 60 ) ) ) { // Allow up to 60 seconds for the previous job to run
global $wp_cache_shutdown_gc;
- if ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) {
- if ( !($t = wp_next_scheduled( 'wp_cache_gc' ) ) ) {
+ if ( ! isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) {
+ if ( ! ( $t = wp_next_scheduled( 'wp_cache_gc' ) ) ) {
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' );
wp_cache_debug( 'scheduled wp_cache_gc for 10 seconds time.', 5 );
@@ -2904,7 +3026,7 @@ function schedule_wp_gc( $forced = 0 ) {
$time_to_gc_cache = 1; // tell the "shutdown gc" to run!
}
}
- } elseif ( $cache_schedule_type == 'time' && !wp_next_scheduled( 'wp_cache_gc' ) ) {
+ } elseif ( $cache_schedule_type == 'time' && ! wp_next_scheduled( 'wp_cache_gc' ) ) {
wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' );
}
return true;
@@ -2916,5 +3038,3 @@ function wp_cache_gc_watcher() {
schedule_wp_gc();
}
}
-
-?>
From 6ab5582cd9c956b7434c759f042fa2e79b9466d9 Mon Sep 17 00:00:00 2001
From: robjarsen <29106074+robjarsen@users.noreply.github.com>
Date: Wed, 13 Dec 2017 15:57:55 -0500
Subject: [PATCH 2/2] Update wp-cache-phase2.php
---
wp-cache-phase2.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php
index 8cbb88e2..9f661ea4 100644
--- a/wp-cache-phase2.php
+++ b/wp-cache-phase2.php
@@ -973,7 +973,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
$checks = array( "wp-admin", "exclude_filter", "wp-content", "wp-json" );
foreach( $checks as $check ) {
- if ( isset( $_GET[$check] ) ) {
+ if ( isset( $_GET[ $check ] ) ) {
$$check = 1;
} else {
$$check = 0;
@@ -1656,7 +1656,7 @@ function wp_cache_ob_callback( $buffer ) {
wp_cache_debug( 'URI rejected. Not Caching', 2 );
$cache_this_page = false;
} elseif ( wp_cache_user_agent_is_rejected() ) {
- wp_cache_debug( "USER AGENT ({$_SERVER[ 'HTTP_USER_AGENT' ]}) rejected. Not Caching", 4 );
+ wp_cache_debug( "USER AGENT ({$_SERVER['HTTP_USER_AGENT']}) rejected. Not Caching", 4 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages['single'] ) && $wp_cache_pages['single'] == 1 && isset( $wp_super_cache_query['is_single'] ) ) {
wp_cache_debug( 'Not caching single post.', 2 );
@@ -2860,7 +2860,7 @@ function wp_cache_post_change( $post_id ) {
if ( $post_id > 0 && $meta ) {
$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
if ( $meta['blog_id'] == $blog_id && ( ( $all == true && ! $meta['post'] ) || $meta['post'] == $post_id ) ) {
- wp_cache_debug( "Post change: deleting post wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
+ wp_cache_debug( "Post change: deleting post wp-cache files for {$meta['uri']}: $file", 4 );
@unlink( $blog_cache_dir . 'meta/' . $file );
@unlink( $blog_cache_dir . $file );
if ( false == $supercache_files_deleted && $super_cache_enabled == true ) {
@@ -2871,11 +2871,11 @@ function wp_cache_post_change( $post_id ) {
}
}
} elseif ( $meta['blog_id'] == $blog_id ) {
- wp_cache_debug( "Post change: deleting wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
+ wp_cache_debug( "Post change: deleting wp-cache files for {$meta['uri']}: $file", 4 );
@unlink( $blog_cache_dir . 'meta/' . $file );
@unlink( $blog_cache_dir . $file );
if ( $super_cache_enabled == true ) {
- wp_cache_debug( "Post change: deleting supercache files for {$meta[ 'uri' ]}" );
+ wp_cache_debug( "Post change: deleting supercache files for {$meta['uri']}" );
wpsc_rebuild_files( $dir . $meta['uri'] );
do_action( 'gc_cache', 'rebuild', trailingslashit( $meta['uri'] ) );
}