-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvarnish-helper.php
72 lines (57 loc) · 1.77 KB
/
varnish-helper.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
Plugin Name: Varnish Helper
Plugin URI: https://github.com/mingshun/varnish-helper
Description: Varnish helper for WordPress in purge and ESI.
Author: mingshun
Author URI: https://github.com/mingshun
Version: 1.0
*/
require_once('generic-purges.php');
require_once('esi-widget.php');
require_once('option-page.php');
/**
* Purge the post whose status changed.
*
* @since 1.0
*/
function vh_purge_when_post_status_changed($new_status, $old_status, $post) {
if ($new_status == 'publish' || $old_status == 'publish') {
vh_purge_post($post->ID);
vh_purge_common($post->ID);
vh_purge_post_related_pages($post->ID);
vh_purge_esi_sidebar();
}
}
/**
* Purge the post which has new comment.
*
* @since 1.0
*/
function vh_purge_comment($comment_id) {
$comment = get_comment($comment_id);
$post_id = $comment->comment_post_ID;
vh_purge_post($post_id);
}
/**
* Purge the post containing the comment whose status changed.
*
* @since 1.0
*/
function vh_purge_when_comment_status_changed($new_status, $old_status, $comment) {
if ($new_status == 'approved' || $old_status == 'approved') {
$post_id = $comment->comment_post_ID;
vh_purge_post($post_id);
vh_purge_esi_sidebar();
}
}
// Purge when post status changed.
add_action('transition_post_status', 'vh_purge_when_post_status_changed', 99, 3);
// Purge when there is a comment or the existing comment status changes.
add_action('comment_post', 'vh_purge_comment', 99);
add_action('transition_comment_status', 'vh_purge_when_comment_status_changed', 99, 3);
// Purge when there is a xml-rpc call.
add_action('xmlrpc_call', 'vh_purge_all', 99);
// Purge when switching theme.
add_action('switch_theme', 'vh_purge_all', 99);
?>