Passes single array with shortcode details
This commit is contained in:
@ -6,10 +6,7 @@ use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Date {
|
||||
static function process(
|
||||
$shortcode,
|
||||
$action,
|
||||
$action_argument = false,
|
||||
$action_argument_value = false
|
||||
$shortcode_details
|
||||
) {
|
||||
$action_mapping = array(
|
||||
'd' => 'd',
|
||||
@ -19,11 +16,11 @@ class Date {
|
||||
'mtext' => 'F',
|
||||
'y' => 'Y'
|
||||
);
|
||||
if(!empty($action_mapping[$action])) {
|
||||
return date_i18n($action_mapping[$action], WPFunctions::currentTime('timestamp'));
|
||||
if(!empty($action_mapping[$shortcode_details['action']])) {
|
||||
return date_i18n($action_mapping[$shortcode_details['action']], WPFunctions::currentTime('timestamp'));
|
||||
}
|
||||
return ($action === 'custom' && $action_argument === 'format') ?
|
||||
date_i18n($action_argument_value, WPFunctions::currentTime('timestamp')) :
|
||||
return ($shortcode_details['action'] === 'custom' && $shortcode_details['action_argument'] === 'format') ?
|
||||
date_i18n($shortcode_details['action_argument_value'], WPFunctions::currentTime('timestamp')) :
|
||||
false;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
@ -10,20 +11,17 @@ class Link {
|
||||
const CATEGORY_NAME = 'link';
|
||||
|
||||
static function process(
|
||||
$shortcode,
|
||||
$action,
|
||||
$action_argument,
|
||||
$action_argument_value,
|
||||
$shortcode_details,
|
||||
$newsletter,
|
||||
$subscriber,
|
||||
$queue,
|
||||
$content,
|
||||
$wp_user_preview
|
||||
) {
|
||||
switch($action) {
|
||||
switch($shortcode_details['action']) {
|
||||
case 'subscription_unsubscribe_url':
|
||||
return self::processUrl(
|
||||
$action,
|
||||
$shortcode_details['action'],
|
||||
SubscriptionUrl::getUnsubscribeUrl($wp_user_preview ? false : $subscriber),
|
||||
$queue,
|
||||
$wp_user_preview
|
||||
@ -31,7 +29,7 @@ class Link {
|
||||
|
||||
case 'subscription_manage_url':
|
||||
return self::processUrl(
|
||||
$action,
|
||||
$shortcode_details['action'],
|
||||
SubscriptionUrl::getManageUrl($wp_user_preview ? false : $subscriber),
|
||||
$queue,
|
||||
$wp_user_preview
|
||||
@ -45,10 +43,10 @@ class Link {
|
||||
$queue,
|
||||
$wp_user_preview
|
||||
);
|
||||
return self::processUrl($action, $url, $queue, $wp_user_preview);
|
||||
return self::processUrl($shortcode_details['action'], $url, $queue, $wp_user_preview);
|
||||
|
||||
default:
|
||||
$shortcode = self::getFullShortcode($action);
|
||||
$shortcode = self::getFullShortcode($shortcode_details['action']);
|
||||
$url = apply_filters(
|
||||
'mailpoet_newsletter_shortcode_link',
|
||||
$shortcode,
|
||||
@ -58,14 +56,13 @@ class Link {
|
||||
$wp_user_preview
|
||||
);
|
||||
return ($url !== $shortcode) ?
|
||||
self::processUrl($action, $url, $queue, $wp_user_preview) :
|
||||
self::processUrl($shortcode_details['action'], $url, $queue, $wp_user_preview) :
|
||||
false;
|
||||
}
|
||||
}
|
||||
|
||||
static function processUrl($action, $url, $queue, $wp_user_preview = false) {
|
||||
if ($wp_user_preview)
|
||||
return $url;
|
||||
if($wp_user_preview) return $url;
|
||||
return ($queue !== false && (boolean)Setting::getValue('tracking.enabled')) ?
|
||||
self::getFullShortcode($action) :
|
||||
$url;
|
||||
|
@ -9,16 +9,13 @@ require_once(ABSPATH . "wp-includes/pluggable.php");
|
||||
|
||||
class Newsletter {
|
||||
static function process(
|
||||
$shortcode,
|
||||
$action,
|
||||
$action_argument,
|
||||
$action_argument_value,
|
||||
$shortcode_details,
|
||||
$newsletter,
|
||||
$subscriber,
|
||||
$queue,
|
||||
$content
|
||||
) {
|
||||
switch($action) {
|
||||
switch($shortcode_details['action']) {
|
||||
case 'subject':
|
||||
return ($newsletter) ? $newsletter->subject : false;
|
||||
|
||||
|
@ -9,18 +9,15 @@ require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
class Subscriber {
|
||||
static function process(
|
||||
$shortcode,
|
||||
$action,
|
||||
$action_argument,
|
||||
$action_argument_value,
|
||||
$shortcode_details,
|
||||
$newsletter,
|
||||
$subscriber
|
||||
) {
|
||||
if($subscriber !== false && !is_object($subscriber)) return $shortcode;
|
||||
$default_value = ($action_argument === 'default') ?
|
||||
$action_argument_value :
|
||||
if($subscriber !== false && !is_object($subscriber)) return $shortcode_details['shortcode'];
|
||||
$default_value = ($shortcode_details['action_argument'] === 'default') ?
|
||||
$shortcode_details['action_argument_value'] :
|
||||
'';
|
||||
switch($action) {
|
||||
switch($shortcode_details['action']) {
|
||||
case 'firstname':
|
||||
return (!empty($subscriber->first_name)) ? $subscriber->first_name : $default_value;
|
||||
case 'lastname':
|
||||
@ -37,7 +34,7 @@ class Subscriber {
|
||||
return SubscriberModel::filter('subscribed')
|
||||
->count();
|
||||
default:
|
||||
if(preg_match('/cf_(\d+)/', $action, $custom_field) &&
|
||||
if(preg_match('/cf_(\d+)/', $shortcode_details['action'], $custom_field) &&
|
||||
!empty($subscriber->id)
|
||||
) {
|
||||
$custom_field = SubscriberCustomField
|
||||
|
@ -49,20 +49,21 @@ class Shortcodes {
|
||||
$processed_shortcodes = array_map(
|
||||
function($shortcode) use ($content, $_this) {
|
||||
$shortcode_details = $_this->match($shortcode);
|
||||
$shortcode_category = !empty($shortcode_details['category']) ?
|
||||
ucfirst($shortcode_details['category']) :
|
||||
$shortcode_details['shortcode'] = $shortcode;
|
||||
$shortcode_details['category'] = !empty($shortcode_details['category']) ?
|
||||
$shortcode_details['category'] :
|
||||
false;
|
||||
$shortcode_action = !empty($shortcode_details['action']) ?
|
||||
$shortcode_details['action'] = !empty($shortcode_details['action']) ?
|
||||
$shortcode_details['action'] :
|
||||
false;
|
||||
$shortcode_class =
|
||||
Shortcodes::SHORTCODE_CATEGORY_NAMESPACE . $shortcode_category;
|
||||
$shortcode_argument = !empty($shortcode_details['argument']) ?
|
||||
$shortcode_details['action_argument'] = !empty($shortcode_details['argument']) ?
|
||||
$shortcode_details['argument'] :
|
||||
false;
|
||||
$shortcode_argument_value = !empty($shortcode_details['argument_value']) ?
|
||||
$shortcode_details['action_argument_value'] = !empty($shortcode_details['argument_value']) ?
|
||||
$shortcode_details['argument_value'] :
|
||||
false;
|
||||
$shortcode_class =
|
||||
Shortcodes::SHORTCODE_CATEGORY_NAMESPACE . ucfirst($shortcode_details['category']);
|
||||
if(!class_exists($shortcode_class)) {
|
||||
$custom_shortcode = apply_filters(
|
||||
'mailpoet_newsletter_shortcode',
|
||||
@ -78,10 +79,7 @@ class Shortcodes {
|
||||
$custom_shortcode;
|
||||
}
|
||||
return $shortcode_class::process(
|
||||
$shortcode,
|
||||
$shortcode_action,
|
||||
$shortcode_argument,
|
||||
$shortcode_argument_value,
|
||||
$shortcode_details,
|
||||
$_this->newsletter,
|
||||
$_this->subscriber,
|
||||
$_this->queue,
|
||||
|
@ -82,15 +82,21 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanProcessDateShortcodes() {
|
||||
$date = new \DateTime(current_time('mysql'));
|
||||
expect(Date::process('[date:d]', 'd'))->equals(date_i18n('d', current_time('timestamp')));
|
||||
expect(Date::process('[date:dordinal]', 'dordinal'))->equals(date_i18n('dS', current_time('timestamp')));
|
||||
expect(Date::process('[date:dordinal]', 'dtext'))->equals(date_i18n('l', current_time('timestamp')));
|
||||
expect(Date::process('[date:m]', 'm'))->equals(date_i18n('m', current_time('timestamp')));
|
||||
expect(Date::process('[date:mtext]', 'mtext'))->equals(date_i18n('F', current_time('timestamp')));
|
||||
expect(Date::process('[date:y]', 'y'))->equals(date_i18n('Y', current_time('timestamp')));
|
||||
$shortcode_details = array('action' => 'd');
|
||||
expect(Date::process($shortcode_details))->equals(date_i18n('d', current_time('timestamp')));
|
||||
$shortcode_details = array('action' => 'dordinal');
|
||||
expect(Date::process($shortcode_details))->equals(date_i18n('dS', current_time('timestamp')));
|
||||
$shortcode_details = array('action' => 'dtext');
|
||||
expect(Date::process($shortcode_details))->equals(date_i18n('l', current_time('timestamp')));
|
||||
$shortcode_details = array('action' => 'm');
|
||||
expect(Date::process($shortcode_details))->equals(date_i18n('m', current_time('timestamp')));
|
||||
$shortcode_details = array('action' => 'mtext');
|
||||
expect(Date::process($shortcode_details))->equals(date_i18n('F', current_time('timestamp')));
|
||||
$shortcode_details = array('action' => 'y');
|
||||
expect(Date::process($shortcode_details))->equals(date_i18n('Y', current_time('timestamp')));
|
||||
// allow custom date formats (http://php.net/manual/en/function.date.php)
|
||||
expect(Date::process('[date:custom|format:U F]', 'custom', 'format', 'U F'))->equals(date_i18n('U F', current_time('timestamp')));
|
||||
$shortcode_details = array('action' => 'custom', 'action_argument' => 'format', 'action_argument_value' => 'U F');
|
||||
expect(Date::process($shortcode_details))->equals(date_i18n('U F', current_time('timestamp')));
|
||||
}
|
||||
|
||||
function testItCanProcessNewsletterShortcodes() {
|
||||
|
Reference in New Issue
Block a user