diff --git a/lib/block-supports/duotone.php b/lib/block-supports/duotone.php index e5373e65600868..561ed126158675 100644 --- a/lib/block-supports/duotone.php +++ b/lib/block-supports/duotone.php @@ -434,7 +434,7 @@ function gutenberg_render_duotone_support( $block_content, $block ) { } $filter_preset = array( - 'slug' => uniqid(), + 'slug' => wp_unique_id( sanitize_key( implode( '-', $block['attrs']['style']['color']['duotone'] ) . '-' ) ), 'colors' => $block['attrs']['style']['color']['duotone'], ); $filter_property = gutenberg_get_duotone_filter_property( $filter_preset ); diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index 711631a63b6612..23f0426c3737b5 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -33,7 +33,7 @@ function gutenberg_render_elements_support( $block_content, $block ) { return $block_content; } - $class_name = 'wp-elements-' . uniqid(); + $class_name = wp_unique_id( 'wp-elements-' ); if ( strpos( $link_color, 'var:preset|color|' ) !== false ) { // Get the name from the string and add proper styles. diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 1e5916993e6658..3d4307b190a89a 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -148,18 +148,18 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { $used_layout = $default_layout; } - $id = uniqid(); - $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) ); + $class_name = wp_unique_id( 'wp-container-' ); + $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) ); // Skip if gap value contains unsupported characters. // Regex for CSS value borrowed from `safecss_filter_attr`, and used here // because we only want to match against the value, not the CSS attribute. $gap_value = preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value; - $style = gutenberg_get_layout_style( ".wp-container-$id", $used_layout, $has_block_gap_support, $gap_value ); + $style = gutenberg_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value ); // This assumes the hook only applies to blocks with a single wrapper. // I think this is a reasonable limitation for that particular hook. $content = preg_replace( '/' . preg_quote( 'class="', '/' ) . '/', - 'class="wp-container-' . $id . ' ', + 'class="' . esc_attr( $class_name ) . ' ', $block_content, 1 ); diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 2f4ad1045ad0c4..da318a2dfda316 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -23,7 +23,7 @@ function render_block_core_archives( $attributes ) { $class .= ' wp-block-archives-dropdown'; - $dropdown_id = esc_attr( uniqid( 'wp-block-archives-' ) ); + $dropdown_id = wp_unique_id( 'wp-block-archives-' ); $title = __( 'Archives' ); /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 6cb6eeacf0e368..d1419084255413 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -513,7 +513,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { ) ); - $modal_unique_id = uniqid(); + $modal_unique_id = wp_unique_id( 'modal-' ); // Determine whether or not navigation elements should be wrapped in the markup required to make it responsive, // return early if they don't. @@ -538,12 +538,12 @@ function render_block_core_navigation( $attributes, $content, $block ) { ); $responsive_container_markup = sprintf( - ' -