PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.6.4
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.6.4
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
← All changes | public/cron.php +18 -53 2.9.02.6.4 View file →
@@ -21,9 +21,9 @@
21 21 */
22 22 class AYG_Public_Cron {
23 23
24 24 /**
25 - * Register the plugin's custom cron intervals.
25 + * Add a custom weekly cron schedule.
26 26 *
27 27 * @since 2.3.0
28 28 * @param array $schedules An array of non-default cron schedules.
29 29 * @return array $schedules Filtered array of non-default cron schedules.
@@ -28,11 +28,11 @@
28 28 * @param array $schedules An array of non-default cron schedules.
29 29 * @return array $schedules Filtered array of non-default cron schedules.
30 30 */
31 31 public function cron_schedules( $schedules ) {
32 - $schedules['ayg_every_five_minutes'] = array(
33 - 'interval' => 5 * MINUTE_IN_SECONDS,
34 - 'display' => __( 'Every 5 Minutes', 'automatic-youtube-gallery' )
32 + $schedules['weekly'] = array(
33 + 'interval' => 7 * DAY_IN_SECONDS,
34 + 'display' => __( 'Weekly', 'automatic-youtube-gallery' )
35 35 );
36 36
37 37 return $schedules;
38 38 }
@@ -37,71 +37,36 @@
37 37 return $schedules;
38 38 }
39 39
40 40 /**
41 - * Schedule the plugin's custom cron event if it's not already scheduled.
41 + * Schedule an action if it's not already scheduled.
42 42 *
43 43 * @since 2.3.0
44 44 */
45 45 public function schedule_events() {
46 - // Migrate away from the pre-2.8.0 weekly event — its cleanup work now runs through
47 - // the single ayg_cron_schedule dispatcher below.
48 - if ( wp_next_scheduled( 'ayg_schedule_weekly' ) ) {
49 - wp_clear_scheduled_hook( 'ayg_schedule_weekly' );
46 + if ( ! wp_next_scheduled( 'ayg_schedule_weekly' ) ) {
47 + wp_schedule_event( time(), 'weekly', 'ayg_schedule_weekly' );
50 48 }
51 -
52 - if ( ! wp_next_scheduled( 'ayg_cron_schedule' ) ) {
53 - wp_schedule_event( time(), 'ayg_every_five_minutes', 'ayg_cron_schedule' );
54 - }
55 49 }
56 50
57 51 /**
58 - * Master scheduled-task dispatcher. Fired every 5 minutes by the ayg_cron_schedule event.
52 + * Called weekly.
59 53 *
60 54 * @since 2.3.0
61 55 */
62 56 public function cron_event() {
63 - // Gallery Builder sync — every fire (sync() itself picks the single due gallery).
64 - $this->sync_galleries();
57 + $existing_keys = get_option( 'ayg_transient_keys', array() );
65 58
66 - // Legacy transient-cache cleanup — heavier, so throttled to roughly once a week.
67 - $last_cleanup = (int) get_option( 'ayg_last_transient_cleanup', 0 );
59 + if ( is_array( $existing_keys ) ) {
60 + $filtered_keys = array();
68 61
69 - if ( time() - $last_cleanup >= WEEK_IN_SECONDS ) {
70 - $this->cleanup_transients();
71 - update_option( 'ayg_last_transient_cleanup', time(), false );
72 - }
73 - }
62 + foreach ( $existing_keys as $key ) {
63 + if ( get_transient( $key ) ) {
64 + $filtered_keys[] = $key;
65 + }
66 + }
74 67
75 - /**
76 - * Run the Gallery Builder scheduled sync.
77 - *
78 - * @since 2.8.0
79 - * @access private
80 - */
81 - private function sync_galleries() {
82 - $importer = new AYG_Import();
83 - $importer->sync();
84 - }
85 -
86 - /**
87 - * Drop expired keys from the legacy transient-cache key list.
88 - *
89 - * @since 2.3.0
90 - * @access private
91 - */
92 - private function cleanup_transients() {
93 - $existing_keys = ayg_get_option( 'ayg_transient_keys' );
94 -
95 - $filtered_keys = array();
96 -
97 - foreach ( $existing_keys as $key ) {
98 - if ( get_transient( $key ) ) {
99 - $filtered_keys[] = $key;
100 - }
101 - }
102 -
103 - // Save it to the DB (autoload=no: this list can grow large and is not needed on every page load)
104 - update_option( 'ayg_transient_keys', $filtered_keys, false );
68 + update_option( 'ayg_transient_keys', $filtered_keys );
69 + }
105 70 }
106 71
107 72 }