diff --git a/readme.txt b/readme.txt index 3e1bd5e..8faff77 100644 --- a/readme.txt +++ b/readme.txt @@ -1,6 +1,6 @@ === W3TC Auto Pilot === Contributors: cybr -Tags: cache, control, w3, total +Tags: cache, control, w3, total, automatic, flush, update, multisite, mapping, hide Requires at least: 3.6.0 Tested up to: 4.2.2 Stable tag: 4.2.2 @@ -50,8 +50,11 @@ It's absolutely great on MultiSite installations, especially when you allow untr == Changelog == += 1.0.3 = +* Fine tuned the purging of page cache to only when a domain is actually mapped. + = 1.0.2 = -* Added forced page cache purging on each post save when Domain Mapping (by WPMUdev) is active +* Added forced page cache purging on each post save when Domain Mapping (by WPMUdev) is active. This will fix a bug with Domain Mapping. = 1.0.1 = * Removed admin notices and errors for non-super-admins (MultiSite) / non-admins (single) diff --git a/w3tc-auto-pilot.php b/w3tc-auto-pilot.php index b6e1e13..1b0a583 100644 --- a/w3tc-auto-pilot.php +++ b/w3tc-auto-pilot.php @@ -3,7 +3,7 @@ * Plugin Name: W3TC Auto Pilot * Plugin URI: https://wordpress.org/plugins/w3tc-auto-pilot/ * Description: Put W3 Total Cache on auto pilot. This plugin allows you to control W3 Total Cache in such a manner that no one knows you're using it, not even your admins. Either network activate it or activate it per site. - * Version: 1.0.2 + * Version: 1.0.3 * Author: Sybre Waaijer * Author URI: https://cyberwire.nl/ * License: GPLv2 or later @@ -61,8 +61,21 @@ function wap_w3tc_init() { function wap_mapped_clear() { //* Check for domain-mapping plugin - if ( is_plugin_active( 'domain-mapping/domain-mapping.php' )) - add_action( 'save_post', 'wap_w3tc_flush_page' ); + if ( is_plugin_active( 'domain-mapping/domain-mapping.php' )) { + global $wpdb,$blog_id; + + $ismapped = wp_cache_get('wap_mapped_clear_' . $blog_id, 'domain_mapping' ); + if ( false === $ismapped ) { + $ismapped = $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM {$wpdb->base_prefix}domain_mapping WHERE blog_id = %d", $blog_id ) ); //string + wp_cache_set('wap_mapped_clear_' . $blog_id, $ismapped, 'domain_mapping', 3600 ); // 1 hour + } + + //* string $ismapped, if mapped != '' + if ( !empty($ismapped) ) { +// add_action( 'save_post', 'wap_w3tc_flush_single_post' ); // Doesn't work unfortunately with Domain Mapping... somehow 2 ID's are being created? + add_action( 'save_post', 'wap_w3tc_flush_page' ); // So we just flush it entirely. But only if the domain is mapped! :D + } + } } function wap_w3tc_flush_all() { @@ -115,6 +128,18 @@ function wap_w3tc_flush_all_widget($instance, $new_instance, $old_instance, $thi return $instance; } +function wap_w3tc_flush_single_post() { + + // Purge the single page cache + if ( function_exists( 'w3tc_pgcache_flush_post' ) ) { + global $post; + $post_id = $post->ID; + + w3tc_pgcache_flush_post($post_id); + } + +} + function wap_w3tc_flush_page() { // Purge the entire page cache