Skip to content

Instantly share code, notes, and snippets.

@ssovit
Created September 28, 2017 06:43

Revisions

  1. ssovit created this gist Sep 28, 2017.
    33 changes: 33 additions & 0 deletions clear-cache.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <?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();
    ?>