exists( $path ) ) { return null; } $contents = $filesystem->get_contents( $path ); return is_string( $contents ) ? $contents : null; } private static function write_file( string $path, string $body ): bool { $filesystem = self::filesystem(); if ( null === $filesystem ) { return false; } $directory = dirname( $path ); if ( ! $filesystem->is_dir( $directory ) && ! wp_mkdir_p( $directory ) ) { return false; } return (bool) $filesystem->put_contents( $path, $body, FS_CHMOD_FILE ); } public static function remove_llms_txt_file(): void { $path = self::get_llms_txt_path(); if ( file_exists( $path ) && self::is_plugin_owned_llms_file( $path ) ) { Agentmatica_Compatibility::delete_path_if_exists( $path ); } } public static function remove_ucp_profile_file(): void { if ( get_option( self::MANAGES_UCP_FILE_OPTION, '0' ) !== '1' ) { return; } Agentmatica_Compatibility::delete_path_if_exists( self::get_ucp_profile_path() ); delete_option( self::MANAGES_UCP_FILE_OPTION ); } public static function cleanup(): void { self::remove_llms_txt_file(); self::remove_ucp_profile_file(); self::remove_htaccess_rules(); } private static function is_plugin_owned_llms_file( string $path ): bool { $contents = self::read_file( $path ); if ( null === $contents ) { return false; } return strncmp( $contents, self::LLMS_MARKER, strlen( self::LLMS_MARKER ) ) === 0; } private static function sync_htaccess_rules(): void { if ( ! Agentmatica_Compatibility::load_htaccess_admin_includes() ) { return; } $home_path = Agentmatica_Compatibility::get_wordpress_home_path(); $rules = array( '', 'RewriteEngine On', ); if ( Agentmatica_Llms_Txt::is_enabled() ) { $rules[] = 'RewriteRule ^llms\.txt$ index.php?agentmatica_llms_txt=1 [L,QSA]'; } $rules[] = 'RewriteRule ^\.well-known/ucp/?$ index.php?agentmatica_ucp_profile=1 [L,QSA]'; $rules[] = ''; insert_with_markers( $home_path . '.htaccess', self::HTACCESS_MARKER, $rules ); } private static function remove_htaccess_rules(): void { if ( ! Agentmatica_Compatibility::load_htaccess_admin_includes() ) { return; } $home_path = Agentmatica_Compatibility::get_wordpress_home_path(); if ( ! file_exists( $home_path . '.htaccess' ) ) { return; } insert_with_markers( $home_path . '.htaccess', self::HTACCESS_MARKER, array() ); } }