Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Table::apply_styles_to_table_elementprivateWC 1.0

Apply CSS styles directly to the table element.

Method of the class: Table{}

No Hooks.

Returns

String. Table content with styles applied.

Usage

// private - for code of main (parent) class only
$result = $this->apply_styles_to_table_element( $table_content, $styles ): string;
$table_content(string) (required)
Table HTML content.
$styles(string) (required)
CSS styles to apply.

Table::apply_styles_to_table_element() code WC 10.4.3

private function apply_styles_to_table_element( string $table_content, string $styles ): string {
	$html = new \WP_HTML_Tag_Processor( $table_content );
	if ( $html->next_tag( array( 'tag_name' => 'TABLE' ) ) ) {
		$existing_style = (string) ( $html->get_attribute( 'style' ) ?? '' );
		$existing_style = rtrim( $existing_style, "; \t\n\r\0\x0B" );

		// Add default border widths if individual border colors are present but no widths.
		$border_width_styles = $this->get_default_border_widths( $existing_style );

		$new_style = $existing_style;
		if ( ! empty( $border_width_styles ) ) {
			$new_style = $new_style ? $new_style . '; ' . $border_width_styles : $border_width_styles;
		}
		if ( ! empty( $styles ) ) {
			$new_style = $new_style ? $new_style . '; ' . $styles : $styles;
		}

		$html->set_attribute( 'style', $new_style );
		return $html->get_updated_html();
	}
	return $table_content;
}