Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer
Content_Renderer::inline_styles
Method to inline styles into the HTML
Метод класса: Content_Renderer{}
Хуки из метода
Возвращает
Строку
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->inline_styles( $html, $post, $template );
- $html(строка) (обязательный)
- HTML content.
- $post(WP_Post) (обязательный)
- Post object.
- $template(WP_Block_Template|null)
- Block template.
По умолчанию: null
Код Content_Renderer::inline_styles() Content Renderer::inline styles WC 10.0.2
private function inline_styles( $html, WP_Post $post, $template = null ) { $styles = (string) file_get_contents( __DIR__ . '/' . self::CONTENT_STYLES_FILE ); $styles .= (string) file_get_contents( __DIR__ . '/../../content-shared.css' ); // Apply default contentWidth to constrained blocks. $layout = $this->theme_controller->get_layout_settings(); $styles .= sprintf( ' .is-layout-constrained > *:not(.alignleft):not(.alignright):not(.alignfull) { max-width: %1$s; margin-left: auto !important; margin-right: auto !important; } .is-layout-constrained > .alignwide { max-width: %2$s; margin-left: auto !important; margin-right: auto !important; } ', $layout['contentSize'], $layout['wideSize'] ); // Get styles from theme. $styles .= $this->theme_controller->get_stylesheet_for_rendering( $post, $template ); $block_support_styles = $this->theme_controller->get_stylesheet_from_context( 'block-supports', array() ); // Get styles from block-supports stylesheet. This includes rules such as layout (contentWidth) that some blocks use. // @see https://github.com/WordPress/WordPress/blob/3c5da9c74344aaf5bf8097f2e2c6a1a781600e03/wp-includes/script-loader.php#L3134 // @internal :where is not supported by emogrifier, so we need to replace it with *. $block_support_styles = str_replace( ':where(:not(.alignleft):not(.alignright):not(.alignfull))', '*:not(.alignleft):not(.alignright):not(.alignfull)', $block_support_styles ); /* * Layout CSS assumes the top level block will have a single DIV wrapper with children. Since our blocks use tables, * we need to adjust this to look for children in the TD element. This may requires more advanced replacement but * this works in the current version of Gutenberg. * Example rule we're targetting: .wp-container-core-group-is-layout-1.wp-container-core-group-is-layout-1 > * */ $block_support_styles = preg_replace( '/group-is-layout-(\d+) >/', 'group-is-layout-$1 > tbody tr td >', $block_support_styles ); $styles .= $block_support_styles; /* * Debugging for content styles. Remember these get inlined. * echo '<pre>'; * var_dump($styles); * echo '</pre>'; */ $styles = '<style>' . wp_strip_all_tags( (string) apply_filters( 'woocommerce_email_content_renderer_styles', $styles, $post ) ) . '</style>'; return $this->css_inliner->from_html( $styles . $html )->inline_css()->render(); }