| @@ -355,9 +355,8 @@ | ||
| 355 | 355 | $num_columns = ( $num_rows > 0 ) ? count( $this->table['data'][0] ) : 0; |
| 356 | 356 | |
| 357 | 357 | // Check if there are rows and columns in the table (might not be the case after removing hidden rows/columns!). |
| 358 | 358 | if ( 0 === $num_rows || 0 === $num_columns ) { |
| 359 | - /* translators: %s: Table ID */ | |
| 360 | 359 | $this->output = sprintf( __( '<!-- The table with the ID %s is empty! -->', 'tablepress' ), $this->table['id'] ); |
| 361 | 360 | return; |
| 362 | 361 | } |
| 363 | 362 | |
| @@ -478,9 +477,9 @@ | ||
| 478 | 477 | // Loop through rows in reversed order, to search for rowspan trigger keyword. |
| 479 | 478 | $row_idx = $this->last_row_idx; |
| 480 | 479 | |
| 481 | 480 | // Render the table footer rows, if there is at least one extra row. |
| 482 | - if ( $this->render_options['table_foot'] > 0 && $num_rows >= $this->render_options['table_head'] + $this->render_options['table_foot'] ) { | |
| 481 | + if ( $this->render_options['table_foot'] > 0 && $num_rows >= $this->render_options['table_head'] + $this->render_options['table_foot'] ) { // @phpstan-ignore greaterOrEqual.invalid (`table_head` and `table_foot` are integers.) | |
| 483 | 482 | $last_tbody_idx = $this->last_row_idx - $this->render_options['table_foot']; |
| 484 | 483 | while ( $row_idx > $last_tbody_idx ) { |
| 485 | 484 | $tfoot[] = $this->_render_row( $row_idx, 'th' ); |
| 486 | 485 | --$row_idx; |
| @@ -633,11 +632,10 @@ | ||
| 633 | 632 | // $css_classes might contain several classes in one array entry. |
| 634 | 633 | $css_classes = explode( ' ', implode( ' ', $css_classes ) ); |
| 635 | 634 | $css_classes = array_map( array( 'TablePress', 'sanitize_css_class' ), $css_classes ); |
| 636 | 635 | $css_classes = array_unique( $css_classes ); |
| 637 | - $css_classes = array_filter( $css_classes ); // Remove empty entries. | |
| 638 | - $css_classes = implode( ' ', $css_classes ); | |
| 639 | - if ( '' !== $css_classes ) { | |
| 636 | + $css_classes = trim( implode( ' ', $css_classes ) ); | |
| 637 | + if ( ! empty( $css_classes ) ) { | |
| 640 | 638 | $table_attributes['class'] = $css_classes; |
| 641 | 639 | } |
| 642 | 640 | |
| 643 | 641 | // ARIA label attributes. |
| @@ -667,9 +665,9 @@ | ||
| 667 | 665 | |
| 668 | 666 | // Legacy support for attributes that are not encouraged in HTML5. |
| 669 | 667 | foreach ( array( 'cellspacing', 'cellpadding', 'border' ) as $attribute ) { |
| 670 | 668 | if ( false !== $this->render_options[ $attribute ] ) { |
| 671 | - $table_attributes[ $attribute ] = (string) absint( $this->render_options[ $attribute ] ); | |
| 669 | + $table_attributes[ $attribute ] = (int) $this->render_options[ $attribute ]; | |
| 672 | 670 | } |
| 673 | 671 | } |
| 674 | 672 | |
| 675 | 673 | /** |
| @@ -703,12 +701,12 @@ | ||
| 703 | 701 | unset( $table_html ); // Unset the potentially large variable to free up memory. |
| 704 | 702 | |
| 705 | 703 | // name/description below table (HTML already generated above). |
| 706 | 704 | if ( $this->render_options['print_name'] && 'below' === $this->render_options['print_name_position'] ) { |
| 707 | - $output .= $print_name_html; | |
| 705 | + $output .= $print_name_html; // @phpstan-ignore variable.undefined (The variable is set above.) | |
| 708 | 706 | } |
| 709 | 707 | if ( $this->render_options['print_description'] && 'below' === $this->render_options['print_description_position'] ) { |
| 710 | - $output .= $print_description_html; | |
| 708 | + $output .= $print_description_html; // @phpstan-ignore variable.undefined (The variable is set above.) | |
| 711 | 709 | } |
| 712 | 710 | |
| 713 | 711 | /** |
| 714 | 712 | * Filters the generated HTML code for the table and HTML elements around it. |
| @@ -752,9 +750,10 @@ | ||
| 752 | 750 | // Invalid rowspan, so we set cell content from #rowspan# to empty. |
| 753 | 751 | $cell_content = ''; |
| 754 | 752 | } elseif ( $this->span_trigger['colspan'] === $cell_content ) { // There will be a colspan. |
| 755 | 753 | if ( ! ( |
| 756 | - ( 0 === $col_idx ) // No colspan inside first column. | |
| 754 | + ( ( 0 === $row_idx ) && 1 === $this->render_options['table_head'] && $this->render_options['use_datatables'] ) // Don't allow colspan inside a single row table head, as DataTables seems to have a bug here. | |
| 755 | + || ( 0 === $col_idx ) // No colspan inside first column. | |
| 757 | 756 | || ( 1 === $col_idx && $this->render_options['first_column_th'] ) // No colspan into first column head. |
| 758 | 757 | ) ) { |
| 759 | 758 | // Increase counter for colspan in this row. |
| 760 | 759 | ++$this->colspan[ $row_idx ]; |
| @@ -838,17 +837,13 @@ | ||
| 838 | 837 | */ |
| 839 | 838 | $tag_attributes = apply_filters( 'tablepress_cell_tag_attributes', $tag_attributes, $this->table['id'], $cell_content, $row_idx + 1, $col_idx + 1, $this->colspan[ $row_idx ], $this->rowspan[ $col_idx ] ); |
| 840 | 839 | $tag_attributes = $this->_attributes_array_to_string( $tag_attributes ); |
| 841 | 840 | |
| 842 | - if ( '' === $cell_content ) { | |
| 843 | - $cell_tag = 'td'; // For accessibility, empty cells should use `td` and not `th` tags. | |
| 844 | - } elseif ( $this->render_options['first_column_th'] && 0 === $col_idx ) { | |
| 845 | - $cell_tag = 'th'; // Non-empty cells in the first column should use `th` tags, if enabled. | |
| 846 | - } else { | |
| 847 | - $cell_tag = $tag; // Otherwise, use the tag that was passed in as the default for the row. | |
| 841 | + if ( $this->render_options['first_column_th'] && 0 === $col_idx ) { | |
| 842 | + $tag = 'th'; | |
| 848 | 843 | } |
| 849 | 844 | |
| 850 | - $row_cells[] = "<{$cell_tag}{$tag_attributes}>{$cell_content}</{$cell_tag}>"; | |
| 845 | + $row_cells[] = "<{$tag}{$tag_attributes}>{$cell_content}</{$tag}>"; | |
| 851 | 846 | $this->colspan[ $row_idx ] = 1; // Reset. |
| 852 | 847 | $this->rowspan[ $col_idx ] = 1; // Reset. |
| 853 | 848 | } |
| 854 | 849 | |
| @@ -1009,13 +1004,8 @@ | ||
| 1009 | 1004 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;{$rtl_direction} |
| 1010 | 1005 | } |
| 1011 | 1006 | p { |
| 1012 | 1007 | font-size: 13px; |
| 1013 | - } | |
| 1014 | - .preview { | |
| 1015 | - overflow-x: auto; | |
| 1016 | - overflow-y: hidden; | |
| 1017 | - scroll-behavior: smooth; | |
| 1018 | 1008 | } |
| 1019 | 1009 | {$default_css_minified} |
| 1020 | 1010 | </style> |
| 1021 | 1011 | CSS; |