MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks
Image::addImageDimensions()
Settings width and height attributes for images is important for MS Outlook.
Method of the class: Image{}
No Hooks.
Return
null
. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->addImageDimensions( $block_content, $parsed_block, $settings_controller ): string;
- $block_content(string) (required)
- Block content.
- $parsed_block(array) (required)
- Parsed block.
- $settings_controller(Settings_Controller) (required)
- Settings controller.
Image::addImageDimensions() Image::addImageDimensions code WC 9.8.1
private function addImageDimensions( $block_content, array $parsed_block, Settings_Controller $settings_controller ): string { $html = new \WP_HTML_Tag_Processor( $block_content ); if ( $html->next_tag( array( 'tag_name' => 'img' ) ) ) { // Getting height from styles and if it's set, we set the height attribute. /** @var string $styles */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan $styles = $html->get_attribute( 'style' ) ?? ''; $styles = $settings_controller->parse_styles_to_array( $styles ); $height = $styles['height'] ?? null; if ( $height && 'auto' !== $height && is_numeric( $settings_controller->parse_number_from_string_with_pixels( $height ) ) ) { $height = $settings_controller->parse_number_from_string_with_pixels( $height ); /* @phpstan-ignore-next-line Wrong annotation for parameter in WP. */ $html->set_attribute( 'height', esc_attr( $height ) ); } if ( isset( $parsed_block['attrs']['width'] ) ) { $width = $settings_controller->parse_number_from_string_with_pixels( $parsed_block['attrs']['width'] ); /* @phpstan-ignore-next-line Wrong annotation for parameter in WP. */ $html->set_attribute( 'width', esc_attr( $width ) ); } $block_content = $html->get_updated_html(); } return $block_content; }