Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Image::remove_style_attribute_from_element
Remove style attribute from the element.
Method of the class: Image{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->remove_style_attribute_from_element( $block_content, $tag, $style_name ): string;
- $block_content(string) (required)
- Block content.
- $tag(array) (required)
- .
- $style_name(string) (required)
- Name of the style to remove.
Image::remove_style_attribute_from_element() Image::remove style attribute from element code WC 10.6.2
private function remove_style_attribute_from_element( $block_content, array $tag, string $style_name ): 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 = preg_replace( '/' . preg_quote( $style_name, '/' ) . '\s*:\s*[^;]+;?/', '', $element_style );
$html->set_attribute( 'style', esc_attr( strval( $element_style ) ) );
$block_content = $html->get_updated_html();
}
return $block_content;
}