Last active
April 6, 2020 01:22
-
-
Save the-sufi/6e2445be8c72d6b45a5b9c24e5b285e8 to your computer and use it in GitHub Desktop.
WordPress - Weekly Flush all caches of W3 Total Cache Automatically
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 | |
/** Flush all caches of W3TC | |
* Weekly basis | |
*/ | |
//add weekly shcedule to wp cron | |
function dctit_cron_add_weekly( $schedules ) { | |
//adds once weekly to the existing schedules. | |
$schedules['weekly'] = array( | |
'interval' => 604800, | |
'display' => __( 'Once Weekly' ) | |
); | |
return $schedules; | |
} | |
add_filter( 'cron_schedules', 'dctit_cron_add_weekly' ); | |
//flush W3TC Cache - all of them | |
function dctit_flush_w3tc_cache() { | |
if ( function_exists('w3tc_flush_all') ) { | |
w3tc_flush_all(); | |
} | |
} | |
add_action( 'dctit_flush_w3tc_cache_hook', 'dctit_flush_w3tc_cache'); | |
//schedule cron event - weekly | |
function dctit_flush_cache_event() { | |
if ( ! wp_next_scheduled( 'dctit_flush_w3tc_cache_hook' ) ) { | |
wp_schedule_event( time(), 'weekly', 'dctit_flush_w3tc_cache_hook' ); | |
} | |
} | |
add_action( 'wp', 'dctit_flush_cache_event' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment