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 / infrastructure / file / wordpress-llms-txt-permission-gate.php

wordpress-llms-txt-permission-gate.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.7, at src/llms-txt/infrastructure/file/wordpress-llms-txt-permission-gate.php

67 lines 1.9 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\Infrastructure\File;
5
6 use Yoast\WP\SEO\Helpers\Options_Helper;
7 use Yoast\WP\SEO\Llms_Txt\Application\File\Commands\Populate_File_Command_Handler;
8 use Yoast\WP\SEO\Llms_Txt\Domain\File\Llms_Txt_Permission_Gate_Interface;
9
10 /**
11 * Handles checks to see if we manage the llms.txt file.
12 */
13 class WordPress_Llms_Txt_Permission_Gate implements Llms_Txt_Permission_Gate_Interface {
14
15 /**
16 * The file system adapter.
17 *
18 * @var WordPress_File_System_Adapter
19 */
20 private $file_system_adapter;
21
22 /**
23 * The options helper.
24 *
25 * @var Options_Helper
26 */
27 private $options_helper;
28
29 /**
30 * Constructor.
31 *
32 * @param WordPress_File_System_Adapter $file_system_adapter The file system adapter.
33 * @param Options_Helper $options_helper The options helper.
34 */
35 public function __construct(
36 WordPress_File_System_Adapter $file_system_adapter,
37 Options_Helper $options_helper
38 ) {
39 $this->file_system_adapter = $file_system_adapter;
40 $this->options_helper = $options_helper;
41 }
42
43 /**
44 * Checks if Yoast SEO manages the llms.txt.
45 *
46 * @return bool Checks if Yoast SEO manages the llms.txt.
47 */
48 public function is_managed_by_yoast_seo(): bool {
49 $stored_hash = \get_option( Populate_File_Command_Handler::CONTENT_HASH_OPTION, '' );
50
51 // If the file does not exist yet, we always regenerate/create it.
52 if ( ! $this->file_system_adapter->file_exists() ) {
53 return true;
54 }
55
56 // 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.
57 if ( $stored_hash === '' ) {
58 return false;
59 }
60
61 $current_content = $this->file_system_adapter->get_file_contents();
62
63 // 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.
64 return \md5( $current_content ) === $stored_hash;
65 }
66 }
67