Created
September 28, 2017 06:43
-
-
Save ssovit/a698daa15e37af740f9d87e16c1d4316 to your computer and use it in GitHub Desktop.
Auto clean autoptimize cache once a month
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 | |
namespace wppress; | |
class GarbageCollection | |
{ | |
public function __construct() | |
{ | |
add_filter('cron_schedules', function ($schedules) { | |
$schedules['weekly'] = array( | |
'interval' => 604800, | |
'display' => __('Once a Week'), | |
); | |
$schedules['monthly'] = array( | |
'interval' => 2635200, | |
'display' => __('Once a month'), | |
); | |
return $schedules; | |
}); | |
if (!wp_next_scheduled('wppress/garbage/clear')) { | |
wp_schedule_event(time(), 'monthly', 'wppress/garbage/clear'); | |
} | |
add_action('wppress/garbage/clear', [ &$this, 'clear']); | |
} | |
public function clear() | |
{ | |
if (class_exists('\autoptimizeCache')) { | |
/* Clear autoptimize cache once a month */ | |
\autoptimizeCache::clearall(); | |
} | |
} | |
} | |
new GarbageCollection(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment