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

Yoast / wordpress-seo / e2f53222cf97fe912f41d61152981b5b595f5500

01 Jul 2025 09:02AM UTC coverage: 53.694% (+0.9%) from 52.787%
e2f53222cf97fe912f41d61152981b5b595f5500

push

github

YoastBot
Bump version to 25.4 on free

8218 of 14291 branches covered (57.5%)

Branch coverage included in aggregate %.

30333 of 57507 relevant lines covered (52.75%)

41519.48 hits per line

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

0.0
/src/llms-txt/infrastructure/file/wordpress-file-system-adapter.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\Llms_Txt\Domain\File\Llms_File_System_Interface;
6

7
/**
8
 * Adapter class for handling file system operations in a WordPress environment.
9
 */
10
class WordPress_File_System_Adapter implements Llms_File_System_Interface {
11

12
        /**
13
         * Creates a file and writes the specified content to it.
14
         *
15
         * @param string $content The content to write into the file.
16
         *
17
         * @return bool True on success, false on failure.
18
         */
19
        public function set_file_content( string $content ): bool {
×
20
                if ( $this->is_file_system_available() ) {
×
21
                        global $wp_filesystem;
×
22
                        $result = $wp_filesystem->put_contents(
×
23
                                $this->get_llms_file_path(),
×
24
                                $content,
×
25
                                \FS_CHMOD_FILE
×
26
                        );
×
27

28
                        return $result;
×
29
                }
30

31
                return false;
×
32
        }
33

34
        /**
35
         * Removes the llms.txt from the filesystem.
36
         *
37
         * @return bool True on success, false on failure.
38
         */
39
        public function remove_file(): bool {
×
40
                if ( $this->is_file_system_available() ) {
×
41
                        global $wp_filesystem;
×
42
                        $result = $wp_filesystem->delete( $this->get_llms_file_path() );
×
43

44
                        return $result;
×
45
                }
46

47
                return false;
×
48
        }
49

50
        /**
51
         * Gets the contents of the current llms.txt file.
52
         *
53
         * @return string The content of the file.
54
         */
55
        public function get_file_contents(): string {
×
56
                if ( $this->is_file_system_available() ) {
×
57
                        global $wp_filesystem;
×
58

59
                        return $wp_filesystem->get_contents( $this->get_llms_file_path() );
×
60
                }
61

62
                return '';
×
63
        }
64

65
        /**
66
         * Checks if the llms.txt file exists.
67
         *
68
         * @return bool Whether the llms.txt file exists.
69
         */
70
        public function file_exists(): bool {
×
71
                if ( $this->is_file_system_available() ) {
×
72
                        global $wp_filesystem;
×
73

74
                        return $wp_filesystem->exists( $this->get_llms_file_path() );
×
75
                }
76

77
                return false;
×
78
        }
79

80
        /**
81
         * Checks if the file system is available.
82
         *
83
         * @return bool If the file system is available.
84
         */
85
        private function is_file_system_available(): ?bool {
×
86
                if ( ! \function_exists( 'WP_Filesystem' ) ) {
×
87
                        require_once \ABSPATH . 'wp-admin/includes/file.php';
×
88
                }
89

90
                return \WP_Filesystem();
×
91
        }
92

93
        /**
94
         * Creates the path to the llms.txt file.
95
         *
96
         * @return string
97
         */
98
        private function get_llms_file_path(): string {
×
99

100
                $llms_filesystem_path = \get_home_path();
×
101

102
                // phpcs:disable WordPress.Security.ValidatedSanitizedInput -- Reason: This is how we used this for the robots.txt file as well.
103
                if ( ! \is_writable( $llms_filesystem_path ) && ! empty( $_SERVER['DOCUMENT_ROOT'] ) ) {
×
104
                        $llms_filesystem_path = $_SERVER['DOCUMENT_ROOT'];
×
105
                }
106
                // phpcs:enable WordPress.Security.ValidatedSanitizedInput
107

108
                /**
109
                 * Filter: 'wpseo_llmstxt_filesystem_path' - Allows editing the filesystem path of the llmst.txt file to account for server restrictions to the filesystem.
110
                 *
111
                 * @param string $llms_filesystem_path The filesystem path of the llmst.txt file that defaults to get_home_path() or the $_SERVER['DOCUMENT_ROOT'] if the home path is not writeable.
112
                 */
113
                $llms_filesystem_path = \apply_filters( 'wpseo_llmstxt_filesystem_path', $llms_filesystem_path );
×
114

115
                return \trailingslashit( $llms_filesystem_path ) . 'llms.txt';
×
116
        }
117
}
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