Make WordPress Core

Changeset 53013


Ignore:
Timestamp:
03/29/2022 01:07:07 PM (4 years 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.
Merges [53012] to the 5.9 branch.
See #55474.

Location:
branches/5.9
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/5.9

  • branches/5.9/src/wp-includes/block-supports/duotone.php

    r52769 r53013  
    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        );
  • branches/5.9/src/wp-includes/block-supports/elements.php

    r52748 r53013  
    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 ) {
  • branches/5.9/src/wp-includes/block-supports/layout.php

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

    r52264 r53013  
    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.