Skip to content

Commit

Permalink
Editor: Use wp_unique_id() instead of uniqid() to generate CSS cl…
Browse files Browse the repository at this point in the history
…ass names.

Backports changes from WordPress/gutenberg#38891.
See WordPress/gutenberg#38889.

Props westonruter, mamaduka.
Merges [53012] to the 5.9 branch.
See #55474.

Built from https://develop.svn.wordpress.org/branches/5.9@53013


git-svn-id: https://core.svn.wordpress.org/branches/5.9@52602 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
audrasjb committed Mar 29, 2022
1 parent 1f16dc1 commit c681ef6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion wp-includes/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ function wp_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 = wp_get_duotone_filter_property( $filter_preset );
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function wp_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.
Expand Down
8 changes: 4 additions & 4 deletions wp-includes/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ function wp_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 = wp_get_layout_style( ".wp-container-$id", $used_layout, $has_block_gap_support, $gap_value );
$style = wp_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
);
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9.3-alpha-53009';
$wp_version = '5.9.3-alpha-53013';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit c681ef6

Please sign in to comment.