max_excerpt_length = $wp->applyFilters('mailpoet_newsletter_post_excerpt_length', $this->max_excerpt_length); $this->woocommerce_helper = $woocommerce_helper ?: new WooCommerceHelper(); } public function getContent($post, $displayType) { if ($displayType === 'titleOnly') { return ''; } if ($this->woocommerce_helper->isWooCommerceActive() && $post->post_type === 'product') { $product = $this->woocommerce_helper->wcGetProduct($post->ID); if ($product) { return $this->getContentForProduct($product, $displayType); } } if ($displayType === 'excerpt') { if (!empty($post->post_excerpt)) { return self::stripShortCodes($post->post_excerpt); } return $this->generateExcerpt($post->post_content); } return self::stripShortCodes($post->post_content); } public function filterContent($content, $display_type, $with_post_class = true) { $content = self::convertEmbeddedContent($content); // convert h4 h5 h6 to h3 $content = preg_replace('/<([\/])?h[456](.*?)>/', '<$1h3$2>', $content); // convert currency signs $content = str_replace( ['$', '€', '£', '¥'], ['$', '€', '£', '¥'], $content ); // strip useless tags $tags_not_being_stripped = [ '
', '', '', '', '', '',
'', ' wpautop($content));
} else {
$content = WPFunctions::get()->wpautop($content);
}
$content = trim($content);
return $content;
}
private function getContentForProduct($product, $displayType) {
if ($displayType === 'excerpt') {
return $product->get_short_description();
}
return $product->get_description();
}
private function generateExcerpt($content) {
// remove image captions in gutenberg
$content = preg_replace(
"/', '
', '
', '',
];
if ($display_type === 'full') {
$tags_not_being_stripped = array_merge($tags_not_being_stripped, ['
', '
', '
', '
']);
}
$content = strip_tags($content, implode('', $tags_not_being_stripped));
if ($with_post_class) {
$content = str_replace('