Created
April 21, 2023 09:05
-
-
Save adczk/93033de5d31b30ca65d025ca52bf9ceb to your computer and use it in GitHub Desktop.
Very Simple Object Cache Flusher through custom URL
This file contains hidden or 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 | |
| /** | |
| * Plugin Name: Very Simple Object Cache Flusher | |
| * Plugin URI: https://premium.wpmudev.org/ | |
| * Description: Flush object cache by calling custom URL with query var; | |
| * Note: only works if Object Cache is integrated with WP via object-cache.php drop-in | |
| * Author: adczk | |
| * Author URI: https://premium.wpmudev.org/ | |
| * License: GPLv2 or later | |
| * | |
| * config explained in code comment; use as MU plugin | |
| * use: just visit URL like "https://yoursite.com/?hocfe=12356 where 12356 should be replaced with key defined in the code | |
| */ | |
| // register query var | |
| function hocfe_query_vars( $qvars ) { | |
| $qvars[] = 'hocfe'; | |
| return $qvars; | |
| } | |
| add_filter( 'query_vars', 'hocfe_query_vars' ); | |
| // listen to request and run cache flush | |
| add_action( 'wp_footer', 'hocfe_flush_cache', 99 ); | |
| function hocfe_flush_cache() { | |
| $key = "12356"; // define key - can be any random string | |
| $doflush = get_query_var( 'hocfe', 0 ); | |
| if ( $doflush == $key ) { | |
| $doneflush = wp_cache_flush(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment