diff --git src/wp-includes/blocks/legacy-widget.php src/wp-includes/blocks/legacy-widget.php
index 030aa88f56..d0e4132ac6 100644
--- src/wp-includes/blocks/legacy-widget.php
+++ src/wp-includes/blocks/legacy-widget.php
@@ -24,11 +24,10 @@ function render_block_core_legacy_widget( $attributes ) {
 		return '';
 	}
 
-	$id_base = $attributes['idBase'];
+	$id_base    = $attributes['idBase'];
+	$widget_key = '';
 	if ( method_exists( $wp_widget_factory, 'get_widget_key' ) ) {
 		$widget_key = $wp_widget_factory->get_widget_key( $id_base );
-	} else {
-		$widget_key = gutenberg_get_widget_key( $id_base );
 	}
 
 	if ( ! $widget_key ) {
diff --git src/wp-includes/class-wp-widget-factory.php src/wp-includes/class-wp-widget-factory.php
index 82eda94e3a..0f0e7ac46c 100644
--- src/wp-includes/class-wp-widget-factory.php
+++ src/wp-includes/class-wp-widget-factory.php
@@ -120,4 +120,22 @@ class WP_Widget_Factory {
 
 		return null;
 	}
+
+	/**
+	 * Returns the registered key for the given widget type.
+	 *
+	 * @since 5.8.0
+	 *
+	 * @param string $id_base Widget type ID.
+	 * @return string
+	 */
+	public function get_widget_key( $id_base ) {
+		foreach ( $this->widgets as $key => $widget_object ) {
+			if ( $widget_object->id_base === $id_base ) {
+				return $key;
+			}
+		}
+
+		return '';
+	}
 }
