Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
RRZE Webteam
RRZE Cache
Commits
6d616426
Commit
6d616426
authored
Nov 12, 2020
by
Rolf Forst
Browse files
Add Schedule class
parent
653b0d67
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/Schedule.php
0 → 100644
View file @
6d616426
<?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
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment