Categories
3 days ago
Shortcodes.php
2 months ago
ShortcodesHelper.php
4 days ago
index.php
3 years ago
ShortcodesHelper.php
164 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Newsletter\Shortcodes; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\CustomFields\CustomFieldsRepository; |
| 9 | use MailPoet\Entities\NewsletterLinkEntity; |
| 10 | |
| 11 | class ShortcodesHelper { |
| 12 | /** @var CustomFieldsRepository */ |
| 13 | private $customFieldsRepository; |
| 14 | |
| 15 | public function __construct( |
| 16 | CustomFieldsRepository $customFieldsRepository |
| 17 | ) { |
| 18 | $this->customFieldsRepository = $customFieldsRepository; |
| 19 | } |
| 20 | |
| 21 | public function getShortcodes(): array { |
| 22 | $shortcodes = [ |
| 23 | __('Subscriber', 'mailpoet') => [ |
| 24 | [ |
| 25 | 'text' => __('First Name', 'mailpoet'), |
| 26 | 'shortcode' => '[subscriber:firstname | default:reader]', |
| 27 | ], |
| 28 | [ |
| 29 | 'text' => __('Last Name', 'mailpoet'), |
| 30 | 'shortcode' => '[subscriber:lastname | default:reader]', |
| 31 | ], |
| 32 | [ |
| 33 | 'text' => __('Email Address', 'mailpoet'), |
| 34 | 'shortcode' => '[subscriber:email]', |
| 35 | ], |
| 36 | [ |
| 37 | 'text' => __('WordPress User Display Name', 'mailpoet'), |
| 38 | 'shortcode' => '[subscriber:displayname | default:member]', |
| 39 | ], |
| 40 | [ |
| 41 | 'text' => __('Total Number of Subscribers', 'mailpoet'), |
| 42 | 'shortcode' => '[subscriber:count]', |
| 43 | ], |
| 44 | ], |
| 45 | __('Newsletter', 'mailpoet') => [ |
| 46 | [ |
| 47 | 'text' => __('Newsletter Subject', 'mailpoet'), |
| 48 | 'shortcode' => '[newsletter:subject]', |
| 49 | ], |
| 50 | ], |
| 51 | __('Post Notifications', 'mailpoet') => [ |
| 52 | [ |
| 53 | 'text' => __('Total Number of Posts or Pages', 'mailpoet'), |
| 54 | 'shortcode' => '[newsletter:total]', |
| 55 | ], |
| 56 | [ |
| 57 | 'text' => __('Most Recent Post Title', 'mailpoet'), |
| 58 | 'shortcode' => '[newsletter:post_title]', |
| 59 | ], |
| 60 | [ |
| 61 | 'text' => __('Issue Number', 'mailpoet'), |
| 62 | 'shortcode' => '[newsletter:number]', |
| 63 | ], |
| 64 | ], |
| 65 | __('Date', 'mailpoet') => [ |
| 66 | [ |
| 67 | 'text' => __('Current day of the month number', 'mailpoet'), |
| 68 | 'shortcode' => '[date:d]', |
| 69 | ], |
| 70 | [ |
| 71 | 'text' => __('Current day of the month in ordinal form, i.e. 2nd, 3rd, 4th, etc.', 'mailpoet'), |
| 72 | 'shortcode' => '[date:dordinal]', |
| 73 | ], |
| 74 | [ |
| 75 | 'text' => __('Full name of current day', 'mailpoet'), |
| 76 | 'shortcode' => '[date:dtext]', |
| 77 | ], |
| 78 | [ |
| 79 | 'text' => __('Current month number', 'mailpoet'), |
| 80 | 'shortcode' => '[date:m]', |
| 81 | ], |
| 82 | [ |
| 83 | 'text' => __('Full name of current month', 'mailpoet'), |
| 84 | 'shortcode' => '[date:mtext]', |
| 85 | ], |
| 86 | [ |
| 87 | 'text' => __('Year', 'mailpoet'), |
| 88 | 'shortcode' => '[date:y]', |
| 89 | ], |
| 90 | ], |
| 91 | __('Links', 'mailpoet') => [ |
| 92 | [ |
| 93 | 'text' => __('Unsubscribe link', 'mailpoet'), |
| 94 | 'shortcode' => sprintf( |
| 95 | '<a target="_blank" href="%s">%s</a>', |
| 96 | NewsletterLinkEntity::UNSUBSCRIBE_LINK_SHORT_CODE, |
| 97 | __('Unsubscribe', 'mailpoet') |
| 98 | ), |
| 99 | ], |
| 100 | [ |
| 101 | 'text' => __('Edit subscription page link', 'mailpoet'), |
| 102 | 'shortcode' => sprintf( |
| 103 | '<a target="_blank" href="%s">%s</a>', |
| 104 | '[link:subscription_manage_url]', |
| 105 | __('Manage subscription', 'mailpoet') |
| 106 | ), |
| 107 | ], |
| 108 | [ |
| 109 | 'text' => __('View in browser link', 'mailpoet'), |
| 110 | 'shortcode' => sprintf( |
| 111 | '<a target="_blank" href="%s">%s</a>', |
| 112 | '[link:newsletter_view_in_browser_url]', |
| 113 | __('View in your browser', 'mailpoet') |
| 114 | ), |
| 115 | ], |
| 116 | [ |
| 117 | 'text' => __('Tracking opt-out link', 'mailpoet'), |
| 118 | 'shortcode' => sprintf( |
| 119 | '<a target="_blank" href="%s">%s</a>', |
| 120 | '[link:subscription_tracking_opt_out_url]', |
| 121 | __('Opt out of tracking', 'mailpoet') |
| 122 | ), |
| 123 | ], |
| 124 | ], |
| 125 | __('Site', 'mailpoet') => [ |
| 126 | [ |
| 127 | 'text' => __('Site title', 'mailpoet'), |
| 128 | 'shortcode' => '[site:title]', |
| 129 | ], |
| 130 | [ |
| 131 | 'text' => __('Homepage link', 'mailpoet'), |
| 132 | 'shortcode' => sprintf( |
| 133 | '<a target="_blank" href="%s">%s</a>', |
| 134 | '[site:homepage_url]', |
| 135 | '[site:title]' |
| 136 | ), |
| 137 | ], |
| 138 | [ |
| 139 | 'text' => __('Homepage URL', 'mailpoet'), |
| 140 | 'shortcode' => '[site:homepage_url]', |
| 141 | ], |
| 142 | ], |
| 143 | ]; |
| 144 | $customFields = $this->getCustomFields(); |
| 145 | if (count($customFields) > 0) { |
| 146 | $shortcodes[__('Subscriber', 'mailpoet')] = array_merge( |
| 147 | $shortcodes[__('Subscriber', 'mailpoet')], |
| 148 | $customFields |
| 149 | ); |
| 150 | } |
| 151 | return $shortcodes; |
| 152 | } |
| 153 | |
| 154 | public function getCustomFields(): array { |
| 155 | $customFields = $this->customFieldsRepository->findAllActive(); |
| 156 | return array_map(function($customField) { |
| 157 | return [ |
| 158 | 'text' => $customField->getName(), |
| 159 | 'shortcode' => '[subscriber:cf_' . $customField->getId() . ']', |
| 160 | ]; |
| 161 | }, $customFields); |
| 162 | } |
| 163 | } |
| 164 |