Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Image::add_style_to_element
Add style to the element.
Method of the class: Image{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->add_style_to_element( $block_content, $tag, $style ): string;
- $block_content(string) (required)
- Block content.
- $tag(array) (required)
- .
- $style(string) (required)
- Style to add.
Image::add_style_to_element() Image::add style to element code WC 10.6.2
private function add_style_to_element( $block_content, array $tag, string $style ): string {
$html = new \WP_HTML_Tag_Processor( $block_content );
if ( $html->next_tag( $tag ) ) {
/** @var string $element_style */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$element_style = $html->get_attribute( 'style' ) ?? '';
$element_style = ! empty( $element_style ) ? ( rtrim( $element_style, ';' ) . ';' ) : ''; // Adding semicolon if it's missing.
$element_style .= $style;
$html->set_attribute( 'style', esc_attr( $element_style ) );
$block_content = $html->get_updated_html();
}
return $block_content;
}