Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 49 additions & 25 deletions plugins/multisite.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<?php

if ( is_multisite() ) {
add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
if ( function_exists( 'add_action' ) ) {
add_action( 'ms_loaded', 'wp_super_cache_multisite_loaded' );
} else {
add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
}
}

function wp_super_cache_multisite_loaded() {
wp_super_cache_override_on_flag();
wp_super_cache_multisite_admin_init();
}

function wp_super_cache_multisite_init() {
add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' );
add_action( 'manage_sites_custom_column', 'wp_super_cache_blogs_field', 10, 2 );
add_action( 'init', 'wp_super_cache_override_on_flag', 9 );
wp_super_cache_multisite_admin_init();
}

function wp_super_cache_multisite_admin_init() {
if ( is_admin() ) {
add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' );
add_action( 'manage_sites_custom_column', 'wp_super_cache_blogs_field', 10, 2 );
}
}

function wp_super_cache_blogs_col( $col ) {
Expand All @@ -17,48 +32,57 @@ function wp_super_cache_blogs_col( $col ) {

function wp_super_cache_blogs_field( $name, $blog_id ) {
if ( 'wp_super_cache' !== $name ) {
return false;
return;
}

$blog_id = (int) $blog_id;

if ( isset( $_GET['id'], $_GET['action'], $_GET['_wpnonce'] )
&& $blog_id === filter_input( INPUT_GET, 'id', FILTER_VALIDATE_INT )
&& wp_verify_nonce( $_GET['_wpnonce'], 'wp-cache' . $blog_id )
if ( isset( $_GET['id'], $_GET['action'], $_GET['_wpnonce'] ) // WPCS: input var ok.
&& filter_input( INPUT_GET, 'id', FILTER_VALIDATE_INT ) === $blog_id
&& wp_verify_nonce( $_GET['_wpnonce'], 'wp-cache' . $blog_id ) // WPCS: sanitization ok.
) {
if ( 'disable_cache' === filter_input( INPUT_GET, 'action' ) ) {
if ( filter_input( INPUT_GET, 'action' ) === 'disable_cache' ) {
add_blog_option( $blog_id, 'wp_super_cache_disabled', 1 );
} elseif ( 'enable_cache' === filter_input( INPUT_GET, 'action' ) ) {
} elseif ( filter_input( INPUT_GET, 'action' ) === 'enable_cache' ) {
delete_blog_option( $blog_id, 'wp_super_cache_disabled' );
}
}

if ( 1 === (int) get_blog_option( $blog_id, 'wp_super_cache_disabled' ) ) {
echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Enable', 'wp-super-cache' ) . '</a>';
} else {
echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'disable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Disable', 'wp-super-cache' ) . '</a>';
}
$cache_option = (int) get_blog_option( $blog_id, 'wp_super_cache_disabled' ) === 1;

$action_text = $cache_option ? __( 'Enable', 'wp-super-cache' ) : __( 'Disable', 'wp-super-cache' );
$action_args = array(
'action' => $cache_option ? 'enable_cache' : 'disable_cache',
'id' => $blog_id,
'_wpnonce' => wp_create_nonce( 'wp-cache' . $blog_id ),
);
printf( '<a href="%s">%s</a>', esc_url_raw( add_query_arg( $action_args ) ), esc_html( $action_text ) );
}

function wp_super_cache_multisite_notice() {
if ( 'wpsupercache' === filter_input( INPUT_GET, 'page' ) ) {
echo '<div class="error"><p><strong>' . __( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>';
if ( filter_input( INPUT_GET, 'page' ) === 'wpsupercache' ) {
echo '<div class="error"><p><strong>' . esc_html__( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>';
}
}

function wp_super_cache_override_on_flag() {
global $cache_enabled, $super_cache_enabled;
if ( true !== $cache_enabled ) {
global $cache_enabled, $super_cache_enabled, $cache_path, $blogcacheid, $blog_cache_dir, $current_blog;

if ( is_object( $current_blog ) ) {
$blogcacheid = trim( is_subdomain_install() ? $current_blog->domain : $current_blog->path, '/' );
$blog_cache_dir = $cache_path . 'blogs/' . $blogcacheid . '/';
}

if ( true !== $cache_enabled || (int) get_option( 'wp_super_cache_disabled' ) !== 1 ) {
return false;
}

if ( 1 === (int) get_option( 'wp_super_cache_disabled' ) ) {
$cache_enabled = false;
$super_cache_enabled = false;
define( 'DONOTCACHEPAGE', 1 );
$cache_enabled = false;
$super_cache_enabled = false;
defined( 'DONOTCACHEPAGE' ) || define( 'DONOTCACHEPAGE', 1 );

if ( is_admin() ) {
define( 'SUBMITDISABLED', 'disabled style="color: #aaa" ' );
if ( is_admin() ) {
add_action( 'admin_notices', 'wp_super_cache_multisite_notice' );
}
add_action( 'admin_notices', 'wp_super_cache_multisite_notice' );
}
}
5 changes: 1 addition & 4 deletions wp-cache-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
$blog_cache_dir = $cache_path;

if ( is_multisite() ) {
global $current_blog;

if ( is_object( $current_blog ) && function_exists( 'is_subdomain_install' ) ) {
$blogcacheid = is_subdomain_install() ? $current_blog->domain : trim( $current_blog->path, '/' );
} elseif ( ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST === 'yes' ) ) {
if ( ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) || ( defined( 'VHOST' ) && VHOST === 'yes' ) ) {
$blogcacheid = $WPSC_HTTP_HOST;
} else {
$request_uri = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
Expand Down
6 changes: 0 additions & 6 deletions wp-cache-phase1.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@

require WPCACHEHOME . '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;

$mutex_filename = 'wp_cache_mutex.lock';
Expand Down