Skip to content

Commit

Permalink
Fixing an issue where the style tag in the table data block was not a…
Browse files Browse the repository at this point in the history
…llowed in a <tr> so was being moved around in <td>'s causing style inconsistencies.

Following blocks pro's direction in moving the celss style tag to the footer.

There's a corresponding commit in pro

https://stellarwp.atlassian.net/browse/KAD-3902
  • Loading branch information
mark-c-woodard committed Dec 3, 2024
1 parent 950940f commit 9bc37b5
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions includes/blocks/class-kadence-blocks-abstract-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ public function should_render_inline_stylesheet( $name ) {
}
}

/**
* Render styles in the footer.
*
* @param string $name the stylesheet name.
*/
public function render_styles_footer( $name, $css ) {
if ( ! is_admin() && ! wp_style_is( $name, 'done' ) && ! is_feed() ) {
wp_register_style( $name, false, array(), false );
wp_add_inline_style( $name, $css );
wp_enqueue_style( $name );
}
}

/**
* Check if block should render inline.
*
Expand Down Expand Up @@ -247,20 +260,31 @@ public function render_css( $attributes, $content, $block_instance ) {
if ( ! $css_class->has_styles( 'kb-' . $this->block_name . $unique_style_id ) && ! is_feed() && apply_filters( 'kadence_blocks_render_inline_css', true, $this->block_name, $unique_id ) ) {
$css = $this->build_css( $attributes, $css_class, $unique_id, $unique_style_id );
if ( ! empty( $css ) && ! wp_is_block_theme() ) {
$content = '<style>' . $css . '</style>' . $content;
$this->do_inline_styles( $content, $unique_style_id, $css );
}
} elseif ( ! wp_is_block_theme() && ! $css_class->has_header_styles( 'kb-' . $this->block_name . $unique_style_id ) && ! is_feed() && apply_filters( 'kadence_blocks_render_inline_css', true, $this->block_name, $unique_id ) ) {
// Some plugins run render block without outputing the content, this makes it so css can be rebuilt.
$css = $this->build_css( $attributes, $css_class, $unique_id, $unique_style_id );
if ( ! empty( $css ) ) {
$content = '<style>' . $css . '</style>' . $content;
$this->do_inline_styles( $content, $unique_style_id, $css );
}
}
}

return $content;
}

/**
* Potentially prepend inline style to the content, unless it needs to get moved off to the footer.
*/
public function do_inline_styles( &$content, $unique_style_id, $css ) {
if ( apply_filters( 'kadence_blocks_render_styles_footer', $this->block_name == 'data' || $this->block_name == 'slide' ) ) {
$this->render_styles_footer( 'kb-' . $this->block_name . $unique_style_id, $css );
} else {
$content = '<style>' . $css . '</style>' . $content;
}
}

/**
* Builds CSS for block.
*
Expand Down

0 comments on commit 9bc37b5

Please sign in to comment.