| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Cron Jobs. |
| 5 |
* |
| 6 |
* @link https://plugins360.com |
| 7 |
* @since 2.3.0 |
| 8 |
* |
| 9 |
* @package Automatic_YouTube_Gallery |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly |
| 13 |
if ( ! defined( 'WPINC' ) ) { |
| 14 |
die; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* AYG_Public_Cron class. |
| 19 |
* |
| 20 |
* @since 2.3.0 |
| 21 |
*/ |
| 22 |
class AYG_Public_Cron { |
| 23 |
|
| 24 |
/** |
| 25 |
* Add a custom weekly cron schedule. |
| 26 |
* |
| 27 |
* @since 2.3.0 |
| 28 |
* @param array $schedules An array of non-default cron schedules. |
| 29 |
* @return array $schedules Filtered array of non-default cron schedules. |
| 30 |
*/ |
| 31 |
public function cron_schedules( $schedules ) { |
| 32 |
$schedules['weekly'] = array( |
| 33 |
'interval' => 7 * DAY_IN_SECONDS, |
| 34 |
'display' => __( 'Weekly', 'automatic-youtube-gallery' ) |
| 35 |
); |
| 36 |
|
| 37 |
return $schedules; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Schedule an action if it's not already scheduled. |
| 42 |
* |
| 43 |
* @since 2.3.0 |
| 44 |
*/ |
| 45 |
public function schedule_events() { |
| 46 |
if ( ! wp_next_scheduled( 'ayg_schedule_weekly' ) ) { |
| 47 |
wp_schedule_event( time(), 'weekly', 'ayg_schedule_weekly' ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Called weekly. |
| 53 |
* |
| 54 |
* @since 2.3.0 |
| 55 |
*/ |
| 56 |
public function cron_event() { |
| 57 |
$existing_keys = get_option( 'ayg_transient_keys', array() ); |
| 58 |
|
| 59 |
if ( is_array( $existing_keys ) ) { |
| 60 |
$filtered_keys = array(); |
| 61 |
|
| 62 |
foreach ( $existing_keys as $key ) { |
| 63 |
if ( get_transient( $key ) ) { |
| 64 |
$filtered_keys[] = $key; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
update_option( 'ayg_transient_keys', $filtered_keys ); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|