- Adds subsription tracking option to Settings->Advanced
- Updates sending queue worker to not replace links if tracking is disabled Closes #417
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Subscription\Url as SubscriptionUrl;
|
||||
|
||||
class Subscription {
|
||||
@ -21,23 +22,35 @@ class Subscription {
|
||||
) {
|
||||
switch($action) {
|
||||
case 'unsubscribe':
|
||||
return '<a target="_blank" href="'.
|
||||
esc_attr(SubscriptionUrl::getUnsubscribeUrl($subscriber))
|
||||
return '<a target="_blank" href="['.
|
||||
self::processUrl(
|
||||
$action,
|
||||
esc_attr(SubscriptionUrl::getUnsubscribeUrl($subscriber))
|
||||
)
|
||||
.'">'.__('Unsubscribe').'</a>';
|
||||
break;
|
||||
|
||||
case 'unsubscribe_url':
|
||||
return SubscriptionUrl::getUnsubscribeUrl($subscriber);
|
||||
return self::processUrl(
|
||||
$action,
|
||||
SubscriptionUrl::getUnsubscribeUrl($subscriber)
|
||||
);
|
||||
break;
|
||||
|
||||
case 'manage':
|
||||
return '<a target="_blank" href="'.
|
||||
esc_attr(SubscriptionUrl::getManageUrl($subscriber))
|
||||
self::processUrl(
|
||||
$action,
|
||||
esc_attr(SubscriptionUrl::getManageUrl($subscriber))
|
||||
)
|
||||
.'">'.__('Manage subscription').'</a>';
|
||||
break;
|
||||
|
||||
case 'manage_url':
|
||||
return SubscriptionUrl::getManageUrl($subscriber);
|
||||
return self::processUrl(
|
||||
$action,
|
||||
SubscriptionUrl::getManageUrl($subscriber)
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -45,4 +58,11 @@ class Subscription {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static function processUrl($action, $url) {
|
||||
if((int) Setting::getValue('tracking.enabled') === 1) {
|
||||
return sprintf('[subscription:%s]', $action);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
}
|
@ -18,18 +18,21 @@ class Shortcodes {
|
||||
return array_unique($shortcodes[0]);
|
||||
}
|
||||
|
||||
function match($shortcode) {
|
||||
preg_match(
|
||||
'/\[(?P<type>\w+):(?P<action>\w+)(?:.*?default:(?P<default>.*?))?\]/',
|
||||
$shortcode,
|
||||
$match
|
||||
);
|
||||
return $match;
|
||||
}
|
||||
|
||||
function process($shortcodes, $text) {
|
||||
$processed_shortcodes = array_map(
|
||||
function($shortcode) use($text) {
|
||||
preg_match(
|
||||
'/\[(?P<type>\w+):(?P<action>\w+)(?:.*?default:(?P<default>.*?))?\]/',
|
||||
$shortcode,
|
||||
$shortcode_details
|
||||
);
|
||||
$shortcode_details = $this->match($shortcode);
|
||||
$shortcode_type = ucfirst($shortcode_details['type']);
|
||||
$shortcode_action = $shortcode_details['action'];
|
||||
// do not process subscription management links
|
||||
if ($shortcode_type === 'Subscription') return $shortcode;
|
||||
$shortcode_class =
|
||||
__NAMESPACE__ . '\\Categories\\' . $shortcode_type;
|
||||
$shortcode_default_value = isset($shortcode_details['default'])
|
||||
|
Reference in New Issue
Block a user