| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace TableBuilder\Shortcode; |
| 9 | 9 | |
| 10 | +use TableBuilder\Hooks\AssetGenerator; | |
| 10 | 11 | use TableBuilder\Shortcode\ShortcodeUtils; |
| 11 | 12 | use TableBuilder\Render\BlockRenderer; |
| 12 | 13 | use TableBuilder\Traits\Singleton; |
| 13 | 14 | |
| @@ -75,22 +76,31 @@ | ||
| 75 | 76 | public function render( $raw_atts, string $content = '' ): string { |
| 76 | 77 | $atts = $this->sanitize_atts( shortcode_atts( self::DEFAULT_ATTS, (array) $raw_atts, 'tableKit' ) ); |
| 77 | 78 | $ids = $this->parse_ids( $atts ); |
| 78 | 79 | |
| 80 | + // The shortcode prints its own table CSS, so the generic late-CSS | |
| 81 | + // printer (AssetGenerator) must not print it a second time. | |
| 82 | + $asset_generator = AssetGenerator::instance(); | |
| 83 | + $asset_generator->suspend_late_css(); | |
| 84 | + | |
| 79 | 85 | ob_start(); |
| 80 | 86 | |
| 81 | - if ( empty( $ids['block_id'] ) && empty( $ids['raw_id'] ) ) { | |
| 82 | - echo $this->render_all_blocks( $ids, $atts, $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from the_content filter output and esc_*()-escaped pieces, see render_all_blocks(). | |
| 83 | - return (string) ob_get_clean(); | |
| 84 | - } | |
| 87 | + try { | |
| 88 | + if ( empty( $ids['block_id'] ) && empty( $ids['raw_id'] ) ) { | |
| 89 | + echo $this->render_all_blocks( $ids, $atts, $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from the_content filter output and esc_*()-escaped pieces, see render_all_blocks(). | |
| 90 | + return (string) ob_get_clean(); | |
| 91 | + } | |
| 85 | 92 | |
| 86 | - $block = $this->locate_block( $ids['post_id'], $ids['block_id'], $ids['raw_id'] ); | |
| 93 | + $block = $this->locate_block( $ids['post_id'], $ids['block_id'], $ids['raw_id'] ); | |
| 87 | 94 | |
| 88 | - if ( ! empty( $block ) ) { | |
| 89 | - echo $this->render_single_block( $block, $atts, $ids, $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- delegates to BlockRenderer::render_table_builder(), which escapes/kses's its own output. | |
| 95 | + if ( ! empty( $block ) ) { | |
| 96 | + echo $this->render_single_block( $block, $atts, $ids, $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- delegates to BlockRenderer::render_table_builder(), which escapes/kses's its own output. | |
| 97 | + } | |
| 98 | + | |
| 99 | + return (string) ob_get_clean(); | |
| 100 | + } finally { | |
| 101 | + $asset_generator->resume_late_css(); | |
| 90 | 102 | } |
| 91 | - | |
| 92 | - return (string) ob_get_clean(); | |
| 93 | 103 | } |
| 94 | 104 | |
| 95 | 105 | // ------------------------------------------------------------------------- |
| 96 | 106 | // Multi-block rendering (no block_id given) |