Changeset 56994
- Timestamp:
- 10/24/2023 08:49:38 AM (14 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/layout.php
r56709 r56994 631 631 $class_names = array(); 632 632 $layout_definitions = wp_get_layout_definitions(); 633 $container_class = wp_unique_id( 'wp-container-' ); 633 634 /* 635 * Uses an incremental ID that is independent per prefix to make sure that 636 * rendering different numbers of blocks doesn't affect the IDs of other 637 * blocks. Makes the CSS class names stable across paginations 638 * for features like the enhanced pagination of the Query block. 639 */ 640 $container_class = wp_unique_prefixed_id( 641 'wp-container-' . sanitize_title( $block['blockName'] ) . '-layout-' 642 ); 634 643 635 644 // Set the correct layout type for blocks using legacy content width. -
trunk/src/wp-includes/functions.php
r56809 r56994 7832 7832 7833 7833 /** 7834 * Generates an incremental ID that is independent per each different prefix. 7835 * 7836 * It is similar to `wp_unique_id`, but each prefix has its own internal ID 7837 * counter to make each prefix independent from each other. The ID starts at 1 7838 * and increments on each call. The returned value is not universally unique, 7839 * but it is unique across the life of the PHP process and it's stable per 7840 * prefix. 7841 * 7842 * @since 6.4.0 7843 * 7844 * @param string $prefix Optional. Prefix for the returned ID. Default empty string. 7845 * @return string Incremental ID per prefix. 7846 */ 7847 function wp_unique_prefixed_id( $prefix = '' ) { 7848 static $id_counters = array(); 7849 7850 if ( ! is_string( $prefix ) ) { 7851 wp_trigger_error( 7852 __FUNCTION__, 7853 sprintf( 'The prefix must be a string. "%s" data type given.', gettype( $prefix ) ) 7854 ); 7855 $prefix = ''; 7856 } 7857 7858 if ( ! isset( $id_counters[ $prefix ] ) ) { 7859 $id_counters[ $prefix ] = 0; 7860 } 7861 7862 $id = ++$id_counters[ $prefix ]; 7863 7864 return $prefix . (string) $id; 7865 } 7866 7867 /** 7834 7868 * Gets last changed date for the specified cache group. 7835 7869 * -
trunk/tests/phpunit/tests/blocks/render.php
r56547 r56994 219 219 $html = do_blocks( self::strip_r( file_get_contents( $html_path ) ) ); 220 220 // If blocks opt into Gutenberg's layout implementation 221 // the container will receive an add ed classname of `wp_unique_id( 'wp-container-' )`221 // the container will receive an additional, unique classname based on "wp-container-[blockname]-layout" 222 222 // so we need to normalize the random id. 223 $normalized_html = preg_replace( '/wp-container- \d+/', 'wp-container-1', $html );223 $normalized_html = preg_replace( '/wp-container-[a-z-]+\d+/', 'wp-container-1', $html ); 224 224 225 225 // The gallery block uses a unique class name of `wp_unique_id( 'wp-block-gallery-' )`
Note: See TracChangeset
for help on using the changeset viewer.