-
Notifications
You must be signed in to change notification settings - Fork 9
/
wp-purges.php
76 lines (67 loc) · 1.37 KB
/
wp-purges.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
73
74
75
76
<?php
/**
* Singleton for registering default WP purges.
*/
class Purgely_Purges {
/**
* The one instance of Purgely_Purges.
*
* @var Purgely_Purges
*/
private static $instance;
/**
* Instantiate or return the one Purgely_Purges instance.
*
* @return Purgely_Purges
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Initiate actions.
*
* @return Purgely_Purges
*/
public function __construct() {
foreach ( $this->_purge_actions() as $action ) {
add_action( $action, array( $this, 'purge' ), 10, 1 );
}
}
/**
* Callback for post changing events to purge URLs.
*
* @param int $post_id Post ID.
* @return void
*/
public function purge( $post_id ) {
if ( ! in_array( get_post_status( $post_id ), array( 'publish', 'trash' ) ) ) {
return;
}
purgely_purge_surrogate_key( 'post-' . absint( $post_id ) );
}
/**
* A list of actions to purge URLs.
*
* @return array List of actions.
*/
private function _purge_actions() {
return array(
'save_post',
'deleted_post',
'trashed_post',
'delete_attachment',
);
}
}
/**
* Instantiate or return the one Purgely_Purges instance.
*
* @return Purgely_Purges
*/
function get_purgely_purges_instance() {
return Purgely_Purges::instance();
}
get_purgely_purges_instance();