• 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/infrastructure/file/wordpress-llms-txt-permission-gate.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
3
namespace Yoast\WP\SEO\Llms_Txt\Infrastructure\File;
4

5
use Yoast\WP\SEO\Helpers\Options_Helper;
6
use Yoast\WP\SEO\Llms_Txt\Domain\File\Llms_Txt_Permission_Gate_Interface;
7

8
/**
9
 * Handles checks to see if we manage the llms.txt file.
10
 */
11
class WordPress_Llms_Txt_Permission_Gate implements Llms_Txt_Permission_Gate_Interface {
12

13
        /**
14
         * The file system adapter.
15
         *
16
         * @var WordPress_File_System_Adapter
17
         */
18
        private $file_system_adapter;
19

20
        /**
21
         * The options helper.
22
         *
23
         * @var Options_Helper
24
         */
25
        private $options_helper;
26

27
        /**
28
         * Constructor.
29
         *
30
         * @param WordPress_File_System_Adapter $file_system_adapter The file system adapter.
31
         * @param Options_Helper                $options_helper      The options helper.
32
         */
NEW
33
        public function __construct(
×
34
                WordPress_File_System_Adapter $file_system_adapter,
35
                Options_Helper $options_helper
36
        ) {
NEW
37
                $this->file_system_adapter = $file_system_adapter;
×
NEW
38
                $this->options_helper      = $options_helper;
×
39
        }
40

41
        /**
42
         * Checks if Yoast SEO manages the llms.txt.
43
         *
44
         * @return bool Checks if Yoast SEO manages the llms.txt.
45
         */
NEW
46
        public function is_managed_by_yoast_seo(): bool {
×
NEW
47
                $stored_hash = \get_option( 'wpseo_llms_txt_content_hash', '' );
×
48

49
                // If the file does not exist yet, we always regenerate/create it.
NEW
50
                if ( ! $this->file_system_adapter->file_exists() ) {
×
NEW
51
                        return true;
×
52
                }
53

54
                // This means the file is already there (maybe hand made or another plugin created it). And since we don't have a hash it's not ours.
NEW
55
                if ( $stored_hash === '' ) {
×
NEW
56
                        return false;
×
57
                }
58

NEW
59
                $current_content = $this->file_system_adapter->get_file_contents();
×
60

61
                // If you have a hash, we want to make sure it's the same. This check makes sure the file is not edited by the user.
NEW
62
                return \md5( $current_content ) === $stored_hash;
×
63
        }
64
}
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