diff --git a/assets/css/src/newsletter_editor/libraryOverrides.styl b/assets/css/src/newsletter_editor/libraryOverrides.styl index 78491b2929..12c509df0d 100644 --- a/assets/css/src/newsletter_editor/libraryOverrides.styl +++ b/assets/css/src/newsletter_editor/libraryOverrides.styl @@ -31,7 +31,7 @@ div.mce-toolbar-grp.mce-container box-shadow(0px 0px 3px 1px rgba(0, 0, 0, 0.05)) .mce-window - /* Fix TinyMCE mailpoet_custom_fields window lack of hiding overflow */ + /* Fix TinyMCE mailpoet_shortcodes window lack of hiding overflow */ div.mce-container-body.mce-abs-layout overflow: hidden @@ -40,8 +40,8 @@ div.mce-toolbar-grp.mce-container width: -webkit-calc( 100% - 36px ) width: calc( 100% - 36px ) -/* TinyMCE mailpoet_custom_fields toolbar icon */ -.mce-i-mailpoet_custom_fields:before +/* TinyMCE mailpoet_shortcodes toolbar icon */ +.mce-i-mailpoet_shortcodes:before font: 400 20px/1 dashicons!important content: "\f307" diff --git a/assets/js/lib/mailpoet_custom_fields b/assets/js/lib/mailpoet_custom_fields deleted file mode 120000 index 8af63bfa98..0000000000 --- a/assets/js/lib/mailpoet_custom_fields +++ /dev/null @@ -1 +0,0 @@ -../src/newsletter_editor/tinymce/mailpoet_custom_fields \ No newline at end of file diff --git a/assets/js/lib/mailpoet_shortcodes b/assets/js/lib/mailpoet_shortcodes new file mode 120000 index 0000000000..6a526a0174 --- /dev/null +++ b/assets/js/lib/mailpoet_shortcodes @@ -0,0 +1 @@ +../src/newsletter_editor/tinymce/mailpoet_shortcodes \ No newline at end of file diff --git a/assets/js/src/newsletter_editor/blocks/footer.js b/assets/js/src/newsletter_editor/blocks/footer.js index 9581643b45..2fd0882a5e 100644 --- a/assets/js/src/newsletter_editor/blocks/footer.js +++ b/assets/js/src/newsletter_editor/blocks/footer.js @@ -56,7 +56,7 @@ define([ inline: true, menubar: false, - toolbar: "bold italic link unlink forecolor mailpoet_custom_fields", + toolbar: "bold italic link unlink forecolor mailpoet_shortcodes", valid_elements: "p[class|style],span[class|style],a[href|class|title|target|style],strong[class|style],em[class|style],strike,br", invalid_elements: "script", @@ -64,7 +64,7 @@ define([ relative_urls: false, remove_script_host: false, - plugins: "link textcolor colorpicker mailpoet_custom_fields", + plugins: "link textcolor colorpicker mailpoet_shortcodes", setup: function(editor) { editor.on('change', function(e) { @@ -80,8 +80,8 @@ define([ }); }, - mailpoet_custom_fields: App.getConfig().get('customFields').toJSON(), - mailpoet_custom_fields_window_title: MailPoet.I18n.t('customFieldsWindowTitle'), + mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(), + mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle'), }); }, }); diff --git a/assets/js/src/newsletter_editor/blocks/header.js b/assets/js/src/newsletter_editor/blocks/header.js index 81a3bba510..0d5418f6f9 100644 --- a/assets/js/src/newsletter_editor/blocks/header.js +++ b/assets/js/src/newsletter_editor/blocks/header.js @@ -56,7 +56,7 @@ define([ inline: true, menubar: false, - toolbar: "bold italic link unlink forecolor mailpoet_custom_fields", + toolbar: "bold italic link unlink forecolor mailpoet_shortcodes", valid_elements: "p[class|style],span[class|style],a[href|class|title|target|style],strong[class|style],em[class|style],strike,br", invalid_elements: "script", @@ -64,7 +64,7 @@ define([ relative_urls: false, remove_script_host: false, - plugins: "link textcolor colorpicker mailpoet_custom_fields", + plugins: "link textcolor colorpicker mailpoet_shortcodes", setup: function(editor) { editor.on('change', function(e) { @@ -80,8 +80,8 @@ define([ }); }, - mailpoet_custom_fields: App.getConfig().get('customFields').toJSON(), - mailpoet_custom_fields_window_title: MailPoet.I18n.t('customFieldsWindowTitle'), + mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(), + mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle'), }); }, }); diff --git a/assets/js/src/newsletter_editor/blocks/text.js b/assets/js/src/newsletter_editor/blocks/text.js index 9d46f975e8..9c62104f13 100644 --- a/assets/js/src/newsletter_editor/blocks/text.js +++ b/assets/js/src/newsletter_editor/blocks/text.js @@ -53,7 +53,7 @@ define([ menubar: false, toolbar1: "formatselect bold italic forecolor | link unlink", - toolbar2: "alignleft aligncenter alignright alignjustify | bullist numlist blockquote | code mailpoet_custom_fields", + toolbar2: "alignleft aligncenter alignright alignjustify | bullist numlist blockquote | code mailpoet_shortcodes", //forced_root_block: 'p', valid_elements: "p[class|style],span[class|style],a[href|class|title|target|style],h1[class|style],h2[class|style],h3[class|style],ol[class|style],ul[class|style],li[class|style],strong[class|style],em[class|style],strike,br,blockquote[class|style],table[class|style],tr[class|style],th[class|style],td[class|style]", @@ -62,7 +62,7 @@ define([ relative_urls: false, remove_script_host: false, - plugins: "link code textcolor colorpicker mailpoet_custom_fields", + plugins: "link code textcolor colorpicker mailpoet_shortcodes", setup: function(editor) { editor.on('change', function(e) { @@ -78,8 +78,8 @@ define([ }); }, - mailpoet_custom_fields: App.getConfig().get('customFields').toJSON(), - mailpoet_custom_fields_window_title: MailPoet.I18n.t('customFieldsWindowTitle'), + mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(), + mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle'), }); } }, diff --git a/assets/js/src/newsletter_editor/tinymce/mailpoet_custom_fields/plugin.js b/assets/js/src/newsletter_editor/tinymce/mailpoet_custom_fields/plugin.js deleted file mode 100644 index ca7e5fe434..0000000000 --- a/assets/js/src/newsletter_editor/tinymce/mailpoet_custom_fields/plugin.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * wysija_custom_fields/plugin.js - * - * TinyMCE plugin for adding dynamic data placeholders to newsletters. - * - * This adds a button to the editor toolbar which displays a modal window of - * available dynamic data placeholder buttons. On click each button inserts - * its placeholder into editor text. - */ - -/*jshint unused:false */ -/*global tinymce:true */ -tinymce.PluginManager.add('mailpoet_custom_fields', function(editor, url) { - var appendLabelAndClose = function(text) { - editor.insertContent('[' + text + ']'); - editor.windowManager.close(); - }, - generateOnClickFunc = function(id) { - return function() { - appendLabelAndClose(id); - }; - }; - - editor.addButton('mailpoet_custom_fields', { - icon: 'mailpoet_custom_fields', - onclick: function() { - var customFields = [], - configCustomFields = editor.settings.mailpoet_custom_fields; - - for (var segment in configCustomFields) { - if (configCustomFields.hasOwnProperty(segment)) { - customFields.push({ - type: 'label', - text: segment, - }); - - for (var i = 0; i < configCustomFields[segment].length; i += 1) { - customFields.push({ - type: 'button', - text: configCustomFields[segment][i].text, - onClick: generateOnClickFunc(configCustomFields[segment][i].shortcode) - }); - } - } - } - - // Open window - editor.windowManager.open({ - height: parseInt(editor.getParam("plugin_mailpoet_custom_fields_height", 400)), - width: parseInt(editor.getParam("plugin_mailpoet_custom_fields_width", 450)), - autoScroll: true, - title: editor.settings.mailpoet_custom_fields_window_title, - body: customFields, - buttons: [], - }); - }, - }); -}); diff --git a/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes/plugin.js b/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes/plugin.js new file mode 100644 index 0000000000..e0f08040c9 --- /dev/null +++ b/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes/plugin.js @@ -0,0 +1,58 @@ +/** + * wysija_shortcodes/plugin.js + * + * TinyMCE plugin for adding dynamic data placeholders to newsletters. + * + * This adds a button to the editor toolbar which displays a modal window of + * available dynamic data placeholder buttons. On click each button inserts + * its placeholder into editor text. + */ + +/*jshint unused:false */ +/*global tinymce:true */ +tinymce.PluginManager.add('mailpoet_shortcodes', function(editor, url) { + var appendLabelAndClose = function(text) { + editor.insertContent('[' + text + ']'); + editor.windowManager.close(); + }, + generateOnClickFunc = function(id) { + return function() { + appendLabelAndClose(id); + }; + }; + + editor.addButton('mailpoet_shortcodes', { + icon: 'mailpoet_shortcodes', + onclick: function() { + var shortcodes = [], + configShortcodes = editor.settings.mailpoet_shortcodes; + + for (var segment in configShortcodes) { + if (configShortcodes.hasOwnProperty(segment)) { + shortcodes.push({ + type: 'label', + text: segment, + }); + + for (var i = 0; i < configShortcodes[segment].length; i += 1) { + shortcodes.push({ + type: 'button', + text: configShortcodes[segment][i].text, + onClick: generateOnClickFunc(configShortcodes[segment][i].shortcode) + }); + } + } + } + + // Open window + editor.windowManager.open({ + height: parseInt(editor.getParam("plugin_mailpoet_shortcodes_height", 400)), + width: parseInt(editor.getParam("plugin_mailpoet_shortcodes_width", 450)), + autoScroll: true, + title: editor.settings.mailpoet_shortcodes_window_title, + body: shortcodes, + buttons: [], + }); + }, + }); +}); diff --git a/assets/js/src/newsletter_editor/tinymce/mailpoet_custom_fields/plugin.min.js b/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes/plugin.min.js similarity index 100% rename from assets/js/src/newsletter_editor/tinymce/mailpoet_custom_fields/plugin.min.js rename to assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes/plugin.min.js diff --git a/lib/Config/Menu.php b/lib/Config/Menu.php index 93bb7caf58..0d00431dc3 100644 --- a/lib/Config/Menu.php +++ b/lib/Config/Menu.php @@ -7,6 +7,7 @@ use MailPoet\Models\CustomField; use MailPoet\Models\Form; use MailPoet\Models\Segment; use MailPoet\Models\Setting; +use MailPoet\Newsletter\Shortcodes\ShortcodesHelper; use MailPoet\Settings\Charsets; use MailPoet\Settings\Hosts; use MailPoet\Settings\Pages; @@ -419,15 +420,8 @@ class Menu { } function newletterEditor() { - $custom_fields = array_map(function($field) { - return array( - 'text' => $field['name'], - 'shortcode' => 'field:' . $field['id'], - ); - }, CustomField::findArray()); - $data = array( - 'customFields' => $custom_fields, + 'shortcodes' => ShortcodesHelper::getShortcodes(), 'settings' => Setting::getAll(), 'sub_menu' => 'mailpoet-newsletters' ); diff --git a/lib/Newsletter/Shortcodes/Categories/Date.php b/lib/Newsletter/Shortcodes/Categories/Date.php index f066c1d510..dfa7ef9dda 100644 --- a/lib/Newsletter/Shortcodes/Categories/Date.php +++ b/lib/Newsletter/Shortcodes/Categories/Date.php @@ -2,32 +2,6 @@ namespace MailPoet\Newsletter\Shortcodes\Categories; class Date { - /* - { - text: '<%= __('Current day of the month number') %>', - shortcode: 'date:d', - }, - { - text: '<%= __('Current day of the month in ordinal, ie. 2nd, 3rd, etc.') %>', - shortcode: 'date:dordinal', - }, - { - text: '<%= __('Full name of current day') %>', - shortcode: 'date:dtext', - }, - { - text: '<%= __('Current month number') %>', - shortcode: 'date:m', - }, - { - text: '<%= __('Full name of current month') %>', - shortcode: 'date:mtext', - }, - { - text: '<%= __('Year') %>', - shortcode: 'date:y', - } - */ static function process($action) { $date = new \DateTime('now'); $actions = array( diff --git a/lib/Newsletter/Shortcodes/Categories/Link.php b/lib/Newsletter/Shortcodes/Categories/Link.php index a223e65d24..c26f987ec4 100644 --- a/lib/Newsletter/Shortcodes/Categories/Link.php +++ b/lib/Newsletter/Shortcodes/Categories/Link.php @@ -2,25 +2,11 @@ namespace MailPoet\Newsletter\Shortcodes\Categories; use MailPoet\Models\Setting; -use MailPoet\Models\Subscriber; +use MailPoet\Models\Subscriber as SubscriberModel; use MailPoet\Statistics\Track\Unsubscribes; use MailPoet\Subscription\Url as SubscriptionUrl; class Link { - /* - { - text: '<%= __('Unsubscribe') %>',- - shortcode: 'subscription:unsubscribe', - }, - { - text: '<%= __('Manage subscription') %>', - shortcode: 'subscription:manage', - }, - { - text: '<%= __('View in browser link') %>', - shortcode: 'newsletter:view_in_browser', - } - */ static function process($action, $default_value = false, $newsletter, @@ -116,7 +102,7 @@ class Link { $subscriber['id'] : $subscriber, 'subscriber_token' => (isset($subscriber['id'])) ? - Subscriber::generateToken($subscriber['email']) : + SubscriberModel::generateToken($subscriber['email']) : false, 'queue' => (isset($queue['id'])) ? $queue['id'] : diff --git a/lib/Newsletter/Shortcodes/Categories/Newsletter.php b/lib/Newsletter/Shortcodes/Categories/Newsletter.php index 1aae2059c6..576369b777 100644 --- a/lib/Newsletter/Shortcodes/Categories/Newsletter.php +++ b/lib/Newsletter/Shortcodes/Categories/Newsletter.php @@ -7,28 +7,6 @@ use MailPoet\Newsletter\Shortcodes\ShortcodesHelper; require_once( ABSPATH . "wp-includes/pluggable.php" ); class Newsletter { - /* - { - text: '<%= __('Newsletter Subject') %>',- - shortcode: 'newsletter:subject', - }, - { - text: '<%= __('Total number of posts or pages') %>', - shortcode: 'newsletter:total', - }, - { - text: '<%= __('Latest post title') %>', - shortcode: 'newsletter:post_title', - }, - { - text: '<%= __('Issue number') %>', - shortcode: 'newsletter:number', - }, - { - text: '<%= __('Issue number') %>', - shortcode: 'newsletter:number', - } - */ static function process($action, $default_value = false, $newsletter, diff --git a/lib/Newsletter/Shortcodes/Categories/User.php b/lib/Newsletter/Shortcodes/Categories/Subscriber.php similarity index 51% rename from lib/Newsletter/Shortcodes/Categories/User.php rename to lib/Newsletter/Shortcodes/Categories/Subscriber.php index 10cef17d34..0ddba1efc4 100644 --- a/lib/Newsletter/Shortcodes/Categories/User.php +++ b/lib/Newsletter/Shortcodes/Categories/Subscriber.php @@ -1,67 +1,51 @@ -', - shortcode: 'user:firstname | default:reader', - }, - { - text: '<%= __('Last Name') %>', - shortcode: 'user:lastname | default:reader', - }, - { - text: '<%= __('Email Address') %>', - shortcode: 'user:email', - }, - { - text: '<%= __('Wordpress user display name') %>', - shortcode: 'user:displayname | default:member', - }, - { - text: '<%= __('Total of subscribers') %>', - shortcode: 'user:count', - } - */ - static function process( - $action, - $default_value, - $newsletter = false, - $subscriber - ) { - switch($action) { - case 'firstname': - return ($subscriber) ? $subscriber['first_name'] : $default_value; - break; - - case 'lastname': - return ($subscriber) ? $subscriber['last_name'] : $default_value; - break; - - case 'email': - return ($subscriber) ? $subscriber['email'] : false; - break; - - case 'displayname': - if($subscriber && $subscriber['wp_user_id']) { - $wp_user = get_userdata($subscriber['wp_user_id']); - return $wp_user->user_login; - } - return $default_value; - break; - - case 'count': - return Subscriber::filter('subscribed')->count(); - break; - - default: - return false; - break; - } - } +user_login; + } + return $default_value; + break; + case 'count': + return SubscriberModel::filter('subscribed') + ->count(); + break; + default: + if(preg_match('/cf_(\d+)/', $action, $custom_field) && + !empty($subscriber['id']) + ) { + $custom_field = SubscriberCustomField + ::where('subscriber_id', $subscriber['id']) + ->where('custom_field_id', $custom_field[1]) + ->findOne(); + return ($custom_field) ? $custom_field->value : false; + } + return false; + break; + } + } } \ No newline at end of file diff --git a/lib/Newsletter/Shortcodes/ShortcodesHelper.php b/lib/Newsletter/Shortcodes/ShortcodesHelper.php new file mode 100644 index 0000000000..9768ebeccc --- /dev/null +++ b/lib/Newsletter/Shortcodes/ShortcodesHelper.php @@ -0,0 +1,113 @@ + array( + array( + 'text' => __('First Name'), + 'shortcode' => 'subscriber:firstname | default:reader', + ), + array( + 'text' => __('Last Name'), + 'shortcode' => 'subscriber:lastname | default:reader', + ), + array( + 'text' => __('Email Address'), + 'shortcode' => 'subscriber:email', + ), + array( + 'text' => __('Wordpress user display name'), + 'shortcode' => 'subscriber:displayname | default:member', + ), + array( + 'text' => __('Total of subscribers'), + 'shortcode' => 'subscriber:count', + ) + ), + __('Newsletter') => array( + array( + 'text' => __('Newsletter Subject'), + 'shortcode' => 'newsletter:subject', + ) + ), + __('Post Notifications') => array( + array( + 'text' => __('Total number of posts or pages'), + 'shortcode' => 'newsletter:total', + ), + array( + 'text' => __('Latest post title'), + 'shortcode' => 'newsletter:post_title', + ), + array( + 'text' => __('Issue number'), + 'shortcode' => 'newsletter:number', + ) + ), + __('Date') => array( + array( + 'text' => __('Current day of the month number'), + 'shortcode' => 'date:d', + ), + array( + 'text' => __('Current day of the month in ordinal, ie. 2nd, 3rd, etc.'), + 'shortcode' => 'date:dordinal', + ), + array( + 'text' => __('Full name of current day'), + 'shortcode' => 'date:dtext', + ), + array( + 'text' => __('Current month number'), + 'shortcode' => 'date:m', + ), + array( + 'text' => __('Full name of current month'), + 'shortcode' => 'date:mtext', + ), + array( + 'text' => __('Year'), + 'shortcode' => 'date:y', + ) + ), + __('Links') => array( + array( + 'text' => __('Unsubscribe link'), + 'shortcode' => 'link:subscription_unsubscribe', + ), + array( + 'text' => __('Edit subscription page link'), + 'shortcode' => 'link:subscription_manage', + ), + array( + 'text' => __('View in browser link'), + 'shortcode' => 'link:newsletter_view_in_browser', + ) + ) + ); + $custom_fields = self::getCustomFields(); + if($custom_fields) { + $shortcodes[__('Subscriber')] = array_merge( + $shortcodes[__('Subscriber')], + $custom_fields + ); + } + return $shortcodes; + } + + static function getCustomFields() { + $custom_fields = CustomField::findMany(); + if(!$custom_fields) return false; + return array_map(function ($custom_field) { + return array( + 'text' => $custom_field->name, + 'shortcode' => 'subscriber:cf_' . $custom_field->id + ); + }, $custom_fields); + } +} \ No newline at end of file diff --git a/tests/unit/Newsletter/ShortcodesHelperTest.php b/tests/unit/Newsletter/ShortcodesHelperTest.php new file mode 100644 index 0000000000..1fd0edca4a --- /dev/null +++ b/tests/unit/Newsletter/ShortcodesHelperTest.php @@ -0,0 +1,38 @@ +equals( + array( + 'Subscriber', + 'Newsletter', + 'Post Notifications', + 'Date', + 'Links' + ) + ); + } + + function testItCanGetCustomShortShortcodes() { + $shortcodes = ShortcodesHelper::getShortcodes(); + expect(count($shortcodes['Subscriber']))->equals(5); + $custom_field = CustomField::create(); + $custom_field->name = 'name'; + $custom_field->type = 'type'; + $custom_field->save(); + $shortcodes = ShortcodesHelper::getShortcodes(); + expect(count($shortcodes['Subscriber']))->equals(6); + $custom_subscriber_shortcode = end($shortcodes['Subscriber']); + expect($custom_subscriber_shortcode['text'])->equals($custom_field->name); + expect($custom_subscriber_shortcode['shortcode']) + ->equals('subscriber:cf_' . $custom_field->id); + } + + function _after() { + ORM::raw_execute('TRUNCATE ' . CustomField::$_table); + } +} \ No newline at end of file diff --git a/tests/unit/Newsletter/ShortcodesTest.php b/tests/unit/Newsletter/ShortcodesTest.php index 6dce3a37ca..50c394a1d4 100644 --- a/tests/unit/Newsletter/ShortcodesTest.php +++ b/tests/unit/Newsletter/ShortcodesTest.php @@ -1,9 +1,11 @@ equals(2); } - function testItCanProcessUserShortcodes() { + function testItCanProcessSubscriberShortcodes() { $shortcodes_object = $this->shortcodes_object; $result = - $shortcodes_object->process(array('[user:firstname]')); + $shortcodes_object->process(array('[subscriber:firstname]')); expect($result[0])->equals($this->subscriber->first_name); $result = - $shortcodes_object->process(array('[user:lastname]')); + $shortcodes_object->process(array('[subscriber:lastname]')); expect($result[0])->equals($this->subscriber->last_name); $result = - $shortcodes_object->process(array('[user:displayname]')); + $shortcodes_object->process(array('[subscriber:displayname]')); expect($result[0])->equals($this->WP_user->user_login); $subscribers = Subscriber::where('status', 'subscribed') ->findMany(); $subscriber_count = count($subscribers); $result = - $shortcodes_object->process(array('[user:count]')); + $shortcodes_object->process(array('[subscriber:count]')); expect($result[0])->equals($subscriber_count); $this->subscriber->status = 'unsubscribed'; $this->subscriber->save(); $result = - $shortcodes_object->process(array('[user:count]')); + $shortcodes_object->process(array('[subscriber:count]')); expect($result[0])->equals(--$subscriber_count); } + function testItCanProcessSubscriberCustomFieldShortcodes() { + $shortcodes_object = $this->shortcodes_object; + $subscriber = $this->subscriber; + $custom_field = CustomField::create(); + $custom_field->name = 'custom_field_name'; + $custom_field->type = 'text'; + $custom_field->save(); + $result = $shortcodes_object->process( + array('[subscriber:cf_' . $custom_field->id . ']') + ); + expect($result[0])->false(); + $subscriber_custom_field = SubscriberCustomField::create(); + $subscriber_custom_field->subscriber_id = $subscriber->id; + $subscriber_custom_field->custom_field_id = $custom_field->id; + $subscriber_custom_field->value = 'custom_field_value'; + $subscriber_custom_field->save(); + $result = $shortcodes_object->process( + array('[subscriber:cf_' . $custom_field->id . ']') + ); + expect($result[0])->equals($subscriber_custom_field->value); + } + function testItCanProcessLinkShortcodes() { $shortcodes_object = $this->shortcodes_object; $result = @@ -245,6 +269,8 @@ class ShortcodesTest extends MailPoetTest { function _after() { ORM::raw_execute('TRUNCATE ' . Subscriber::$_table); ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table); + ORM::raw_execute('TRUNCATE ' . CustomField::$_table); + ORM::raw_execute('TRUNCATE ' . SubscriberCustomField::$_table); wp_delete_post($this->WP_post, true); wp_delete_user($this->WP_user->ID); } diff --git a/views/newsletter/editor.html b/views/newsletter/editor.html index 77c815a80c..fac7cf6537 100644 --- a/views/newsletter/editor.html +++ b/views/newsletter/editor.html @@ -317,7 +317,7 @@ <%= localize({ 'failedToFetchAvailablePosts': __('Failed to fetch available posts'), 'failedToFetchRenderedPosts': __('Failed to fetch rendered posts'), - 'customFieldsWindowTitle': __('Select a shortcode'), + 'shortcodesWindowTitle': __('Select a shortcode'), 'unsubscribeLinkMissing': __('All newsletters must include an "unsubscribe" link. Add a footer widget to your newsletter to continue.'), 'newsletterPreviewEmailMissing': __('Please enter an email where newsletter preview should be sent to.'), 'newsletterPreviewFailed': __('Preview failed. Pleae check console log.'), @@ -340,7 +340,7 @@ <%= javascript( 'lib/tinymce/tinymce.jquery.min.js', 'lib/tinymce/jquery.tinymce.min.js', - 'lib/mailpoet_custom_fields/plugin.js', + 'lib/mailpoet_shortcodes/plugin.js', 'lib/wplink/plugin.js', 'newsletter_editor.js' ) %> @@ -1168,93 +1168,7 @@ }, }, }, - customFields: { - '<%= __('Subscriber') %>': [ - { - text: '<%= __('First Name') %>', - shortcode: 'user:firstname | default:reader', - }, - { - text: '<%= __('Last Name') %>', - shortcode: 'user:lastname | default:reader', - }, - { - text: '<%= __('Email Address') %>', - shortcode: 'user:email', - }, - { - text: '<%= __('Wordpress user display name') %>', - shortcode: 'user:displayname | default:member', - }, - { - text: '<%= __('Total of subscribers') %>', - shortcode: 'user:count', - } - ], - '<%= __('Newsletter') %>': [ - { - text: '<%= __('Newsletter Subject') %>', - shortcode: 'newsletter:subject', - }, - ], - '<%= __('Post Notifications') %>': [ - { - text: '<%= __('Total number of posts or pages') %>', - shortcode: 'newsletter:total', - }, - { - text: '<%= __('Latest post title') %>', - shortcode: 'newsletter:post_title', - }, - { - text: '<%= __('Issue number') %>', - shortcode: 'newsletter:number', - } - ], - '<%= __('Date') %>': [ - { - text: '<%= __('Current day of the month number') %>', - shortcode: 'date:d', - }, - { - text: '<%= __('Current day of the month in ordinal, ie. 2nd, 3rd, etc.') %>', - shortcode: 'date:dordinal', - }, - { - text: '<%= __('Full name of current day') %>', - shortcode: 'date:dtext', - }, - { - text: '<%= __('Current month number') %>', - shortcode: 'date:m', - }, - { - text: '<%= __('Full name of current month') %>', - shortcode: 'date:mtext', - }, - { - text: '<%= __('Year') %>', - shortcode: 'date:y', - } - ], - '<%= __('Links') %>': [ - { - text: '<%= __('Unsubscribe link') %>', - shortcode: 'link:subscription_unsubscribe', - }, - { - text: '<%= __('Edit subscription page link') %>', - shortcode: 'link:subscription_manage', - }, - { - text: '<%= __('View in browser link') %>', - shortcode: 'link:newsletter_view_in_browser', - } - ], - <% if customFields %> - '<%= __('Custom fields') %>': <%= json_encode(customFields) %>, - <% endif %> - }, + shortcodes: <%= json_encode(shortcodes) %>, sidepanelWidth: '331px', validation: { validateUnsubscribeLinkPresent: true, // TODO: Add validation based on whether Mailpoet MTA is used or not