Commit b923246572 for wordpress.org

commit b92324657259969c741d9f7d06c812720629ed65
Author: SergeyBiryukov <sergeybiryukov@git.wordpress.org>
Date:   Thu Oct 22 20:30:56 2026 +0000

    Widgets: Avoid sidebar name collision in `dynamic_sidebar()`.

    This ensures that `dynamic_sidebar()` displays the correct sidebar when it has the same ID as the sanitized name of another sidebar registered earlier.

    An exact sidebar ID match is now prioritized over a sanitized name match, which may be less accurate.

    Developed in https://github.com/WordPress/wordpress-develop/pull/12166.

    Follow-up to r5474.

    Props sainathpoojary, wildworks, alexvorn2, markoheijnen, dilip2615, mosescursor, im3dabasia1, SergeyBiryukov.
    Fixes #22116.
    Built from https://develop.svn.wordpress.org/trunk@64681


    git-svn-id: http://core.svn.wordpress.org/trunk@63831 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/version.php b/wp-includes/version.php
index 8095e5622f..1040f6eb96 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-beta1-64680';
+$wp_version = '7.2-beta1-64681';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php
index d40a39ced0..31fce41b65 100644
--- a/wp-includes/widgets.php
+++ b/wp-includes/widgets.php
@@ -702,10 +702,13 @@ function dynamic_sidebar( $index = 1 ) {
 		$index = "sidebar-$index";
 	} else {
 		$index = sanitize_title( $index );
-		foreach ( (array) $wp_registered_sidebars as $key => $value ) {
-			if ( sanitize_title( $value['name'] ) === $index ) {
-				$index = $key;
-				break;
+
+		if ( empty( $wp_registered_sidebars[ $index ] ) ) {
+			foreach ( (array) $wp_registered_sidebars as $key => $value ) {
+				if ( sanitize_title( $value['name'] ) === $index ) {
+					$index = $key;
+					break;
+				}
 			}
 		}
 	}