PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.4
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / expiring-store / user-interface / expiring-store-cleanup-integration.php

expiring-store-cleanup-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.4, at src/expiring-store/user-interface/expiring-store-cleanup-integration.php

74 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Expiring_Store\User_Interface;
4
5 use Yoast\WP\SEO\Conditionals\No_Conditionals;
6 use Yoast\WP\SEO\Expiring_Store\Application\Expiring_Store;
7 use Yoast\WP\SEO\Integrations\Integration_Interface;
8
9 /**
10 * Runs expiring store cleanup on a recurring weekly WP-Cron schedule.
11 */
12 class Expiring_Store_Cleanup_Integration implements Integration_Interface {
13
14 use No_Conditionals;
15
16 public const CRON_HOOK = 'wpseo_expiring_store_cleanup';
17
18 /**
19 * The expiring store.
20 *
21 * @var Expiring_Store
22 */
23 private $expiring_store;
24
25 /**
26 * The constructor.
27 *
28 * @param Expiring_Store $expiring_store The expiring store.
29 */
30 public function __construct( Expiring_Store $expiring_store ) {
31 $this->expiring_store = $expiring_store;
32 }
33
34 /**
35 * Registers action hooks.
36 *
37 * @return void
38 */
39 public function register_hooks(): void {
40 \add_action( 'admin_init', [ $this, 'schedule_cleanup' ] );
41 \add_action( self::CRON_HOOK, [ $this, 'run_cleanup' ] );
42 \add_action( 'wpseo_deactivate', [ $this, 'unschedule_cleanup' ] );
43 }
44
45 /**
46 * Schedules the weekly cleanup cron if not already scheduled.
47 *
48 * @return void
49 */
50 public function schedule_cleanup(): void {
51 if ( ! \wp_next_scheduled( self::CRON_HOOK ) ) {
52 \wp_schedule_event( \time(), 'weekly', self::CRON_HOOK );
53 }
54 }
55
56 /**
57 * Clears all scheduled cleanup events.
58 *
59 * @return void
60 */
61 public function unschedule_cleanup(): void {
62 \wp_clear_scheduled_hook( self::CRON_HOOK );
63 }
64
65 /**
66 * Runs the expiring store cleanup.
67 *
68 * @return void
69 */
70 public function run_cleanup(): void {
71 $this->expiring_store->cleanup_expired();
72 }
73 }
74