diff --git a/wp-includes/block-supports/layout.php b/wp-includes/block-supports/layout.php index 4c1f4c2fe7..0e22dded74 100644 --- a/wp-includes/block-supports/layout.php +++ b/wp-includes/block-supports/layout.php @@ -630,7 +630,16 @@ function wp_render_layout_support_flag( $block_content, $block ) { $class_names = array(); $layout_definitions = wp_get_layout_definitions(); - $container_class = wp_unique_id( 'wp-container-' ); + + /* + * Uses an incremental ID that is independent per prefix to make sure that + * rendering different numbers of blocks doesn't affect the IDs of other + * blocks. Makes the CSS class names stable across paginations + * for features like the enhanced pagination of the Query block. + */ + $container_class = wp_unique_prefixed_id( + 'wp-container-' . sanitize_title( $block['blockName'] ) . '-layout-' + ); // Set the correct layout type for blocks using legacy content width. if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) { diff --git a/wp-includes/functions.php b/wp-includes/functions.php index c467961c98..cb490ee176 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -7830,6 +7830,40 @@ function wp_unique_id( $prefix = '' ) { return $prefix . (string) ++$id_counter; } +/** + * Generates an incremental ID that is independent per each different prefix. + * + * It is similar to `wp_unique_id`, but each prefix has its own internal ID + * counter to make each prefix independent from each other. The ID starts at 1 + * and increments on each call. The returned value is not universally unique, + * but it is unique across the life of the PHP process and it's stable per + * prefix. + * + * @since 6.4.0 + * + * @param string $prefix Optional. Prefix for the returned ID. Default empty string. + * @return string Incremental ID per prefix. + */ +function wp_unique_prefixed_id( $prefix = '' ) { + static $id_counters = array(); + + if ( ! is_string( $prefix ) ) { + wp_trigger_error( + __FUNCTION__, + sprintf( 'The prefix must be a string. "%s" data type given.', gettype( $prefix ) ) + ); + $prefix = ''; + } + + if ( ! isset( $id_counters[ $prefix ] ) ) { + $id_counters[ $prefix ] = 0; + } + + $id = ++$id_counters[ $prefix ]; + + return $prefix . (string) $id; +} + /** * Gets last changed date for the specified cache group. * diff --git a/wp-includes/version.php b/wp-includes/version.php index d9ad5099a7..d3a4da59ad 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-56992'; +$wp_version = '6.5-alpha-56994'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.