diff --git a/lib/Config/Shortcodes.php b/lib/Config/Shortcodes.php
index c556027c7b..9359ff3651 100644
--- a/lib/Config/Shortcodes.php
+++ b/lib/Config/Shortcodes.php
@@ -3,7 +3,6 @@ namespace MailPoet\Config;
use \MailPoet\Models\Newsletter;
use \MailPoet\Models\Subscriber;
use \MailPoet\Models\SubscriberSegment;
-use \MailPoet\Subscription;
use MailPoet\Newsletter\Url as NewsletterUrl;
class Shortcodes {
@@ -113,12 +112,16 @@ class Shortcodes {
}
function renderArchiveSubject($newsletter) {
- $preview_url = NewsletterUrl::getViewInBrowserUrl($newsletter);
+ $preview_url = NewsletterUrl::getViewInBrowserUrl(
+ $newsletter,
+ $subscriber = false,
+ $queue = false,
+ $wp_user_preview = true
+ );
return ''
.esc_attr($newsletter->subject).
'';
}
-
-}
+}
\ No newline at end of file
diff --git a/lib/Newsletter/Shortcodes/Categories/Link.php b/lib/Newsletter/Shortcodes/Categories/Link.php
index 977a85a403..2bfb1e5c19 100644
--- a/lib/Newsletter/Shortcodes/Categories/Link.php
+++ b/lib/Newsletter/Shortcodes/Categories/Link.php
@@ -7,11 +7,14 @@ use MailPoet\Statistics\Track\Unsubscribes;
use MailPoet\Subscription\Url as SubscriptionUrl;
class Link {
- static function process($action,
+ static function process(
+ $action,
$default_value,
$newsletter,
$subscriber,
- $queue
+ $queue,
+ $content,
+ $wp_user_preview
) {
switch($action) {
case 'subscription_unsubscribe':
@@ -19,7 +22,8 @@ class Link {
$url = self::processUrl(
$action,
esc_attr(SubscriptionUrl::getUnsubscribeUrl($subscriber)),
- $queue
+ $queue,
+ $wp_user_preview
);
return sprintf(
'%s',
@@ -31,14 +35,16 @@ class Link {
return self::processUrl(
$action,
SubscriptionUrl::getUnsubscribeUrl($subscriber),
- $queue
+ $queue,
+ $wp_user_preview
);
case 'subscription_manage':
$url = self::processUrl(
$action = 'subscription_manage_url',
esc_attr(SubscriptionUrl::getManageUrl($subscriber)),
- $queue
+ $queue,
+ $wp_user_preview
);
return sprintf(
'%s',
@@ -50,13 +56,14 @@ class Link {
return self::processUrl(
$action,
SubscriptionUrl::getManageUrl($subscriber),
- $queue
+ $queue,
+ $wp_user_preview
);
case 'newsletter_view_in_browser':
$action = 'newsletter_view_in_browser_url';
$url = esc_attr(NewsletterUrl::getViewInBrowserUrl($newsletter, $subscriber, $queue));
- $url = self::processUrl($action, $url, $queue);
+ $url = self::processUrl($action, $url, $queue, $wp_user_preview);
return sprintf(
'%s',
$url,
@@ -65,7 +72,7 @@ class Link {
case 'newsletter_view_in_browser_url':
$url = NewsletterUrl::getViewInBrowserUrl($newsletter, $subscriber, $queue);
- return self::processUrl($action, $url, $queue);
+ return self::processUrl($action, $url, $queue, $wp_user_preview);
default:
$shortcode = self::getShortcode($action);
@@ -74,15 +81,17 @@ class Link {
$shortcode,
$newsletter,
$subscriber,
- $queue
+ $queue,
+ $wp_user_preview
);
return ($url !== $shortcode) ?
- self::processUrl($action, $url, $queue) :
+ self::processUrl($action, $url, $queue, $wp_user_preview) :
false;
}
}
- static function processUrl($action, $url, $queue) {
+ static function processUrl($action, $url, $queue, $wp_user_preview = false) {
+ if($wp_user_preview) return '#';
return ($queue !== false && (boolean)Setting::getValue('tracking.enabled')) ?
self::getShortcode($action) :
$url;
diff --git a/lib/Newsletter/Shortcodes/Shortcodes.php b/lib/Newsletter/Shortcodes/Shortcodes.php
index b88928d9e2..3a4341163a 100644
--- a/lib/Newsletter/Shortcodes/Shortcodes.php
+++ b/lib/Newsletter/Shortcodes/Shortcodes.php
@@ -5,16 +5,19 @@ class Shortcodes {
public $newsletter;
public $subscriber;
public $queue;
+ public $wp_user_preview;
const SHORTCODE_CATEGORY_NAMESPACE = 'MailPoet\Newsletter\Shortcodes\Categories\\';
function __construct(
$newsletter = false,
$subscriber = false,
- $queue = false
+ $queue = false,
+ $wp_user_preview = false
) {
$this->newsletter = $newsletter;
$this->subscriber = $subscriber;
$this->queue = $queue;
+ $this->wp_user_preview = $wp_user_preview;
}
function extract($content, $categories = false) {
@@ -64,7 +67,8 @@ class Shortcodes {
$_this->newsletter,
$_this->subscriber,
$_this->queue,
- $content
+ $content,
+ $_this->wp_user_preview
);
return ($custom_shortcode === $shortcode) ?
false :
@@ -76,7 +80,8 @@ class Shortcodes {
$_this->newsletter,
$_this->subscriber,
$_this->queue,
- $content
+ $content,
+ $_this->wp_user_preview
);
}, $shortcodes);
return $processed_shortcodes;
diff --git a/lib/Newsletter/ViewInBrowser.php b/lib/Newsletter/ViewInBrowser.php
index f312d8112c..fc2bd3e7e7 100644
--- a/lib/Newsletter/ViewInBrowser.php
+++ b/lib/Newsletter/ViewInBrowser.php
@@ -27,8 +27,8 @@ class ViewInBrowser {
$shortcodes = new Shortcodes(
$newsletter,
$subscriber,
- $queue
-
+ $queue,
+ $wp_user_preview
);
$rendered_newsletter = $shortcodes->replace($newsletter_body['html']);
if($queue && (boolean)Setting::getValue('tracking.enabled')) {
diff --git a/tests/unit/Newsletter/ShortcodesTest.php b/tests/unit/Newsletter/ShortcodesTest.php
index 04820573d0..64d76c4155 100644
--- a/tests/unit/Newsletter/ShortcodesTest.php
+++ b/tests/unit/Newsletter/ShortcodesTest.php
@@ -269,6 +269,30 @@ class ShortcodesTest extends MailPoetTest {
}
}
+ function testItReturnsHashInsteadofLinksWhenInPreviewIsEnabled() {
+ $shortcodes_object = $this->shortcodes_object;
+ $shortcodes_object->wp_user_preview = true;
+ $shortcodes = array(
+ '[link:subscription_unsubscribe_url]',
+ '[link:subscription_manage_url]',
+ '[link:newsletter_view_in_browser_url]',
+ );
+ $result = $shortcodes_object->process($shortcodes);
+ // hash is returned
+ foreach($result as $index => $transformed_shortcode) {
+ expect($transformed_shortcode)->equals('#');
+ }
+ $shortcodes = array(
+ '[link:subscription_unsubscribe]',
+ '[link:subscription_manage]',
+ '[link:newsletter_view_in_browser]',
+ );
+ $result = $shortcodes_object->process($shortcodes);
+ foreach($result as $index => $transformed_shortcode) {
+ expect($transformed_shortcode)->regExp('/href="#"/');
+ }
+ }
+
function testItCanProcessCustomLinkShortcodes() {
$shortcodes_object = $this->shortcodes_object;
$shortcode = '[link:shortcode]';
diff --git a/tests/unit/Newsletter/ViewInBrowserTest.php b/tests/unit/Newsletter/ViewInBrowserTest.php
index b540e55766..359c7964f1 100644
--- a/tests/unit/Newsletter/ViewInBrowserTest.php
+++ b/tests/unit/Newsletter/ViewInBrowserTest.php
@@ -85,13 +85,6 @@ class ViewInBrowserTest extends MailPoetTest {
$queue->newsletter_rendered_body = $this->queue_rendered_newsletter_without_tracking;
$queue->subscribers = array('processed' => array($subscriber->id));
$this->queue = $queue->save();
- // build browser preview data
- $this->browser_preview_data = (object)array(
- 'queue' => $this->queue,
- 'subscriber' => $this->subscriber,
- 'newsletter' => $this->newsletter,
- 'preview' => false
- );
}
function testItRendersNewsletter() {
@@ -99,7 +92,7 @@ class ViewInBrowserTest extends MailPoetTest {
$this->newsletter,
$this->subscriber,
$queue = false,
- $preview = true
+ $preview = false
);
expect($rendered_body)->regExp('/Rendered newsletter/');
}
@@ -109,7 +102,7 @@ class ViewInBrowserTest extends MailPoetTest {
$this->newsletter,
$this->subscriber,
$this->queue,
- $preview = true
+ $preview = false
);
expect($rendered_body)->regExp('/Newsletter from queue/');
}
@@ -120,7 +113,7 @@ class ViewInBrowserTest extends MailPoetTest {
$this->newsletter,
$this->subscriber,
$this->queue,
- $preview = true
+ $preview = false
);
expect($rendered_body)->contains('Hello, First');
expect($rendered_body)->contains(Router::NAME . '&endpoint=view_in_browser');
@@ -134,7 +127,7 @@ class ViewInBrowserTest extends MailPoetTest {
$this->newsletter,
$this->subscriber,
$queue,
- $preview = true
+ $preview = false
);
expect($rendered_body)->contains(Router::NAME . '&endpoint=track');
}