mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://developer.wordpress.org/reference/functions/delete_expired_transients/ https://developer.wordpress.org/reference/hooks/cron_schedules/
21 lines
826 B
Text
21 lines
826 B
Text
function modify_delete_expired_transients_schedule() {
|
|
// Check if the cron event is scheduled
|
|
if ( ! wp_next_scheduled( 'delete_expired_transients' ) ) {
|
|
return;
|
|
}
|
|
// Unschedule the event
|
|
wp_unschedule_event( wp_next_scheduled( 'delete_expired_transients' ), 'delete_expired_transients' );
|
|
// Schedule the event to run every 6 hours
|
|
wp_schedule_event( time(), 'six_hours', 'delete_expired_transients' );
|
|
}
|
|
add_action( 'init', 'modify_delete_expired_transients_schedule' );
|
|
|
|
function add_six_hours_interval( $schedules ) {
|
|
// Add a new interval for every 6 hours
|
|
$schedules['six_hours'] = array(
|
|
'interval' => 21600, // 6 hours in seconds
|
|
'display' => __( 'Every 6 Hours' ),
|
|
);
|
|
return $schedules;
|
|
}
|
|
add_filter( 'cron_schedules', 'add_six_hours_interval' );
|