MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks

Image::remove_style_attribute_from_element()privateWC 1.0

Remove style attribute from the element.

Method of the class: Image{}

No Hooks.

Return

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() code WC 9.8.1

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( '/' . $style_name . ':(.?[0-9]+px)+;?/', '', $element_style );
		$html->set_attribute( 'style', esc_attr( strval( $element_style ) ) );
		$block_content = $html->get_updated_html();
	}

	return $block_content;
}