Make WordPress Core

Changeset 53012


Ignore:
Timestamp:
03/29/2022 01:04:24 PM (14 months ago)
Author:
audrasjb
Message:

Editor: Use wp_unique_id() instead of uniqid() to generate CSS class names.

Backports changes from https://github.com/WordPress/gutenberg/pull/38891.
See https://github.com/WordPress/gutenberg/issues/38889.

Props westonruter, mamaduka.
See #55474.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/duotone.php

    r52768 r53012  
    521521
    522522    $filter_preset   = array(
    523         'slug'   => uniqid(),
     523        'slug'   => wp_unique_id( sanitize_key( implode( '-', $block['attrs']['style']['color']['duotone'] ) . '-' ) ),
    524524        'colors' => $block['attrs']['style']['color']['duotone'],
    525525    );
  • trunk/src/wp-includes/block-supports/elements.php

    r52743 r53012  
    3737    }
    3838
    39     $class_name = 'wp-elements-' . uniqid();
     39    $class_name = wp_unique_id( 'wp-elements-' );
    4040
    4141    if ( strpos( $link_color, 'var:preset|color|' ) !== false ) {
  • trunk/src/wp-includes/block-supports/layout.php

    r52924 r53012  
    159159    }
    160160
    161     $id        = uniqid();
    162     $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
     161    $class_name = wp_unique_id( 'wp-container-' );
     162    $gap_value  = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
    163163    // Skip if gap value contains unsupported characters.
    164164    // Regex for CSS value borrowed from `safecss_filter_attr`, and used here
    165165    // because we only want to match against the value, not the CSS attribute.
    166166    $gap_value = preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
    167     $style     = wp_get_layout_style( ".wp-container-$id", $used_layout, $has_block_gap_support, $gap_value );
     167    $style     = wp_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value );
    168168    // This assumes the hook only applies to blocks with a single wrapper.
    169169    // I think this is a reasonable limitation for that particular hook.
    170170    $content = preg_replace(
    171171        '/' . preg_quote( 'class="', '/' ) . '/',
    172         'class="wp-container-' . $id . ' ',
     172        'class="' . esc_attr( $class_name ) . ' ',
    173173        $block_content,
    174174        1
  • trunk/tests/phpunit/tests/block-supports/elements.php

    r52264 r53012  
    1212     */
    1313    private static function make_unique_id_one( $string ) {
    14         return preg_replace( '/wp-elements-.{13}/', 'wp-elements-1', $string );
     14        return preg_replace( '/wp-elements-\d+/', 'wp-elements-1', $string );
    1515    }
    1616
Note: See TracChangeset for help on using the changeset viewer.