PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / trunk
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels vtrunk
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
automatic-youtube-gallery / public / cron.php

cron.php in Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels trunk, at public/cron.php

108 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * Register the plugin's custom cron intervals.
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['ayg_every_five_minutes'] = array(
33 'interval' => 5 * MINUTE_IN_SECONDS,
34 'display' => __( 'Every 5 Minutes', 'automatic-youtube-gallery' )
35 );
36
37 return $schedules;
38 }
39
40 /**
41 * Schedule the plugin's custom cron event if it's not already scheduled.
42 *
43 * @since 2.3.0
44 */
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' );
50 }
51
52 if ( ! wp_next_scheduled( 'ayg_cron_schedule' ) ) {
53 wp_schedule_event( time(), 'ayg_every_five_minutes', 'ayg_cron_schedule' );
54 }
55 }
56
57 /**
58 * Master scheduled-task dispatcher. Fired every 5 minutes by the ayg_cron_schedule event.
59 *
60 * @since 2.3.0
61 */
62 public function cron_event() {
63 // Gallery Builder sync — every fire (sync() itself picks the single due gallery).
64 $this->sync_galleries();
65
66 // Legacy transient-cache cleanup — heavier, so throttled to roughly once a week.
67 $last_cleanup = (int) get_option( 'ayg_last_transient_cleanup', 0 );
68
69 if ( time() - $last_cleanup >= WEEK_IN_SECONDS ) {
70 $this->cleanup_transients();
71 update_option( 'ayg_last_transient_cleanup', time(), false );
72 }
73 }
74
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 );
105 }
106
107 }
108