From 42e3a97616f4e3e70fab57035f5dbce0721d172c Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Wed, 20 Sep 2017 11:01:05 +0000 Subject: [PATCH] Fixing Shortcodes issue --- lib/Config/Shortcodes.php | 15 ++++++++------- tests/unit/Config/ShortcodesTest.php | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/Config/Shortcodes.php b/lib/Config/Shortcodes.php index 9d1737bab0..aeb35ab16a 100644 --- a/lib/Config/Shortcodes.php +++ b/lib/Config/Shortcodes.php @@ -4,6 +4,7 @@ use MailPoet\Models\Newsletter; use MailPoet\Models\Subscriber; use MailPoet\Models\SubscriberSegment; use MailPoet\Newsletter\Url as NewsletterUrl; +use MailPoet\WP\Hooks; class Shortcodes { function __construct() { @@ -26,10 +27,10 @@ class Shortcodes { $this, 'getArchive' )); - add_filter('mailpoet_archive_date', array( + Hooks::addFilter('mailpoet_archive_date', array( $this, 'renderArchiveDate' ), 2); - add_filter('mailpoet_archive_subject', array( + Hooks::addFilter('mailpoet_archive_subject', array( $this, 'renderArchiveSubject' ), 2, 3); } @@ -79,12 +80,12 @@ class Shortcodes { $subscriber = Subscriber::getCurrentWPUser(); if(empty($newsletters)) { - return apply_filters( + return Hooks::applyFilters( 'mailpoet_archive_no_newsletters', __('Oops! There are no newsletters to display.', 'mailpoet') ); } else { - $title = apply_filters('mailpoet_archive_title', ''); + $title = Hooks::applyFilters('mailpoet_archive_title', ''); if(!empty($title)) { $html .= '

'.$title.'

'; } @@ -93,10 +94,10 @@ class Shortcodes { $queue = $newsletter->queue()->findOne(); $html .= '
  • '. ''. - apply_filters('mailpoet_archive_date', $newsletter). + Hooks::applyFilters('mailpoet_archive_date', $newsletter). ' '. - apply_filters('mailpoet_archive_subject', $newsletter, $subscriber, $queue). + Hooks::applyFilters('mailpoet_archive_subject', $newsletter, $subscriber, $queue). '
  • '; } @@ -124,4 +125,4 @@ class Shortcodes { .esc_attr($newsletter->newsletter_rendered_subject). ''; } -} \ No newline at end of file +} diff --git a/tests/unit/Config/ShortcodesTest.php b/tests/unit/Config/ShortcodesTest.php index 63707835fb..03218b8422 100644 --- a/tests/unit/Config/ShortcodesTest.php +++ b/tests/unit/Config/ShortcodesTest.php @@ -1,6 +1,7 @@ renderArchiveDate($args[0]); + case 'mailpoet_archive_subject': + return $shortcodes->renderArchiveSubject($args[0], $args[1], $args[2]); + } + return ''; + }); // result contains a link pointing to the "view in browser" router endpoint $result = $shortcodes->getArchive($params = false); + WordPress::releaseFunction('apply_filters'); $dom = \pQuery::parseStr($result); $link = $dom->query('a'); $link = $link->attr('href'); @@ -36,4 +49,4 @@ class ShortcodesTest extends \MailPoetTest { expect($request_data['newsletter_id'])->isEmpty(); expect($request_data['newsletter_hash'])->equals($this->newsletter->hash); } -} \ No newline at end of file +}