-
Notifications
You must be signed in to change notification settings - Fork 0
/
pressable-cache-purge.php
49 lines (38 loc) · 1.1 KB
/
pressable-cache-purge.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
<?php
/*
Plugin Name: Pressable Cache Purge
Plugin URI: https://github.com/Jess81/code
Description: Adds a Cache Purge button to the admin bar
Author: Jess Nunez
Version: 1.0.0
Author URI: https://github.com/Jess81/
License: GPL2
*/
add_action('admin_bar_menu', 'cache_add_item', 100);
function cache_add_item( $admin_bar ){
if(is_admin()) {
global $pagenow;
$admin_bar->add_menu( array( 'id'=>'cache-purge','title'=>'Cache Purge','href'=>'#' ) );
}
}
add_action( 'admin_footer', 'cache_purge_action_js' );
function cache_purge_action_js() { ?>
<script type="text/javascript" >
jQuery("li#wp-admin-bar-cache-purge .ab-item").on( "click", function() {
var data = {
'action': 'pressable_cache_purge',
};
jQuery.post(ajaxurl, data, function(response) {
alert( response );
});
});
</script> <?php
}
add_action( 'wp_ajax_pressable_cache_purge', 'pressable_cache_purge_callback' );
function pressable_cache_purge_callback() {
wp_cache_flush();
$response = "Cache Purged";
echo $response;
wp_die();
}
?>