Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/wp-includes/block-supports/custom-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* @return array The same parsed block with custom CSS class name added if appropriate.
*/
function wp_render_custom_css_support_styles( $parsed_block ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] );
// Check if the custom CSS attribute even exists.
$custom_css = $parsed_block['attrs']['style']['css'] ?? '';

if ( ! block_has_support( $block_type, 'customCSS', true ) ) {
if ( empty( trim( $custom_css ) ) ) {
return $parsed_block;
}

$custom_css = trim( $parsed_block['attrs']['style']['css'] ?? '' );
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] );

if ( empty( $custom_css ) ) {
if ( ! block_has_support( $block_type, 'customCSS', true ) ) {
return $parsed_block;
}

Expand Down Expand Up @@ -79,6 +80,12 @@ function wp_enqueue_block_custom_css() {
*/
function wp_render_custom_css_class_name( $block_content, $block ) {
$class_string = $block['attrs']['className'] ?? '';

/* If there is no class string, there is no custom CSS class to add, so return early. */
if ( '' === $class_string ) {
return $block_content;
}

preg_match( '/\bwp-custom-css-\S+\b/', $class_string, $matches );

if ( empty( $matches ) ) {
Expand Down
Loading