diff --git a/lib/Newsletter/Editor/PostContentManager.php b/lib/Newsletter/Editor/PostContentManager.php index 3d35e25aeb..8169263b8d 100644 --- a/lib/Newsletter/Editor/PostContentManager.php +++ b/lib/Newsletter/Editor/PostContentManager.php @@ -14,11 +14,14 @@ class PostContentManager { /** @var WooCommerceHelper */ private $woocommerceHelper; + /** @var WPFunctions */ + private $wp; + public function __construct( WooCommerceHelper $woocommerceHelper = null ) { - $wp = new WPFunctions; - $this->maxExcerptLength = $wp->applyFilters('mailpoet_newsletter_post_excerpt_length', $this->maxExcerptLength); + $this->wp = new WPFunctions; + $this->maxExcerptLength = $this->wp->applyFilters('mailpoet_newsletter_post_excerpt_length', $this->maxExcerptLength); $this->woocommerceHelper = $woocommerceHelper ?: new WooCommerceHelper(); } @@ -26,19 +29,19 @@ class PostContentManager { if ($displayType === 'titleOnly') { return ''; } - if ($this->woocommerceHelper->isWooCommerceActive() && $post->post_type === 'product') { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + if ($this->woocommerceHelper->isWooCommerceActive() && $this->wp->getPostType($post) === 'product') { $product = $this->woocommerceHelper->wcGetProduct($post->ID); if ($product) { return $this->getContentForProduct($product, $displayType); } } if ($displayType === 'excerpt') { - if (!empty($post->post_excerpt)) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - return self::stripShortCodes($post->post_excerpt); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + if ($this->wp->hasExcerpt($post)) { + return self::stripShortCodes($this->wp->getTheExcerpt($post)); } - return $this->generateExcerpt($post->post_content); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + return $this->generateExcerpt($this->wp->getTheContent(null, false, $post)); } - return self::stripShortCodes($post->post_content); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + return self::stripShortCodes($this->wp->getTheContent(null, false, $post)); } public function filterContent($content, $displayType, $withPostClass = true) {