Advertisement
thesufi

Weekly Flush all caches of W3TC Automatically

Feb 16th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. /** Flush all caches of W3TC
  3.  * Weekly basis
  4.  */
  5. //add weekly shcedule to wp cron
  6. function dctit_cron_add_weekly( $schedules ) {
  7.    //adds once weekly to the existing schedules.
  8.    $schedules['weekly'] = array(
  9.        'interval' => 604800,
  10.        'display' => __( 'Once Weekly' )
  11.    );
  12.    return $schedules;
  13. }
  14. add_filter( 'cron_schedules', 'dctit_cron_add_weekly' );
  15.  
  16. //flush W3TC Cache - all of them
  17. function dctit_flush_w3tc_cache() {
  18.     if ( function_exists('w3tc_flush_all') ) {
  19.         w3tc_flush_all();
  20.     }
  21. }
  22. add_action( 'dctit_flush_w3tc_cache_hook', 'dctit_flush_w3tc_cache');
  23.  
  24. //schedule cron event - weekly
  25. function dctit_flush_cache_event() {
  26.     if ( ! wp_next_scheduled( 'dctit_flush_w3tc_cache_hook' ) ) {
  27.         wp_schedule_event( time(), 'weekly', 'dctit_flush_w3tc_cache_hook' );
  28.     }
  29. }
  30. add_action( 'wp', 'dctit_flush_cache_event' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement