! empty( $attributes['enableSorting'] ), 'tableConditionalFormat' => is_array( $attributes['tableConditionalFormat'] ?? null ) ? $attributes['tableConditionalFormat'] : array(), 'mergeTableCell' => $attributes['mergeTableCell'] ?? array(), 'freezeSettings' => $attributes['freezeSettings'] ?? array(), 'blockClass' => $block_class, 'enableFreeze' => ! empty( $attributes['enableFreeze'] ), 'columnWidths' => $col_widths, 'rowHeights' => is_array( $attributes['rowHeights'] ?? null ) ? $attributes['rowHeights'] : array(), 'headerHeight' => absint( $attributes['headerHeight'] ?? 0 ), 'resizerEnabled' => isset( $attributes['resizerEnabled'] ) ? (bool) $attributes['resizerEnabled'] : true, 'mobileBreakpoint' => absint( $attributes['responsiveBreakpoint'] ?? 768 ), ); $figure_classes = trim( 'wp-block-tablebuilder-table-builder table-builder-block ' . $block_class ); $figure_id = ! empty( $block_id ) ? 'block-' . sanitize_html_class( $block_id ) : ''; $has_widths = ! empty( $col_widths ) && array_sum( array_map( 'floatval', $col_widths ) ) > 0; $table_style = $has_widths ? 'table-layout:fixed;width:100%;' : ''; $rendered_tbody = ''; if ( ! empty( $tbody_content ) ) { $rendered_tbody = wp_kses_post( $tbody_content ); } elseif ( ! empty( $row_blocks ) ) { $rendered_tbody = self::render_table_rows( $row_blocks ); } ob_start(); ?>
> > $header ) : ?> $footer ) : ?>
>
markup. */ private static function render_table_rows( array $row_blocks ): string { $output = ''; foreach ( $row_blocks as $row_block ) { if ( ( $row_block['blockName'] ?? '' ) !== 'tablebuilder/table-builder-row' ) { continue; } $row_class = trim( 'wp-block-tablebuilder-table-builder-row gkit-table__body-row ' . ( $row_block['attrs']['blockClass'] ?? '' ) ); $output .= ''; foreach ( $row_block['innerBlocks'] ?? array() as $item_block ) { if ( ( $item_block['blockName'] ?? '' ) !== 'tablebuilder/table-builder-item' ) { continue; } $item_class = trim( 'wp-block-tablebuilder-table-builder-item gkit-table__body-content ' . ( $item_block['attrs']['blockClass'] ?? '' ) ); $item_markup = self::render_nested_inner_blocks( $item_block['innerBlocks'] ?? array() ); $output .= '
' . $item_markup . '
'; } $output .= ''; } return $output; } /** * Renders nested inner blocks of a cell. * * @param array $blocks Parsed inner blocks to render via core's render_block(). * @return string Combined rendered HTML. */ private static function render_nested_inner_blocks( array $blocks ): string { $output = ''; foreach ( $blocks as $inner ) { $output .= render_block( $inner ); } return $output; } /** * Converts stored column widths into percentages for saved frontend parity. * * @param array $column_widths Stored column width values, keyed by column index. * @param int $index Column index to compute the style for. * @return string An inline "width:N%;" style, or an empty string if not applicable. */ private static function get_column_style( array $column_widths, int $index ): string { if ( empty( $column_widths[ $index ] ) ) { return ''; } $total_width = array_sum( array_map( 'floatval', $column_widths ) ); if ( $total_width <= 0 ) { return ''; } $percentage = ( (float) $column_widths[ $index ] / $total_width ) * 100; return 'width:' . round( $percentage, 4 ) . '%;'; } }