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

Image::add_style_to_element │ private │ WC 1.0

Add style to the element.

Метод класса: Image{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->add_style_to_element( $block_content, $tag, $style ): string;
$block_content(строка) (обязательный)
Block content.
$tag(array{tag_name: string, class_name?: string}) (обязательный)
Tag to add style to.
$style(строка) (обязательный)
Style to add.

Код Image::add_style_to_element() WC 11.2.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;
}