Automattic\WooCommerce\EmailEditor\Engine\Renderer

Renderer::renderpublicWC 1.0

Renders the email template

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

Хуки из метода

Возвращает

Массив.

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

$Renderer = new Renderer();
$Renderer->render( $post, $subject, $pre_header, $language, $meta_robots, $template_slug ): array;
$post(WP_Post) (обязательный)
Post object.
$subject(строка) (обязательный)
Email subject.
$pre_header(строка) (обязательный)
An email preheader or preview text is the short snippet of text that follows the subject line in an inbox. See https://kb.mailpoet.com/article/418-preview-text.
$language(строка) (обязательный)
Email language.
$meta_robots(строка)
Optional string. Can be left empty for sending, but you can provide a value (e.g. noindex, nofollow) when you want to display email html in a browser.
По умолчанию: ''
$template_slug(строка)
Optional block template slug used for cases when email doesn't have associated template.
По умолчанию: ''

Код Renderer::render() WC 10.7.0

public function render( \WP_Post $post, string $subject, string $pre_header, string $language, string $meta_robots = '', string $template_slug = '' ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
	if ( ! $template_slug ) {
		$template_slug = get_page_template_slug( $post ) ? get_page_template_slug( $post ) : 'email-general';
	}
	/** @var \WP_Block_Template $template */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
	$template = $this->templates->get_block_template( $template_slug );

	$email_styles   = $this->theme_controller->get_styles();
	$content_result = $this->content_renderer->render_without_css_inline( $post, $template );
	$template_html  = $content_result['html'];
	$content_styles = $content_result['styles'];
	$layout         = $this->theme_controller->get_layout_settings();

	ob_start();
	include self::TEMPLATE_FILE;
	$rendered_template = (string) ob_get_clean();

	$template_styles  =
	WP_Style_Engine::compile_css(
		array(
			'background-color' => $email_styles['color']['background'] ?? 'inherit',
			'color'            => $email_styles['color']['text'] ?? 'inherit',
			'padding-top'      => $email_styles['spacing']['padding']['top'] ?? '0px',
			'padding-bottom'   => $email_styles['spacing']['padding']['bottom'] ?? '0px',
			'font-family'      => $email_styles['typography']['fontFamily'] ?? 'inherit',
			'line-height'      => $email_styles['typography']['lineHeight'] ?? '1.5',
			'font-size'        => $email_styles['typography']['fontSize'] ?? 'inherit',
		),
		'body, .email_layout_wrapper'
	);
	$template_styles .= '.email_layout_wrapper { box-sizing: border-box;}';
	$template_styles .= file_get_contents( __DIR__ . '/' . self::TEMPLATE_STYLES_FILE );
	$template_styles  = wp_strip_all_tags( (string) apply_filters( 'woocommerce_email_renderer_styles', $template_styles, $post ) );

	// Single CSS inlining pass: combine content and template styles, then inline all at once.
	$all_styles        = '<style>' . $template_styles . $content_styles . '</style>';
	$rendered_template = $this->inline_css_styles( $all_styles . $rendered_template );

	// Postprocess after CSS inlining (border normalization, CSS variable replacement, etc.).
	$rendered_template = $this->process_manager->postprocess( $rendered_template );

	// This is a workaround to support link :hover in some clients. Ideally we would remove the ability to set :hover
	// however this is not possible using the color panel from Gutenberg.
	if ( isset( $email_styles['elements']['link'][':hover']['color']['text'] ) ) {
		$rendered_template = str_replace( '<!-- Forced Styles -->', '<style>a:hover { color: ' . esc_attr( $email_styles['elements']['link'][':hover']['color']['text'] ) . ' !important; }</style>', $rendered_template );
	}

	return array(
		'html' => $rendered_template,
		'text' => $this->render_text_version( $rendered_template ),
	);
}