Last active
August 29, 2015 14:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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