Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
WCEmailTemplateChangeSummary::inner_html_hash
Hash a block's markup. Unlike inner_text this keeps inline markup and HTML comments, which is how personalization tags (<!--[woocommerce/…]-->), links, emphasis and inline styling reach the comparison at all.
The base side is a PHP template render and the post side was saved by the block editor, which decodes entities and trims the space just inside a block's outer tag even on blocks the merchant never touched. Both are normalized away here so such a block does not read as edited. Spacing around inline tags is kept: it changes what the merchant sees.
Method of the class: WCEmailTemplateChangeSummary{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WCEmailTemplateChangeSummary::inner_html_hash( $inner_html ): string;
- $inner_html(string) (required)
- Raw
innerHTMLstring from a parsed block.
WCEmailTemplateChangeSummary::inner_html_hash() WCEmailTemplateChangeSummary::inner html hash code WC 11.3.0
private static function inner_html_hash( string $inner_html ): string {
$decoded = html_entity_decode( $inner_html, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
$collapsed = preg_replace( '/[\s\x{00A0}]+/u', ' ', $decoded );
// Invalid UTF-8 makes `preg_replace()` return null; hashing the raw
// markup keeps two such blocks from reading as the same.
if ( null === $collapsed ) {
return sha1( $inner_html );
}
$collapsed = trim( $collapsed );
$trimmed = (string) preg_replace( '/^(<[^>]+>) /', '$1', $collapsed );
$trimmed = (string) preg_replace( '/ (<\/[^>]+>)$/', '$1', $trimmed );
return sha1( $trimmed );
}