From 4a3aecbf5cfea6cedfb560be8081f804e5b000b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lys=C3=BD?= Date: Fri, 1 Oct 2021 09:46:29 +0200 Subject: [PATCH] Use WP functions to get content and excerpt [MAILPOET-3671] --- lib/Newsletter/Editor/PostContentManager.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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) {