Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/EmailEdi...
File: WooContentProcessor.php
<?php
[0] Fix | Delete
declare( strict_types=1 );
[1] Fix | Delete
[2] Fix | Delete
namespace Automattic\WooCommerce\Internal\EmailEditor;
[3] Fix | Delete
[4] Fix | Delete
use Automattic\WooCommerce\EmailEditor\Email_Css_Inliner;
[5] Fix | Delete
use Automattic\WooCommerce\EmailEditor\Email_Editor_Container;
[6] Fix | Delete
use Automattic\WooCommerce\EmailEditor\Engine\Theme_Controller;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Class responsible for extracting the main content from a WC_Email object.
[10] Fix | Delete
*/
[11] Fix | Delete
class WooContentProcessor {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Email theme controller
[15] Fix | Delete
* We use it to get email CSS.
[16] Fix | Delete
*
[17] Fix | Delete
* @var Theme_Controller
[18] Fix | Delete
*/
[19] Fix | Delete
private $theme_controller;
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* CSS inliner
[23] Fix | Delete
*
[24] Fix | Delete
* @var Email_Css_Inliner
[25] Fix | Delete
*/
[26] Fix | Delete
private $css_inliner;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Constructor
[30] Fix | Delete
*/
[31] Fix | Delete
public function __construct() {
[32] Fix | Delete
$this->theme_controller = Email_Editor_Container::container()->get( Theme_Controller::class );
[33] Fix | Delete
$this->css_inliner = new Email_Css_Inliner();
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Get the WooCommerce content excluding headers and footers.
[38] Fix | Delete
*
[39] Fix | Delete
* @param \WC_Email $wc_email WooCommerce email.
[40] Fix | Delete
* @return string
[41] Fix | Delete
*/
[42] Fix | Delete
public function get_woo_content( \WC_Email $wc_email ): string {
[43] Fix | Delete
$woo_content = $this->capture_woo_content( $wc_email );
[44] Fix | Delete
$woo_content_with_css = $this->inline_css( $woo_content );
[45] Fix | Delete
return $this->get_html_body_content( $woo_content_with_css );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Filter CSS for the email.
[50] Fix | Delete
* The CSS was from email editor was already inlined.
[51] Fix | Delete
* The method hookes to woocommerce_email_styles and removes CSS rules that we don't want to apply to the email.
[52] Fix | Delete
*
[53] Fix | Delete
* @param string $css CSS.
[54] Fix | Delete
* @return string
[55] Fix | Delete
*/
[56] Fix | Delete
public function prepare_css( string $css ): string {
[57] Fix | Delete
remove_filter( 'woocommerce_email_styles', array( $this, 'prepare_css' ) );
[58] Fix | Delete
// Remove color and font-family declarations from WooCommerce CSS.
[59] Fix | Delete
$css = preg_replace( '/color\s*:\s*[^;]+;/', '', $css );
[60] Fix | Delete
$css = preg_replace( '/font-family\s*:\s*[^;]+;/', '', $css );
[61] Fix | Delete
return $css;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Get the content of the body tag from the HTML.
[66] Fix | Delete
*
[67] Fix | Delete
* @param string $html HTML.
[68] Fix | Delete
* @return string
[69] Fix | Delete
*/
[70] Fix | Delete
private function get_html_body_content( string $html ): string {
[71] Fix | Delete
// Extract content between <body> and </body> tags using regex.
[72] Fix | Delete
if ( preg_match( '/<body[^>]*>(.*?)<\/body>/is', $html, $matches ) ) {
[73] Fix | Delete
return $matches[1];
[74] Fix | Delete
}
[75] Fix | Delete
return $html;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Inline the CSS from the email theme and user email settings.
[80] Fix | Delete
*
[81] Fix | Delete
* @param string $woo_content WooCommerce content.
[82] Fix | Delete
* @return string
[83] Fix | Delete
*/
[84] Fix | Delete
private function inline_css( string $woo_content ): string {
[85] Fix | Delete
if ( empty( $woo_content ) ) {
[86] Fix | Delete
return '';
[87] Fix | Delete
}
[88] Fix | Delete
$css = $this->theme_controller->get_stylesheet_for_rendering();
[89] Fix | Delete
return $this->css_inliner->from_html( $woo_content )->inline_css( $css )->render();
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* Capture the WooCommerce content excluding headers and footers.
[94] Fix | Delete
*
[95] Fix | Delete
* @param \WC_Email $wc_email WooCommerce email.
[96] Fix | Delete
* @return string
[97] Fix | Delete
*/
[98] Fix | Delete
private function capture_woo_content( \WC_Email $wc_email ): string {
[99] Fix | Delete
return $wc_email->get_block_editor_email_template_content();
[100] Fix | Delete
}
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function