wp/wp-includes/blocks/legacy-widget.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/blocks/legacy-widget.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/blocks/legacy-widget.php	Tue Sep 27 16:37:53 2022 +0200
@@ -24,21 +24,9 @@
 		return '';
 	}
 
-	$id_base = $attributes['idBase'];
-	if ( method_exists( $wp_widget_factory, 'get_widget_key' ) && method_exists( $wp_widget_factory, 'get_widget_object' ) ) {
-		$widget_key    = $wp_widget_factory->get_widget_key( $id_base );
-		$widget_object = $wp_widget_factory->get_widget_object( $id_base );
-	} else {
-		/*
-		 * This file is copied from the published @wordpress/widgets package when WordPress
-		 * Core is built. Because the package is a dependency of both WordPress Core and the
-		 * Gutenberg plugin where the block editor is developed, this fallback condition is
-		 * required until the minimum required version of WordPress for the plugin is raised
-		 * to 5.8.
-		 */
-		$widget_key    = gutenberg_get_widget_key( $id_base );
-		$widget_object = gutenberg_get_widget_object( $id_base );
-	}
+	$id_base       = $attributes['idBase'];
+	$widget_key    = $wp_widget_factory->get_widget_key( $id_base );
+	$widget_object = $wp_widget_factory->get_widget_object( $id_base );
 
 	if ( ! $widget_key || ! $widget_object ) {
 		return '';
@@ -108,6 +96,33 @@
 				padding: 0 !important;
 				margin: 0 !important;
 			}
+
+			/* Hide root level text nodes */
+			body {
+				font-size: 0 !important;
+			}
+
+			/* Hide non-widget elements */
+			body *:not(#page):not(#content):not(.widget):not(.widget *) {
+				display: none !important;
+				font-size: 0 !important;
+				height: 0 !important;
+				left: -9999px !important;
+				max-height: 0 !important;
+				max-width: 0 !important;
+				opacity: 0 !important;
+				pointer-events: none !important;
+				position: absolute !important;
+				top: -9999px !important;
+				transform: translate(-9999px, -9999px) !important;
+				visibility: hidden !important;
+				z-index: -999 !important;
+			}
+
+			/* Restore widget font-size */
+			.widget {
+				font-size: var(--global--font-size-base);
+			}
 		</style>
 	</head>
 	<body <?php body_class(); ?>>