From d679dc8bd8bc0948dbf2e9b20fa49f3c865af43c Mon Sep 17 00:00:00 2001 From: stodorovic Date: Tue, 14 Aug 2018 12:56:16 +0200 Subject: [PATCH 1/4] Postponed blog detection on WP >= 4.6 --- wp-cache-base.php | 12 ++++++++++-- wp-cache-phase1.php | 10 +++++++++- wp-cache-phase2.php | 6 ++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/wp-cache-base.php b/wp-cache-base.php index 88a3c20c..4c85a8aa 100644 --- a/wp-cache-base.php +++ b/wp-cache-base.php @@ -8,9 +8,16 @@ // We want to be able to identify each blog in a WordPress MU install $blogcacheid = ''; -if ( ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) { +if ( is_multisite() ) { + global $current_blog; + $blogcacheid = 'blog'; // main blog - if ( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == true ) { + if ( is_object( $current_blog ) && function_exists( 'is_subdomain_install' ) ) { + $blogcacheid = is_subdomain_install() ? $current_blog->domain : trim( $current_blog->path, '/' ); + if ( empty( $blogcacheid ) ) { + $blogcacheid = 'blog'; + } + } elseif ( ( defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST == 'yes' ) ) { $blogcacheid = $WPSC_HTTP_HOST; } else { if ( isset( $base ) == false ) { @@ -32,4 +39,5 @@ } $blogcacheid = str_replace( '/', '', $blogcacheid ); } + $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' ); } diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index 3a3e047f..82457e4d 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -125,6 +125,14 @@ return true; } -if ( ! isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) { +// WordPress 4.6 introduces action ms_loaded. +if ( is_multisite() && + empty( $wp_super_cache_late_init ) && + version_compare( $wp_version, '4.6', '>=' ) && + function_exists( 'add_action' ) +) { + add_action( 'ms_loaded', 'wp_cache_serve_cache_file' ); +} +elseif ( ! isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) { wp_cache_serve_cache_file(); } diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index d81011bd..a11a4dc0 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -46,6 +46,12 @@ function wp_cache_serve_cache_file() { global $key, $blogcacheid, $wp_cache_request_uri, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta; global $wp_cache_object_cache, $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_home_path, $wp_cache_no_cache_for_get; global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header; + global $current_blog; + + // Fixes $blogcacheid and $blog_cache_dir if ms-settings.php is loaded. + if ( is_multisite() && is_object( $current_blog ) ) { + require WPCACHEHOME . 'wp-cache-base.php'; + } if ( wpsc_is_backend() ) { wp_cache_debug( 'Not serving wp-admin requests.', 5 ); From 26b40745b5449500707b3600a9e2ab05f6f3db17 Mon Sep 17 00:00:00 2001 From: stodorovic Date: Thu, 16 Aug 2018 09:44:27 +0200 Subject: [PATCH 2/4] Removes deprecated multisite code and perfomance optimization --- plugins/multisite.php | 2 +- wp-cache-phase1.php | 11 +++++------ wp-cache.php | 9 ++++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/multisite.php b/plugins/multisite.php index 6306a160..df71f9ac 100644 --- a/plugins/multisite.php +++ b/plugins/multisite.php @@ -1,6 +1,6 @@ =' ); + add_cacheaction( 'supercache_filename_str', 'wp_cache_check_mobile' ); -if ( function_exists( 'add_filter' ) ) { // loaded since WordPress 4.6 +if ( $wpsc_wp_gte_46 ) { + // loaded since WordPress 4.6 add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' ); } @@ -126,11 +129,7 @@ } // WordPress 4.6 introduces action ms_loaded. -if ( is_multisite() && - empty( $wp_super_cache_late_init ) && - version_compare( $wp_version, '4.6', '>=' ) && - function_exists( 'add_action' ) -) { +if ( is_multisite() && $wpsc_wp_gte_46 && empty( $wp_super_cache_late_init ) ) { add_action( 'ms_loaded', 'wp_cache_serve_cache_file' ); } elseif ( ! isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) { diff --git a/wp-cache.php b/wp-cache.php index dd5f9599..a78559e2 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -1284,7 +1284,7 @@ function toggleLayer( whichLayer ) { wp_nonce_field('wp-cache'); echo "\n"; - if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) { + if ( is_multisite() && wpsupercache_site_admin() ) { echo '
'; echo ''; echo '
'; @@ -2844,7 +2844,7 @@ function wp_cache_delete_buttons() { echo '
'; wp_nonce_field('wp-cache'); echo "
\n"; - if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) { + if ( is_multisite() && wpsupercache_site_admin() ) { echo '
'; echo ''; echo '
'; @@ -2976,6 +2976,8 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) { return false; if ( $handle = @opendir( $dir ) ) { + $curr_blog_id = is_multisite() ? get_current_blog_id() : false; + while ( false !== ( $file = readdir( $handle ) ) ) { if ( is_file( $dir . $file ) == false || $file == 'index.html' ) { continue; @@ -2988,8 +2990,9 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) { @unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); } else { $meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true ); - if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && $meta[ 'blog_id' ] != $wpdb->blogid ) + if ( $curr_blog_id && $curr_blog_id !== (int) $meta['blog_id'] ) { continue; + } @unlink( $dir . $file); @unlink( $dir . 'meta/' . $file); } From 716217b0b820497dae26c041f4821778ecafae0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Todorovi=C4=87?= Date: Thu, 16 Aug 2018 11:44:55 +0200 Subject: [PATCH 3/4] Populates $WPSC_HTTP_HOST for WP-CLI commands (#587) --- wp-cache-base.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-cache-base.php b/wp-cache-base.php index 4c85a8aa..a2f68f78 100644 --- a/wp-cache-base.php +++ b/wp-cache-base.php @@ -1,9 +1,13 @@ Date: Thu, 16 Aug 2018 19:02:59 +0200 Subject: [PATCH 4/4] Explicit declaration of globals in wp-cache-base.php --- wp-cache-base.php | 7 ++++--- wp-cache-phase1.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wp-cache-base.php b/wp-cache-base.php index a2f68f78..61f44b92 100644 --- a/wp-cache-base.php +++ b/wp-cache-base.php @@ -1,5 +1,5 @@ domain : trim( $current_blog->path, '/' ); if ( empty( $blogcacheid ) ) { diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index 07e9ffb1..d7547fb5 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -20,11 +20,12 @@ require WPCACHEHOME . 'wp-cache-base.php'; -if ( $blogcacheid != '' ) { +// Moved to wp-cache-base.php +/*if ( $blogcacheid != '' ) { $blog_cache_dir = str_replace( '//', '/', $cache_path . 'blogs/' . $blogcacheid . '/' ); } else { $blog_cache_dir = $cache_path; -} +}*/ $wp_cache_phase1_loaded = true;