Wordpress plugin Cachify cache clear
The Wordpress Plugin Cachify provides a very fast render cache for annonymus users, but it lacks a method to clear the cache if the user is not admin. This tiny plugin solves this issue.
/*
Plugin Name: Clear Cachify cache
Description: Enables Clear cache buttons for all users
Version: The Plugin"s Version Number, e.g.: 1.0
Author: Thorsten Krug
License: GPL
*/
// Prepare cachlink.
$currenturl = substr($_SERVER["REQUEST_URI"], 0, strpos($_SERVER["REQUEST_URI"], "?"))."?";
$getvars = $_GET;
if(! in_array("clearifycache", $getvars)){
$getvars["clearifycache"]="clearifycache";
}
foreach ($getvars as $key =>$val){
$currenturl .=$key."=".$val."&";
}
$GLOBALS["cache-clear-uri"] = substr($currenturl,0,-1);
// action
function clearcachify_go(){
if(isset($_GET["clearifycache"]) and is_user_logged_in() ){
if (CACHIFY_CACHE_DIR){
if( 0 == shell_exec ( "rm -rf ".CACHIFY_CACHE_DIR."/*" ) ){
add_action("admin_notices", "clearcachify_cleared");
}
}
}
}
function clearcachify_cleared(){
echo "<div class="updated settings-error"><p>Cache cleared</p></div>";
}
function newMenu() {
?>
<li class="wp-has-submenu wp-not-current-submenu menu-top toplevel_page_wibstats menu-top-last">
<div class="wp-menu-image">
<a href="<?php print $GLOBALS["cache-clear-uri"]; ?>" class="menu-top menu-top-first menu-top-last" style="line-height: 26px;">
<img alt="" src="/wp-admin/images/generic.png" style="margin-right: 5px;"> Clear Cache
</a>
</div>
<br />
</li>
<?php }
// Custom menu entry.
add_filter("adminmenu", "newMenu");
add_action( "admin_init", "clearcachify_go" );