Commit 6d616426 authored by Rolf Forst's avatar Rolf Forst
Browse files

Add Schedule class

parent 653b0d67
<?php
namespace RRZE\Cache;
defined('ABSPATH') || exit;
class Schedule
{
public function __construct()
{
//
}
public function onLoaded()
{
add_action('wp', [$this, 'activateScheduledEvents']);
add_filter('cron_schedules', [$this, 'customCronSchedules']);
add_action('rrze_cache_every10minutes_event', [$this, 'every10MinutesEvent']);
}
/**
* customCronSchedules
* Add custom cron schedules.
* @param array $schedules Available cron schedules
* @return array New cron schedules
*/
public function customCronSchedules(array $schedules): array
{
$schedules['rrze_cache_every10minutes'] = [
'interval' => 2 * MINUTE_IN_SECONDS,
'display' => __('Every 10 minutes', 'rrze-cache')
];
return $schedules;
}
/**
* activateScheduledEvents
* Activate all scheduled events.
* @return void
*/
public function activateScheduledEvents()
{
if (!wp_next_scheduled('rrze_cache_every10minutes_event')) {
wp_schedule_event(time(), 'rrze_cache_every10minutes', 'rrze_cache_every10minutes_event');
}
}
/**
* every10MinutesEvent
* Run the event every 10 minutes.
* @return void
*/
public function every10MinutesEvent()
{
File::removeDir(File::getCacheOldDir(), true, 10000);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment