Skip to content

Instantly share code, notes, and snippets.

@benjaminpick
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminpick/67b6b9a49ef7991172f9 to your computer and use it in GitHub Desktop.
Save benjaminpick/67b6b9a49ef7991172f9 to your computer and use it in GitHub Desktop.
Allow clearing the cache by calling an URL. This can be useful for automatic deployment.
<?php
if (!defined('CLEAR_CACHE_HOOK_KEY'))
define('CLEAR_CACHE_HOOK_KEY', 'some_secret_key_please');
function yt_cache_clear_web_hook() {
if (isset($_GET['key']) && $_GET['key'] == CLEAR_CACHE_HOOK_KEY) {
if (function_exists('ccfm_clear_cache_for_me')) {
ccfm_clear_cache_for_me( 'ajax' );
echo 'Cache was cleared.';
} else {
echo 'Install the plugin "Clear Cache For Me" first';
}
exit;
}
}
// Call this URL to clear the cache:
// /wp-admin/admin-ajax.php?action=clear_cache&key=some_secret_key_please
add_action( 'wp_ajax_clear_cache', 'yt_cache_clear_web_hook' );
add_action( 'wp_ajax_nopriv_clear_cache', 'yt_cache_clear_web_hook' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment