Index: src/wp-includes/class-wp-user.php
===================================================================
--- src/wp-includes/class-wp-user.php	(revision 60000)
+++ src/wp-includes/class-wp-user.php	(working copy)
@@
 	public function for_site( $site_id = '' ) {
-		$this->caps   = array();
-		$this->cap_key = '';
-
-		$this->get_role_caps();
+		$this->caps    = array();
+		$this->cap_key = '';
+
+		// Delay loading role caps until actually needed.
+		$this->caps_lazy_loaded = false;
+	}
+
+	/**
+	 * Lazily load capability data for the user.
+	 *
+	 * @since 6.9.0
+	 */
+	protected function lazy_load_caps() {
+		if ( ! empty( $this->caps_lazy_loaded ) ) {
+			return;
+		}
+		$this->get_role_caps();
+		$this->caps_lazy_loaded = true;
 	}
 
 	/**
 	 * Sets the site to operate on. Defaults to the current site.
 	 *
 	 * @since 3.0.0
 	 *
 	 * @param int $site_id Site ID to operate on. Defaults to the current site.
 	 */
 	public function set_site_id( $site_id = '' ) {
 		$this->site_id = $site_id ? absint( $site_id ) : get_current_blog_id();
 	}
 
 	/**
 	 * Returns whether the current user has the specified capability.
 	 *
 	 * @since 2.0.0
 	 *
 	 * @param string $cap      Capability name.
 	 * @param mixed  ...$args  Optional further parameters, typically starting with an object ID.
 	 * @return bool Whether the current user has the given capability.
 	 */
 	public function has_cap( $cap, ...$args ) {
+		// Ensure capabilities are loaded before checking.
+		if ( empty( $this->caps_lazy_loaded ) ) {
+			$this->lazy_load_caps();
+		}
 		$args = array_merge( array( $cap ), $args );
 		$caps = call_user_func_array( 'map_meta_cap', array_merge( array( $cap, $this->ID ), $args ) );
 
 		// Must have ALL requested caps.
 		foreach ( $caps as $capability ) {
 			if ( empty( $this->allcaps[ $capability ] ) ) {
 				return false;
 			}
 		}
 
 		return true;
 	}
