Skip to content

Instantly share code, notes, and snippets.

@ssovit
Created September 28, 2017 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssovit/a698daa15e37af740f9d87e16c1d4316 to your computer and use it in GitHub Desktop.
Save ssovit/a698daa15e37af740f9d87e16c1d4316 to your computer and use it in GitHub Desktop.
Auto clean autoptimize cache once a month
<?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