Yoast\WP\SEO\Llms_Txt\Infrastructure\File

WordPress_Llms_Txt_Permission_Gate{}Yoast 1.0└─ Llms_Txt_Permission_Gate_Interface

Handles checks to see if we manage the llms.txt file.

Хуков нет.

Использование

$WordPress_Llms_Txt_Permission_Gate = new WordPress_Llms_Txt_Permission_Gate();
// use class methods

Методы

  1. public __construct(
  2. public is_managed_by_yoast_seo()

Код WordPress_Llms_Txt_Permission_Gate{} Yoast 28.3

class WordPress_Llms_Txt_Permission_Gate implements Llms_Txt_Permission_Gate_Interface {

	/**
	 * The file system adapter.
	 *
	 * @var WordPress_File_System_Adapter
	 */
	private $file_system_adapter;

	/**
	 * The options helper.
	 *
	 * @var Options_Helper
	 */
	private $options_helper;

	/**
	 * Constructor.
	 *
	 * @param WordPress_File_System_Adapter $file_system_adapter The file system adapter.
	 * @param Options_Helper                $options_helper      The options helper.
	 */
	public function __construct(
		WordPress_File_System_Adapter $file_system_adapter,
		Options_Helper $options_helper
	) {
		$this->file_system_adapter = $file_system_adapter;
		$this->options_helper      = $options_helper;
	}

	/**
	 * Checks if Yoast SEO manages the llms.txt.
	 *
	 * @return bool Checks if Yoast SEO manages the llms.txt.
	 */
	public function is_managed_by_yoast_seo(): bool {
		$stored_hash = \get_option( Populate_File_Command_Handler::CONTENT_HASH_OPTION, '' );

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

		// 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.
		if ( $stored_hash === '' ) {
			return false;
		}

		$current_content = $this->file_system_adapter->get_file_contents();

		// 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.
		return \md5( $current_content ) === $stored_hash;
	}
}