Dev Resources

  • Home
  • Reference
  • BuddyX Theme
  • Functions
  • Hooks
  • Classes
Filter by type:
Search
Browse: Home / Reference / Classes / WC_Email / WC_Email::style_inline()

WC_Email::style_inline( string|null $content )

Apply inline styles to dynamic content.

Contents

  • Description
    • Parameters
    • Return
    • Source
  • Related
    • Uses
    • Used By
  • User Contributed Notes

Description #Description

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


Parameters #Parameters

$content

(Required) Content that will receive inline styles.


Top ↑

Return #Return

(string)


Top ↑

Source #Source

File: includes/emails/class-wc-email.php

	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 );

			$emogrifier_class = 'Pelago\\Emogrifier';

			if ( $this->supports_emogrifier() && class_exists( $emogrifier_class ) ) {
				try {
					$emogrifier = new $emogrifier_class( $content, $css );

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

					$content    = $emogrifier->emogrify();
					$html_prune = \Pelago\Emogrifier\HtmlProcessor\HtmlPruner::fromHtml( $content );
					$html_prune->removeElementsWithDisplayNone();
					$content    = $html_prune->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;
	}

Expand full source code Collapse full source code


Top ↑

Related #Related

Top ↑

Uses #Uses

Uses
Uses Description
includes/emails/class-wc-email.php: WC_Email::supports_emogrifier()

Return if emogrifier library is supported.

includes/emails/class-wc-email.php: WC_Email::get_content_type()

Get email content type.

includes/wc-core-functions.php: wc_get_logger()

Get a shared logger instance.

includes/wc-core-functions.php: wc_get_template()

Get other templates (e.g. product attributes) passing attributes and including the file.

Top ↑

Used By #Used By

Used By
Used By Description
includes/emails/class-wc-email.php: WC_Email::send()

Send an email.


Top ↑

User Contributed Notes #User Contributed Notes

You must log in before being able to contribute a note or feedback.

Proudly powered by WordPress