• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 481faf637ba3a7c1e5f2bfef59b582ac39523de6

21 May 2025 09:11AM UTC coverage: 46.174%. First build
481faf637ba3a7c1e5f2bfef59b582ac39523de6

Pull #22291

github

web-flow
Merge pull request #22278 from Yoast/577-sanitize-and-deal-with-special-markdown-characters-before-writing-to-file

577 sanitize and deal with special markdown characters before writing to file
Pull Request #22291: Introduce the llms.txt feature

52 of 403 new or added lines in 30 files covered. (12.9%)

15586 of 33755 relevant lines covered (46.17%)

3.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/llms-txt/user-interface/enable-llms-txt-option-watcher.php
1
<?php
2

3
namespace Yoast\WP\SEO\Llms_Txt\User_Interface;
4

5
use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait;
6
use Yoast\WP\SEO\Integrations\Integration_Interface;
7
use Yoast\WP\SEO\Llms_Txt\Application\File\Commands\Populate_File_Command_Handler;
8
use Yoast\WP\SEO\Llms_Txt\Application\File\Commands\Remove_File_Command_Handler;
9
use Yoast\WP\SEO\Llms_Txt\Application\File\Llms_Txt_Cron_Scheduler;
10

11
/**
12
 * Watches and handles changes to the LLMS.txt enabled option.
13
 */
14
class Enable_Llms_Txt_Option_Watcher implements Integration_Interface {
15

16
        use Admin_Conditional_Trait;
17

18
        /**
19
         * The scheduler.
20
         *
21
         * @var Llms_Txt_Cron_Scheduler
22
         */
23
        private $scheduler;
24

25
        /**
26
         * The remove file command handler.
27
         *
28
         * @var Remove_File_Command_Handler
29
         */
30
        private $remove_file_command_handler;
31

32
        /**
33
         * The populate file command handler.
34
         *
35
         * @var Populate_File_Command_Handler
36
         */
37
        private $populate_file_command_handler;
38

39
        /**
40
         * Constructor.
41
         *
42
         * @param Llms_Txt_Cron_Scheduler       $scheduler                     The cron scheduler.
43
         * @param Remove_File_Command_Handler   $remove_file_command_handler   The remove file command handler.
44
         * @param Populate_File_Command_Handler $populate_file_command_handler The populate file command handler.
45
         */
NEW
46
        public function __construct(
×
47
                Llms_Txt_Cron_Scheduler $scheduler,
48
                Remove_File_Command_Handler $remove_file_command_handler,
49
                Populate_File_Command_Handler $populate_file_command_handler
50
        ) {
NEW
51
                $this->scheduler                     = $scheduler;
×
NEW
52
                $this->remove_file_command_handler   = $remove_file_command_handler;
×
NEW
53
                $this->populate_file_command_handler = $populate_file_command_handler;
×
54
        }
55

56
        /**
57
         * Initializes the integration.
58
         *
59
         * This is the place to register hooks and filters.
60
         *
61
         * @return void
62
         */
NEW
63
        public function register_hooks() {
×
NEW
64
                \add_action( 'update_option_wpseo', [ $this, 'check_toggle_llms_txt' ], 10, 2 );
×
65
        }
66

67
        /**
68
         * Checks if the LLMS.txt feature is toggled.
69
         *
70
         * @param array<string|int|bool|array<string|int|bool>> $old_value The old value of the option.
71
         * @param array<string|int|bool|array<string|int|bool>> $new_value The new value of the option.
72
         *
73
         * @return void
74
         */
NEW
75
        public function check_toggle_llms_txt( $old_value, $new_value ): void {
×
NEW
76
                $option_name = 'enable_llms_txt';
×
77

NEW
78
                if ( \array_key_exists( $option_name, $old_value ) && \array_key_exists( $option_name, $new_value ) && $old_value[ $option_name ] !== $new_value[ $option_name ] ) {
×
NEW
79
                        if ( $new_value[ $option_name ] === true ) {
×
NEW
80
                                $this->scheduler->schedule_weekly_llms_txt_population();
×
NEW
81
                                $this->populate_file_command_handler->handle();
×
82
                        }
83
                        else {
NEW
84
                                $this->scheduler->unschedule_llms_txt_population();
×
NEW
85
                                $this->remove_file_command_handler->handle();
×
86
                        }
87
                }
88
        }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc