- Timestamp:
- 05/19/2026 09:05:27 AM (3 months ago)
- Location:
- branches/7.0
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/block-supports/custom-css.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/7.0
-
branches/7.0/src/wp-includes/block-supports/custom-css.php
r62300 r62376 13 13 * @param array $parsed_block The parsed block. 14 14 * @return array The same parsed block with custom CSS class name added if appropriate. 15 * 16 * @phpstan-param array{ 17 * blockName: string|null, 18 * attrs: array{ 19 * className?: string, 20 * style?: array{ 21 * css?: string, 22 * ... 23 * }, 24 * ... 25 * }, 26 * ... 27 * } $parsed_block 15 28 */ 16 29 function wp_render_custom_css_support_styles( $parsed_block ) { 30 $custom_css = $parsed_block['attrs']['style']['css'] ?? null; 31 if ( ! is_string( $custom_css ) || '' === trim( $custom_css ) ) { 32 return $parsed_block; 33 } 34 17 35 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] ); 18 19 36 if ( ! block_has_support( $block_type, 'customCSS', true ) ) { 20 return $parsed_block;21 }22 23 $custom_css = trim( $parsed_block['attrs']['style']['css'] ?? '' );24 25 if ( empty( $custom_css ) ) {26 37 return $parsed_block; 27 38 } … … 33 44 34 45 // Generate a unique class name for this block instance. 35 $class_name = wp_unique_id_from_values( $parsed_block, 'wp-custom-css-' ); 36 $updated_class_name = isset( $parsed_block['attrs']['className'] ) 37 ? $parsed_block['attrs']['className'] . " $class_name" 46 $class_name = wp_unique_id_from_values( $parsed_block, 'wp-custom-css-' ); 47 $existing_class_name = $parsed_block['attrs']['className'] ?? null; 48 $updated_class_name = is_string( $existing_class_name ) 49 ? "$existing_class_name $class_name" 38 50 : $class_name; 39 51 … … 69 81 * Applies the custom CSS class name to the block's rendered HTML. 70 82 * 71 * The class name is generated in `wp_render_custom_css_support_styles`83 * The class name is generated in {@see wp_render_custom_css_support_styles()} 72 84 * and stored in block attributes. This filter adds it to the actual markup. 73 85 * … … 77 89 * @param array $block Block object. 78 90 * @return string Filtered block content. 91 * 92 * @phpstan-param array{ 93 * attrs: array{ 94 * className?: string, 95 * ... 96 * }, 97 * ... 98 * } $block 79 99 */ 80 100 function wp_render_custom_css_class_name( $block_content, $block ) { 81 $class_string = $block['attrs']['className'] ?? ''; 82 preg_match( '/\bwp-custom-css-\S+\b/', $class_string, $matches ); 83 84 if ( empty( $matches ) ) { 101 $class_name_attr = $block['attrs']['className'] ?? null; 102 103 if ( ! is_string( $class_name_attr ) || ! str_contains( $class_name_attr, 'wp-custom-css-' ) ) { 104 return $block_content; 105 } 106 107 // Parse out the 'wp-custom-css-*' class name added by wp_render_custom_css_support_styles(). 108 $custom_class_name = null; 109 $token_delimiter = " \t\f\r\n"; 110 $class_token = strtok( $class_name_attr, $token_delimiter ); 111 while ( false !== $class_token ) { 112 if ( str_starts_with( $class_token, 'wp-custom-css-' ) ) { 113 $custom_class_name = $class_token; 114 break; 115 } 116 $class_token = strtok( $token_delimiter ); 117 } 118 if ( null === $custom_class_name ) { 85 119 return $block_content; 86 120 } … … 90 124 if ( $tags->next_tag() ) { 91 125 $tags->add_class( 'has-custom-css' ); 92 $tags->add_class( $ matches[0]);126 $tags->add_class( $custom_class_name ); 93 127 } 94 128
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)