options_helper = $options_helper; $this->file_system_adapter = $file_system_adapter; $this->markdown_builder = $markdown_builder; $this->permission_gate = $permission_gate; } /** * Runs the command. * * @return void */ public function handle() { if ( $this->permission_gate->is_managed_by_yoast_seo() ) { $content = $this->markdown_builder->render(); $content = $this->encode_content( $content ); $file_written = $this->file_system_adapter->set_file_content( $content ); if ( $file_written ) { // Maybe move this to a class if we need to handle this option more often. \update_option( self::CONTENT_HASH_OPTION, \md5( $content ) ); \delete_option( self::GENERATION_FAILURE_OPTION ); return; } \update_option( self::GENERATION_FAILURE_OPTION, 'filesystem_permissions' ); return; } \update_option( self::GENERATION_FAILURE_OPTION, 'not_managed_by_yoast_seo' ); } /** * Encodes the content by prepending it with the Byte Order Mark (BOM) for UTF-8. * * @param string $content The content to encode. * * @return string */ private function encode_content( string $content ): string { /** * Filter: 'wpseo_llmstxt_encoding_prefix' - Allows editing the Byte Order Mark (BOM) for UTF-8 we prepend to the llmst.txt file. * * @param string $encoding_prefix The Byte Order Mark (BOM) for UTF-8 we prepend to the llmst.txt file. */ $encoding_prefix = \apply_filters( 'wpseo_llmstxt_encoding_prefix', "\xEF\xBB\xBF" ); return $encoding_prefix . $content; } }