$paths, 'llms' => $llms, 'full' => $full, 'message' => __( 'LLM index files generated successfully.', 'adct-llm-index' ), ); } private static function init_filesystem() { global $wp_filesystem; if ( ! empty( $wp_filesystem ) ) { return true; } require_once ABSPATH . 'wp-admin/includes/file.php'; return (bool) WP_Filesystem(); } private static function write_file( $filename, $content ) { $filename = sanitize_file_name( $filename ); $path = trailingslashit( ABSPATH ) . $filename; if ( ! self::init_filesystem() ) { return new WP_Error( 'adct_llms_filesystem_unavailable', __( 'Unable to access the filesystem.', 'adct-llm-index' ) ); } global $wp_filesystem; if ( ! $wp_filesystem->is_writable( ABSPATH ) && ! $wp_filesystem->exists( $path ) ) { return new WP_Error( 'adct_llms_not_writable', sprintf( /* translators: %s: file path */ __( 'Cannot write %s. Check filesystem permissions.', 'adct-llm-index' ), $path ) ); } if ( ! $wp_filesystem->put_contents( $path, $content, FS_CHMOD_FILE ) ) { return new WP_Error( 'adct_llms_write_failed', sprintf( /* translators: %s: file path */ __( 'Failed to write %s.', 'adct-llm-index' ), $path ) ); } return $path; } private static function maybe_patch_robots_comment() { $robots = trailingslashit( ABSPATH ) . 'robots.txt'; $line = '# LLM index: ' . home_url( '/llms.txt' ); if ( ! self::init_filesystem() ) { return; } global $wp_filesystem; if ( ! $wp_filesystem->exists( $robots ) || ! $wp_filesystem->is_writable( $robots ) ) { return; } $contents = (string) $wp_filesystem->get_contents( $robots ); if ( false !== strpos( $contents, 'llms.txt' ) ) { return; } $wp_filesystem->put_contents( $robots, rtrim( $contents ) . "\n" . $line . "\n", FS_CHMOD_FILE ); } public static function get_last_generated() { return array( 'llms' => get_option( self::META_LLMS, '' ), 'full' => get_option( self::META_FULL, '' ), ); } }