diff --git a/lib/API/Endpoints/Newsletters.php b/lib/API/Endpoints/Newsletters.php
index ee8d302c86..04074b6db2 100644
--- a/lib/API/Endpoints/Newsletters.php
+++ b/lib/API/Endpoints/Newsletters.php
@@ -29,12 +29,12 @@ class Newsletters extends APIEndpoint {
APIError::NOT_FOUND => __('This newsletter does not exist.', 'mailpoet')
));
} else {
- return $this->successResponse(
- $newsletter
+ $newsletter = $newsletter
->withSegments()
->withOptions()
- ->asArray()
- );
+ ->asArray();
+ $newsletter = apply_filters('mailpoet_api_newsletters_get_after', $newsletter);
+ return $this->successResponse($newsletter);
}
}
@@ -51,6 +51,8 @@ class Newsletters extends APIEndpoint {
unset($data['options']);
}
+ $data = apply_filters('mailpoet_api_newsletters_save_before', $data);
+
$newsletter = Newsletter::createOrUpdate($data);
$errors = $newsletter->getErrors();
@@ -93,6 +95,8 @@ class Newsletters extends APIEndpoint {
$newsletter = Newsletter::filter('filterWithOptions')
->findOne($newsletter->id);
+ do_action('mailpoet_api_newsletters_save_after', $newsletter);
+
// if this is a post notification, process newsletter options and update its schedule
if($newsletter->type === Newsletter::TYPE_NOTIFICATION) {
// generate the new schedule from options and get the new "next run" date
@@ -204,6 +208,7 @@ class Newsletters extends APIEndpoint {
if(!empty($errors)) {
return $this->errorResponse($errors);
} else {
+ do_action('mailpoet_api_newsletters_duplicate_after', $newsletter, $duplicate);
return $this->successResponse(
Newsletter::findOne($duplicate->id)->asArray(),
array('count' => 1)
diff --git a/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php b/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php
index 0245f96456..1cdc914eae 100644
--- a/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php
+++ b/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php
@@ -36,11 +36,21 @@ class Newsletter {
$this->tracking_image_inserted = OpenTracking::addTrackingImage();
// render newsletter
$rendered_newsletter = $newsletter->render();
+ $rendered_newsletter = apply_filters(
+ 'mailpoet_sending_newsletter_render_after',
+ $rendered_newsletter,
+ $newsletter
+ );
// hash and save all links
$rendered_newsletter = LinksTask::process($rendered_newsletter, $newsletter, $queue);
} else {
// render newsletter
$rendered_newsletter = $newsletter->render();
+ $rendered_newsletter = apply_filters(
+ 'mailpoet_sending_newsletter_render_after',
+ $rendered_newsletter,
+ $newsletter
+ );
}
// check if this is a post notification and if it contains posts
$newsletter_contains_posts = strpos($rendered_newsletter['html'], 'data-post-id');
diff --git a/lib/Newsletter/Links/Links.php b/lib/Newsletter/Links/Links.php
index c4170b0193..140a2f411f 100644
--- a/lib/Newsletter/Links/Links.php
+++ b/lib/Newsletter/Links/Links.php
@@ -14,6 +14,9 @@ class Links {
const DATA_TAG_OPEN = '[mailpoet_open_data]';
const HASH_LENGTH = 5;
+ const LINK_TYPE_SHORTCODE = 'shortcode';
+ const LINK_TYPE_LINK = 'link';
+
static function extract($content) {
$extracted_links = array();
// adopted from WP's wp_extract_urls() function & modified to work on hrefs
@@ -39,6 +42,7 @@ class Links {
if($shortcodes) {
$extracted_links = array_map(function($shortcode) {
return array(
+ 'type' => self::LINK_TYPE_SHORTCODE,
'html' => $shortcode,
'link' => $shortcode
);
@@ -50,6 +54,7 @@ class Links {
if($matched_urls_count) {
for($index = 0; $index < $matched_urls_count; $index++) {
$extracted_links[] = array(
+ 'type' => self::LINK_TYPE_LINK,
'html' => $matched_urls[0][$index],
'link' => $matched_urls[2][$index]
);
diff --git a/tests/unit/Newsletter/Links/LinksTest.php b/tests/unit/Newsletter/Links/LinksTest.php
index 8e3f85c54e..18ab17cd4c 100644
--- a/tests/unit/Newsletter/Links/LinksTest.php
+++ b/tests/unit/Newsletter/Links/LinksTest.php
@@ -15,6 +15,7 @@ class LinksTest extends MailPoetTest {
expect($result[0])->equals(
array(
+ 'type' => Links::LINK_TYPE_LINK,
'html' => 'href="http://link1.com"',
'link' => 'http://link1.com'
)
@@ -27,6 +28,7 @@ class LinksTest extends MailPoetTest {
expect($result[0])->equals(
array(
+ 'type' => Links::LINK_TYPE_SHORTCODE,
'html' => '[link:some_link_shortcode]',
'link' => '[link:some_link_shortcode]'
)
@@ -139,7 +141,7 @@ class LinksTest extends MailPoetTest {
$newsletter_link->url = '[link:newsletter_view_in_browser_url]';
$newsletter_link = $newsletter_link->save();
$content = '
- View in browser
+ View in browser
Some link';
$result = Links::convertHashedLinksToShortcodesAndUrls($content);
expect($result)->contains($newsletter_link->url);
@@ -161,7 +163,7 @@ class LinksTest extends MailPoetTest {
$newsletter_link_2->url = 'http://google.com';
$newsletter_link_2 = $newsletter_link_2->save();
$content = '
- View in browser
+ View in browser
Some link';
$result = Links::convertHashedLinksToShortcodesAndUrls($content, $convert_all = true);
expect($result)->contains($newsletter_link_1->url);