PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.7
28.6 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 All 130 releases
wordpress-seo / src / llms-txt / application / file / llms-txt-cron-scheduler.php

llms-txt-cron-scheduler.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.7, at src/llms-txt/application/file/llms-txt-cron-scheduler.php

80 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 namespace Yoast\WP\SEO\Llms_Txt\Application\File;
5
6 use Yoast\WP\SEO\Helpers\Options_Helper;
7
8 /**
9 * Responsible for scheduling and unscheduling the cron.
10 */
11 class Llms_Txt_Cron_Scheduler {
12
13 /**
14 * The name of the cron job.
15 */
16 public const LLMS_TXT_POPULATION = 'wpseo_llms_txt_population';
17
18 /**
19 * The options helper.
20 *
21 * @var Options_Helper
22 */
23 private $options_helper;
24
25 /**
26 * Constructor.
27 *
28 * @param Options_Helper $options_helper The options helper.
29 */
30 public function __construct(
31 Options_Helper $options_helper
32 ) {
33 $this->options_helper = $options_helper;
34 }
35
36 /**
37 * Schedules the llms txt population cron a week from now.
38 *
39 * @return void
40 */
41 public function schedule_weekly_llms_txt_population(): void {
42 if ( $this->options_helper->get( 'enable_llms_txt', false ) !== true ) {
43 return;
44 }
45
46 if ( ! \wp_next_scheduled( self::LLMS_TXT_POPULATION ) ) {
47 \wp_schedule_event( ( \time() + \WEEK_IN_SECONDS ), 'weekly', self::LLMS_TXT_POPULATION );
48 }
49 }
50
51 /**
52 * Schedules the llms txt population cron 5 minutes from now.
53 *
54 * @return void
55 */
56 public function schedule_quick_llms_txt_population(): void {
57 if ( $this->options_helper->get( 'enable_llms_txt', false ) !== true ) {
58 return;
59 }
60
61 if ( \wp_next_scheduled( self::LLMS_TXT_POPULATION ) ) {
62 $this->unschedule_llms_txt_population();
63 }
64
65 \wp_schedule_event( ( \time() + ( \MINUTE_IN_SECONDS * 5 ) ), 'weekly', self::LLMS_TXT_POPULATION );
66 }
67
68 /**
69 * Unschedules the llms txt population cron.
70 *
71 * @return void
72 */
73 public function unschedule_llms_txt_population() {
74 $scheduled = \wp_next_scheduled( self::LLMS_TXT_POPULATION );
75 if ( $scheduled ) {
76 \wp_unschedule_event( $scheduled, self::LLMS_TXT_POPULATION );
77 }
78 }
79 }
80