PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.6
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 / user-interface / llms-txt-cron-callback-integration.php

llms-txt-cron-callback-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/llms-txt/user-interface/llms-txt-cron-callback-integration.php

102 lines 2.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\Llms_Txt\User_Interface;
4
5 use Yoast\WP\SEO\Conditionals\No_Conditionals;
6 use Yoast\WP\SEO\Helpers\Options_Helper;
7 use Yoast\WP\SEO\Integrations\Integration_Interface;
8 use Yoast\WP\SEO\Llms_Txt\Application\File\Commands\Populate_File_Command_Handler;
9 use Yoast\WP\SEO\Llms_Txt\Application\File\Commands\Remove_File_Command_Handler;
10 use Yoast\WP\SEO\Llms_Txt\Application\File\Llms_Txt_Cron_Scheduler;
11
12 /**
13 * Cron Callback integration. This handles the actual process of populating the llms.txt on a cron trigger.
14 */
15 class Llms_Txt_Cron_Callback_Integration implements Integration_Interface {
16
17 use No_Conditionals;
18
19 /**
20 * The remove file command handler.
21 *
22 * @var Remove_File_Command_Handler
23 */
24 private $remove_file_command_handler;
25
26 /**
27 * The Create Populate Command Handler.
28 *
29 * @var Populate_File_Command_Handler
30 */
31 private $populate_file_command_handler;
32
33 /**
34 * The options helper.
35 *
36 * @var Options_Helper
37 */
38 private $options_helper;
39
40 /**
41 * The scheduler.
42 *
43 * @var Llms_Txt_Cron_Scheduler
44 */
45 private $scheduler;
46
47 /**
48 * Constructor.
49 *
50 * @param Options_Helper $options_helper The options helper.
51 * @param Llms_Txt_Cron_Scheduler $scheduler The scheduler.
52 * @param Populate_File_Command_Handler $populate_file_command_handler The populate file command handler.
53 * @param Remove_File_Command_Handler $remove_file_command_handler The remove file command handler.
54 */
55 public function __construct(
56 Options_Helper $options_helper,
57 Llms_Txt_Cron_Scheduler $scheduler,
58 Populate_File_Command_Handler $populate_file_command_handler,
59 Remove_File_Command_Handler $remove_file_command_handler
60 ) {
61 $this->options_helper = $options_helper;
62 $this->scheduler = $scheduler;
63 $this->populate_file_command_handler = $populate_file_command_handler;
64 $this->remove_file_command_handler = $remove_file_command_handler;
65 }
66
67 /**
68 * Registers the hooks with WordPress.
69 *
70 * @return void
71 */
72 public function register_hooks() {
73 \add_action(
74 Llms_Txt_Cron_Scheduler::LLMS_TXT_POPULATION,
75 [
76 $this,
77 'populate_file',
78 ],
79 );
80 }
81
82 /**
83 * Populates and creates the file.
84 *
85 * @return void
86 */
87 public function populate_file(): void {
88 if ( ! \wp_doing_cron() ) {
89 return;
90 }
91
92 if ( $this->options_helper->get( 'enable_llms_txt', false ) !== true ) {
93 $this->scheduler->unschedule_llms_txt_population();
94 $this->remove_file_command_handler->handle();
95
96 return;
97 }
98
99 $this->populate_file_command_handler->handle();
100 }
101 }
102