- Updates code based on Taut's comments
This commit is contained in:
@@ -18,37 +18,39 @@ class Subscription {
|
||||
$action,
|
||||
$default_value = false,
|
||||
$newsletter = false,
|
||||
$subscriber = false
|
||||
$subscriber = false,
|
||||
$text = false,
|
||||
$shortcode
|
||||
) {
|
||||
switch($action) {
|
||||
case 'unsubscribe':
|
||||
return '<a target="_blank" href="['.
|
||||
self::processUrl(
|
||||
$action,
|
||||
return '<a target="_blank" href="'.
|
||||
self::getShortcodeUrl(
|
||||
$shortcode,
|
||||
esc_attr(SubscriptionUrl::getUnsubscribeUrl($subscriber))
|
||||
)
|
||||
.'">'.__('Unsubscribe').'</a>';
|
||||
break;
|
||||
|
||||
case 'unsubscribe_url':
|
||||
return self::processUrl(
|
||||
$action,
|
||||
return self::getShortcodeUrl(
|
||||
$shortcode,
|
||||
SubscriptionUrl::getUnsubscribeUrl($subscriber)
|
||||
);
|
||||
break;
|
||||
|
||||
case 'manage':
|
||||
return '<a target="_blank" href="'.
|
||||
self::processUrl(
|
||||
$action,
|
||||
self::getShortcodeUrl(
|
||||
$shortcode,
|
||||
esc_attr(SubscriptionUrl::getManageUrl($subscriber))
|
||||
)
|
||||
.'">'.__('Manage subscription').'</a>';
|
||||
break;
|
||||
|
||||
case 'manage_url':
|
||||
return self::processUrl(
|
||||
$action,
|
||||
return self::getShortcodeUrl(
|
||||
$shortcode,
|
||||
SubscriptionUrl::getManageUrl($subscriber)
|
||||
);
|
||||
break;
|
||||
@@ -59,10 +61,9 @@ class Subscription {
|
||||
}
|
||||
}
|
||||
|
||||
static function processUrl($action, $url) {
|
||||
if((int) Setting::getValue('tracking.enabled') === 1) {
|
||||
return sprintf('[subscription:%s]', $action);
|
||||
}
|
||||
return $url;
|
||||
static function getShortcodeUrl($shortcode, $url) {
|
||||
return ((boolean) Setting::getValue('tracking.enabled') === true) ?
|
||||
$shortcode :
|
||||
$url;
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ namespace MailPoet\Newsletter\Shortcodes;
|
||||
class Shortcodes {
|
||||
public $newsletter;
|
||||
public $subscriber;
|
||||
static $shortcodes_regex = '/\[(?:\w+):.*?\]/ism';
|
||||
|
||||
function __construct(
|
||||
$newsletter = false,
|
||||
@@ -14,7 +15,7 @@ class Shortcodes {
|
||||
}
|
||||
|
||||
function extract($text) {
|
||||
preg_match_all('/\[(?:\w+):.*?\]/', $text, $shortcodes);
|
||||
preg_match_all(self::$shortcodes_regex, $text, $shortcodes);
|
||||
return array_unique($shortcodes[0]);
|
||||
}
|
||||
|
||||
@@ -43,7 +44,8 @@ class Shortcodes {
|
||||
$shortcode_default_value,
|
||||
$this->newsletter,
|
||||
$this->subscriber,
|
||||
$text
|
||||
$text,
|
||||
$shortcode
|
||||
);
|
||||
}, $shortcodes);
|
||||
return $processed_shortcodes;
|
||||
|
Reference in New Issue
Block a user