forked from Automattic/batcache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batcache.php
45 lines (36 loc) · 1.25 KB
/
batcache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/*
Plugin name: Batcache Manager
Plugin URI: http://wordpress.org/extend/plugins/batcache/
Description: This optional plugin improves Batcache.
Author: Andy Skelton
Author URI: http://andyskelton.com/
Version: 1.0
*/
// Do not load if our advanced-cache.php isn't loaded
if ( ! is_object($batcache) || ! method_exists( $wp_object_cache, 'incr' ) )
return;
$batcache->configure_groups();
// Regen home and permalink on posts and pages
add_action('clean_post_cache', 'batcache_post');
// Regen permalink on comments (TODO)
//add_action('comment_post', 'batcache_comment');
//add_action('wp_set_comment_status', 'batcache_comment');
//add_action('edit_comment', 'batcache_comment');
function batcache_post($post_id) {
global $batcache;
$post = get_post($post_id);
if ( $post->post_type == 'revision' || get_post_status($post_id) != 'publish' )
return;
batcache_clear_url( get_option('home') );
batcache_clear_url( trailingslashit( get_option('home') ) );
batcache_clear_url( get_permalink($post_id) );
}
function batcache_clear_url($url) {
global $batcache;
if ( empty($url) )
return false;
$url_key = md5($url);
wp_cache_add("{$url_key}_version", 0, $batcache->group);
return wp_cache_incr("{$url_key}_version", 1, $batcache->group);
}