WC_Email::style_inline()publicWC 1.0

Apply inline styles to dynamic content.

We only inline CSS for html emails, and to do so we use Emogrifier library (if supported).

{} Это метод класса: WC_Email{}

Возвращает

Строку.

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

$WC_Email = new WC_Email();
$WC_Email->style_inline( $content );
$content(строка|null) (обязательный)
Content that will receive inline styles.

Код WC_Email::style_inline() WC 6.9.4

public function style_inline( $content ) {
	if ( in_array( $this->get_content_type(), array( 'text/html', 'multipart/alternative' ), true ) ) {
		ob_start();
		wc_get_template( 'emails/email-styles.php' );
		$css = apply_filters( 'woocommerce_email_styles', ob_get_clean(), $this );

		$css_inliner_class = CssInliner::class;

		if ( $this->supports_emogrifier() && class_exists( $css_inliner_class ) ) {
			try {
				$css_inliner = CssInliner::fromHtml( $content )->inlineCss( $css );

				do_action( 'woocommerce_emogrifier', $css_inliner, $this );

				$dom_document = $css_inliner->getDomDocument();

				HtmlPruner::fromDomDocument( $dom_document )->removeElementsWithDisplayNone();
				$content = CssToAttributeConverter::fromDomDocument( $dom_document )
					->convertCssToVisualAttributes()
					->render();
			} catch ( Exception $e ) {
				$logger = wc_get_logger();
				$logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) );
			}
		} else {
			$content = '<style type="text/css">' . $css . '</style>' . $content;
		}
	}

	return $content;
}