Version Description
- Clear cache on woocommerce stock updates
Download this release
Release Info
| Developer | keycdn |
| Plugin | |
| Version | 1.3.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.2.3 to 1.3.0
- advanced-cache.php +4 -13
- cache-enabler.php +1 -1
- inc/cache_enabler.class.php +61 -37
- readme.txt +3 -0
advanced-cache.php
CHANGED
|
@@ -27,7 +27,7 @@ $settings_file = sprintf('%s-%s%s.json',
|
|
| 27 |
'http://' .strtolower($_SERVER['HTTP_HOST']),
|
| 28 |
PHP_URL_HOST
|
| 29 |
),
|
| 30 |
-
is_multisite() ? '-'.
|
| 31 |
);
|
| 32 |
$settings = _read_settings($settings_file);
|
| 33 |
|
|
@@ -40,18 +40,9 @@ if ( !empty($settings['excl_regexp']) ) {
|
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
-
//
|
| 44 |
-
if ( !empty($
|
| 45 |
-
|
| 46 |
-
} else {
|
| 47 |
-
$query_strings_regex = '/^utm_(source|medium|campaign|term|content)/';
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
// check request query strings
|
| 51 |
-
foreach ( (array)$_GET as $key => $value ) {
|
| 52 |
-
if ( preg_match($query_strings_regex, $key) ) {
|
| 53 |
-
return false;
|
| 54 |
-
}
|
| 55 |
}
|
| 56 |
|
| 57 |
// check cookie values
|
| 27 |
'http://' .strtolower($_SERVER['HTTP_HOST']),
|
| 28 |
PHP_URL_HOST
|
| 29 |
),
|
| 30 |
+
is_multisite() ? '-'. abs(intval($blog_id)) : ''
|
| 31 |
);
|
| 32 |
$settings = _read_settings($settings_file);
|
| 33 |
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
+
// check if request with query strings
|
| 44 |
+
if ( ! empty($_GET) && ! isset( $_GET['utm_source'], $_GET['utm_medium'], $_GET['utm_campaign'] ) ) {
|
| 45 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
// check cookie values
|
cache-enabler.php
CHANGED
|
@@ -6,7 +6,7 @@ Description: Simple and fast WordPress disk caching plugin.
|
|
| 6 |
Author: KeyCDN
|
| 7 |
Author URI: https://www.keycdn.com
|
| 8 |
License: GPLv2 or later
|
| 9 |
-
Version: 1.
|
| 10 |
*/
|
| 11 |
|
| 12 |
/*
|
| 6 |
Author: KeyCDN
|
| 7 |
Author URI: https://www.keycdn.com
|
| 8 |
License: GPLv2 or later
|
| 9 |
+
Version: 1.3.0
|
| 10 |
*/
|
| 11 |
|
| 12 |
/*
|
inc/cache_enabler.class.php
CHANGED
|
@@ -143,6 +143,26 @@ final class Cache_Enabler {
|
|
| 143 |
'on_upgrade_hook'
|
| 144 |
), 10, 2);
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
// add admin clear link
|
| 147 |
add_action(
|
| 148 |
'admin_bar_menu',
|
|
@@ -159,6 +179,15 @@ final class Cache_Enabler {
|
|
| 159 |
'process_clear_request'
|
| 160 |
)
|
| 161 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
// admin
|
| 164 |
if ( is_admin() ) {
|
|
@@ -374,8 +403,8 @@ final class Cache_Enabler {
|
|
| 374 |
}
|
| 375 |
|
| 376 |
// check if we got upgraded ourselves
|
| 377 |
-
if ( $options['action'] == 'update' && $options['type'] == 'plugin' ) {
|
| 378 |
-
foreach ( $options['plugins'] as $each_plugin ) {
|
| 379 |
if ( preg_match("/^cache-enabler\//", $each_plugin) ) {
|
| 380 |
// we got updated!
|
| 381 |
self::on_upgrade();
|
|
@@ -630,7 +659,6 @@ final class Cache_Enabler {
|
|
| 630 |
'excl_ids' => '',
|
| 631 |
'excl_regexp' => '',
|
| 632 |
'excl_cookies' => '',
|
| 633 |
-
'excl_querystrings' => '',
|
| 634 |
'minify_html' => self::MINIFY_DISABLED,
|
| 635 |
)
|
| 636 |
);
|
|
@@ -1377,18 +1405,9 @@ final class Cache_Enabler {
|
|
| 1377 |
return true;
|
| 1378 |
}
|
| 1379 |
|
| 1380 |
-
//
|
| 1381 |
-
if ( !empty($
|
| 1382 |
-
|
| 1383 |
-
} else {
|
| 1384 |
-
$query_strings_regex = '/^utm_(source|medium|campaign|term|content)/';
|
| 1385 |
-
}
|
| 1386 |
-
|
| 1387 |
-
// check request query strings
|
| 1388 |
-
foreach ( (array)$_GET as $key => $value ) {
|
| 1389 |
-
if ( preg_match($query_strings_regex, $key) ) {
|
| 1390 |
-
return true;
|
| 1391 |
-
}
|
| 1392 |
}
|
| 1393 |
|
| 1394 |
// if logged in
|
|
@@ -1511,6 +1530,21 @@ final class Cache_Enabler {
|
|
| 1511 |
}
|
| 1512 |
|
| 1513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1514 |
/**
|
| 1515 |
* set cache
|
| 1516 |
*
|
|
@@ -1946,14 +1980,6 @@ final class Cache_Enabler {
|
|
| 1946 |
Cache_Enabler_Disk::delete_advcache_settings(array("excl_cookies"));
|
| 1947 |
}
|
| 1948 |
|
| 1949 |
-
// custom querystrings exceptions
|
| 1950 |
-
if ( strlen($data["excl_querystrings"]) > 0 ) {
|
| 1951 |
-
Cache_Enabler_Disk::record_advcache_settings(array(
|
| 1952 |
-
"excl_querystrings" => $data["excl_querystrings"]));
|
| 1953 |
-
} else {
|
| 1954 |
-
Cache_Enabler_Disk::delete_advcache_settings(array("excl_querystrings"));
|
| 1955 |
-
}
|
| 1956 |
-
|
| 1957 |
return array(
|
| 1958 |
'expires' => (int)$data['expires'],
|
| 1959 |
'new_post' => (int)(!empty($data['new_post'])),
|
|
@@ -1964,7 +1990,6 @@ final class Cache_Enabler {
|
|
| 1964 |
'excl_ids' => (string)sanitize_text_field(@$data['excl_ids']),
|
| 1965 |
'excl_regexp' => (string)self::validate_regexps(@$data['excl_regexp']),
|
| 1966 |
'excl_cookies' => (string)self::validate_regexps(@$data['excl_cookies']),
|
| 1967 |
-
'excl_querystrings' => (string)self::validate_regexps(@$data['excl_querystrings']),
|
| 1968 |
'minify_html' => (int)$data['minify_html']
|
| 1969 |
);
|
| 1970 |
}
|
|
@@ -2073,31 +2098,30 @@ final class Cache_Enabler {
|
|
| 2073 |
<fieldset>
|
| 2074 |
<label for="cache_excl_ids">
|
| 2075 |
<input type="text" name="cache-enabler[excl_ids]" id="cache_excl_ids" value="<?php echo esc_attr($options['excl_ids']) ?>" />
|
| 2076 |
-
<p class="description"
|
|
|
|
|
|
|
| 2077 |
</label>
|
| 2078 |
|
| 2079 |
<br />
|
| 2080 |
|
| 2081 |
<label for="cache_excl_regexp">
|
| 2082 |
<input type="text" name="cache-enabler[excl_regexp]" id="cache_excl_regexp" value="<?php echo esc_attr($options['excl_regexp']) ?>" />
|
| 2083 |
-
<p class="description"
|
|
|
|
|
|
|
|
|
|
| 2084 |
</label>
|
| 2085 |
|
| 2086 |
<br />
|
| 2087 |
|
| 2088 |
<label for="cache_excl_cookies">
|
| 2089 |
<input type="text" name="cache-enabler[excl_cookies]" id="cache_excl_cookies" value="<?php echo esc_attr($options['excl_cookies']) ?>" />
|
| 2090 |
-
<p class="description"
|
| 2091 |
-
|
| 2092 |
-
|
| 2093 |
-
|
| 2094 |
-
|
| 2095 |
-
<br />
|
| 2096 |
-
|
| 2097 |
-
<label for="cache_excl_querystrings">
|
| 2098 |
-
<input type="text" name="cache-enabler[excl_querystrings]" id="cache_excl_querystrings" value="<?php echo esc_attr($options['excl_querystrings']) ?>" />
|
| 2099 |
-
<p class="description"><?php _e("Regexp matching query strings that should cause the cache to be bypassed. <br>
|
| 2100 |
-
default if unset: <nobr><code>/^utm_(source|medium|campaign|term|content)/</code></nobr>", "cache-enabler"); ?></p>
|
| 2101 |
</label>
|
| 2102 |
</fieldset>
|
| 2103 |
</td>
|
| 143 |
'on_upgrade_hook'
|
| 144 |
), 10, 2);
|
| 145 |
|
| 146 |
+
// act on woocommerce actions
|
| 147 |
+
add_action(
|
| 148 |
+
'woocommerce_product_set_stock',
|
| 149 |
+
array(
|
| 150 |
+
__CLASS__,
|
| 151 |
+
'woocommerce_product_set_stock',
|
| 152 |
+
),
|
| 153 |
+
10,
|
| 154 |
+
1
|
| 155 |
+
);
|
| 156 |
+
add_action(
|
| 157 |
+
'woocommerce_product_set_stock_status',
|
| 158 |
+
array(
|
| 159 |
+
__CLASS__,
|
| 160 |
+
'woocommerce_product_set_stock_status',
|
| 161 |
+
),
|
| 162 |
+
10,
|
| 163 |
+
1
|
| 164 |
+
);
|
| 165 |
+
|
| 166 |
// add admin clear link
|
| 167 |
add_action(
|
| 168 |
'admin_bar_menu',
|
| 179 |
'process_clear_request'
|
| 180 |
)
|
| 181 |
);
|
| 182 |
+
if ( !is_admin() ) {
|
| 183 |
+
add_action(
|
| 184 |
+
'admin_bar_menu',
|
| 185 |
+
array(
|
| 186 |
+
__CLASS__,
|
| 187 |
+
'register_textdomain'
|
| 188 |
+
)
|
| 189 |
+
);
|
| 190 |
+
}
|
| 191 |
|
| 192 |
// admin
|
| 193 |
if ( is_admin() ) {
|
| 403 |
}
|
| 404 |
|
| 405 |
// check if we got upgraded ourselves
|
| 406 |
+
if ( $options['action'] == 'update' && $options['type'] == 'plugin' && array_key_exists('plugins', $options) ) {
|
| 407 |
+
foreach ( (array)$options['plugins'] as $each_plugin ) {
|
| 408 |
if ( preg_match("/^cache-enabler\//", $each_plugin) ) {
|
| 409 |
// we got updated!
|
| 410 |
self::on_upgrade();
|
| 659 |
'excl_ids' => '',
|
| 660 |
'excl_regexp' => '',
|
| 661 |
'excl_cookies' => '',
|
|
|
|
| 662 |
'minify_html' => self::MINIFY_DISABLED,
|
| 663 |
)
|
| 664 |
);
|
| 1405 |
return true;
|
| 1406 |
}
|
| 1407 |
|
| 1408 |
+
// Request with query strings
|
| 1409 |
+
if ( ! empty($_GET) && ! isset( $_GET['utm_source'], $_GET['utm_medium'], $_GET['utm_campaign'] ) && get_option('permalink_structure') ) {
|
| 1410 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1411 |
}
|
| 1412 |
|
| 1413 |
// if logged in
|
| 1530 |
}
|
| 1531 |
|
| 1532 |
|
| 1533 |
+
/**
|
| 1534 |
+
* Act on WooCommerce stock changes
|
| 1535 |
+
*
|
| 1536 |
+
* @since 1.3.0
|
| 1537 |
+
*/
|
| 1538 |
+
|
| 1539 |
+
public static function woocommerce_product_set_stock($product) {
|
| 1540 |
+
self::woocommerce_product_set_stock_status($product->get_id());
|
| 1541 |
+
}
|
| 1542 |
+
|
| 1543 |
+
public static function woocommerce_product_set_stock_status($product_id) {
|
| 1544 |
+
self::clear_total_cache();
|
| 1545 |
+
}
|
| 1546 |
+
|
| 1547 |
+
|
| 1548 |
/**
|
| 1549 |
* set cache
|
| 1550 |
*
|
| 1980 |
Cache_Enabler_Disk::delete_advcache_settings(array("excl_cookies"));
|
| 1981 |
}
|
| 1982 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1983 |
return array(
|
| 1984 |
'expires' => (int)$data['expires'],
|
| 1985 |
'new_post' => (int)(!empty($data['new_post'])),
|
| 1990 |
'excl_ids' => (string)sanitize_text_field(@$data['excl_ids']),
|
| 1991 |
'excl_regexp' => (string)self::validate_regexps(@$data['excl_regexp']),
|
| 1992 |
'excl_cookies' => (string)self::validate_regexps(@$data['excl_cookies']),
|
|
|
|
| 1993 |
'minify_html' => (int)$data['minify_html']
|
| 1994 |
);
|
| 1995 |
}
|
| 2098 |
<fieldset>
|
| 2099 |
<label for="cache_excl_ids">
|
| 2100 |
<input type="text" name="cache-enabler[excl_ids]" id="cache_excl_ids" value="<?php echo esc_attr($options['excl_ids']) ?>" />
|
| 2101 |
+
<p class="description">
|
| 2102 |
+
<?php echo sprintf(__("Post or Pages IDs separated by a %s that should not be cached.", "cache-enabler"), "<code>,</code>"); ?>
|
| 2103 |
+
</p>
|
| 2104 |
</label>
|
| 2105 |
|
| 2106 |
<br />
|
| 2107 |
|
| 2108 |
<label for="cache_excl_regexp">
|
| 2109 |
<input type="text" name="cache-enabler[excl_regexp]" id="cache_excl_regexp" value="<?php echo esc_attr($options['excl_regexp']) ?>" />
|
| 2110 |
+
<p class="description">
|
| 2111 |
+
<?php _e("Regexp matching page paths that should not be cached.", "cache-enabler"); ?><br>
|
| 2112 |
+
<?php _e("Example:", "cache-enabler"); ?> <code>/(^\/$|\/robot\/$|^\/2018\/.*\/test\/)/</code>
|
| 2113 |
+
</p>
|
| 2114 |
</label>
|
| 2115 |
|
| 2116 |
<br />
|
| 2117 |
|
| 2118 |
<label for="cache_excl_cookies">
|
| 2119 |
<input type="text" name="cache-enabler[excl_cookies]" id="cache_excl_cookies" value="<?php echo esc_attr($options['excl_cookies']) ?>" />
|
| 2120 |
+
<p class="description">
|
| 2121 |
+
<?php _e("Regexp matching cookies that should cause the cache to be bypassed.", "cache-enabler"); ?><br>
|
| 2122 |
+
<?php _e("Example:", "cache-enabler"); ?> <code>/^(wp-postpass|wordpress_logged_in|comment_author|(woocommerce_items_in_cart|wp_woocommerce_session)_?)/</code><br>
|
| 2123 |
+
<?php _e("Default if unset:", "cache-enabler"); ?> <code>/^(wp-postpass|wordpress_logged_in|comment_author)_/</code>
|
| 2124 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2125 |
</label>
|
| 2126 |
</fieldset>
|
| 2127 |
</td>
|
readme.txt
CHANGED
|
@@ -69,6 +69,9 @@ When combined with Optimus, the Wordpress Cache Enabler allows you to easily del
|
|
| 69 |
|
| 70 |
== Changelog ==
|
| 71 |
|
|
|
|
|
|
|
|
|
|
| 72 |
= 1.2.3 =
|
| 73 |
* Fix expiry time
|
| 74 |
* Allow to customize bypass cookies
|
| 69 |
|
| 70 |
== Changelog ==
|
| 71 |
|
| 72 |
+
= 1.3.0 =
|
| 73 |
+
* Clear cache on woocommerce stock updates
|
| 74 |
+
|
| 75 |
= 1.2.3 =
|
| 76 |
* Fix expiry time
|
| 77 |
* Allow to customize bypass cookies
|
