PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Admin / SettingsPages / EmailSettings / EmailSettingsPage.php
wp-user-avatar / src / Admin / SettingsPages / EmailSettings Last commit date
CustomizerTrait.php 5 years ago DefaultTemplateCustomizer.php 3 years ago EmailSettingsPage.php 1 year ago WPListTable.php 4 years ago email-template-preview.php 5 years ago
EmailSettingsPage.php
573 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages\EmailSettings;
4
5 use ProfilePress\Core\Classes\SendEmail;
6 use ProfilePress\Core\Membership\Emails\EmailDataTrait;
7 use ProfilePress\Custom_Settings_Page_Api;
8
9 class EmailSettingsPage
10 {
11 use EmailDataTrait;
12
13 const ACCOUNT_EMAIL_TYPE = 'account';
14 const ORDER_EMAIL_TYPE = 'order';
15 const SUBSCRIPTION_EMAIL_TYPE = 'subscription';
16
17 public $email_notification_list_table;
18
19 public $settingsPageInstance;
20
21 public function __construct()
22 {
23 add_filter('ppress_settings_page_submenus_tabs', [$this, 'menu_tab']);
24 add_action('ppress_admin_settings_submenu_page_email_account', [$this, 'emails_admin_page']);
25 add_action('ppress_admin_settings_submenu_page_email_order', [$this, 'emails_admin_page']);
26 add_action('ppress_admin_settings_submenu_page_email_subscription', [$this, 'emails_admin_page']);
27 add_action('ppress_admin_settings_submenu_page_email_settings', [$this, 'email_settings_admin_page']);
28
29 add_action('ppress_settings_page_screen_option', [$this, 'screen_option']);
30 add_action('admin_init', [$this, 'handle_email_preview']);
31
32 add_action('admin_enqueue_scripts', function ($hook_suffix) {
33 if ($hook_suffix == 'profilepress_page_ppress-config') {
34 wp_enqueue_script('customize-loader');
35 }
36 });
37
38 add_filter('ppress_general_settings_admin_page_title', function ($title) {
39 if (isset($_GET['view']) && $_GET['view'] == 'email') {
40 $title = $this->get_admin_title();
41 }
42
43 return $title;
44 });
45
46 add_action('ppress_register_menu_page', function () {
47
48 add_filter('wp_cspa_sanitize_skip', function ($return, $fieldkey, $value) {
49
50 if (isset($_GET['type']) && $fieldkey == sanitize_text_field($_GET['type']) . '_email_content') {
51 return stripslashes($value);
52 }
53
54 return $return;
55
56 }, 10, 3);
57
58 if (ppressGET_var('view') == 'email') {
59 $this->settingsPageInstance = Custom_Settings_Page_Api::instance('', PPRESS_SETTINGS_DB_OPTION_NAME);
60 }
61 });
62 }
63
64 public function screen_option()
65 {
66 if (isset($_GET['view']) && $_GET['view'] == 'email') {
67 add_filter('screen_options_show_screen', '__return_false');
68
69 $type = ppressGET_var('section', self::ACCOUNT_EMAIL_TYPE, true);
70
71 $this->email_notification_list_table = new WPListTable($this->email_notifications($type));
72 }
73 }
74
75 public function menu_tab($tabs)
76 {
77 $tabs[214] = [
78 'parent' => 'email',
79 'id' => 'account',
80 'label' => esc_html__('Account', 'wp-user-avatar')
81 ];
82
83 $tabs[215] = [
84 'parent' => 'email',
85 'id' => 'order',
86 'label' => esc_html__('Order', 'wp-user-avatar')
87 ];
88
89 $tabs[216] = [
90 'parent' => 'email',
91 'id' => 'subscription',
92 'label' => esc_html__('Subscription', 'wp-user-avatar')
93 ];
94
95 $tabs[217] = [
96 'parent' => 'email',
97 'id' => 'settings',
98 'label' => esc_html__('Settings', 'wp-user-avatar')
99 ];
100
101
102 return $tabs;
103 }
104
105 public function get_admin_title()
106 {
107 return esc_html__('Emails', 'wp-user-avatar');
108 }
109
110 /**
111 * @return mixed|void
112 */
113 public function email_notifications($type = '')
114 {
115 $site_title = ppress_site_title();
116
117 $notifications = apply_filters('ppress_email_notifications', [
118 [
119 'type' => self::ACCOUNT_EMAIL_TYPE,
120 'key' => 'welcome_message',
121 'title' => esc_html__('Account Welcome Email', 'wp-user-avatar'),
122 'subject' => sprintf(esc_html__('Welcome To %s', 'wp-user-avatar'), $site_title),
123 'message' => ppress_welcome_msg_content_default(),
124 'description' => esc_html__('Email that is sent to the user upon successful registration.', 'wp-user-avatar'),
125 'recipient' => esc_html__('Users', 'wp-user-avatar'),
126 'placeholders' => [
127 '{{username}}' => esc_html__('Username of the registered user.', 'wp-user-avatar'),
128 '{{userid}}' => esc_html__('User ID of the registered user.', 'wp-user-avatar'),
129 '{{email}}' => esc_html__('Email address of the registered user.', 'wp-user-avatar'),
130 '{{password}}' => esc_html__('Password of the registered user.', 'wp-user-avatar'),
131 '{{site_title}}' => esc_html__('Website title or name.', 'wp-user-avatar'),
132 '{{first_name}}' => esc_html__('First Name entered by user on registration.', 'wp-user-avatar'),
133 '{{last_name}}' => esc_html__('Last Name entered by user on registration.', 'wp-user-avatar'),
134 '{{password_reset_link}}' => esc_html__('URL to reset password.', 'wp-user-avatar'),
135 '{{login_link}}' => esc_html__('URL to login.', 'wp-user-avatar'),
136 '{{field_key}}' => sprintf(
137 esc_html__('Replace "field_key" with the %scustom field key%s or usermeta key.', 'wp-user-avatar'),
138 '<a href="' . PPRESS_CUSTOM_FIELDS_SETTINGS_PAGE . '" target="_blank">', '</a>'
139 )
140 ],
141 ],
142 [
143 'type' => self::ACCOUNT_EMAIL_TYPE,
144 'key' => 'password_reset',
145 'title' => esc_html__('Password Reset Email', 'wp-user-avatar'),
146 'subject' => sprintf(esc_html__('[%s] Password Reset', 'wp-user-avatar'), $site_title),
147 'message' => ppress_password_reset_content_default(),
148 'description' => esc_html__('Email that is sent to the user upon password reset request.', 'wp-user-avatar'),
149 'recipient' => esc_html__('Users', 'wp-user-avatar'),
150 'placeholders' => [
151 '{{username}}' => esc_html__('Username of user.', 'wp-user-avatar'),
152 '{{email}}' => esc_html__('Email address of the registered user.', 'wp-user-avatar'),
153 '{{site_title}}' => esc_html__('Website title or name.', 'wp-user-avatar'),
154 '{{password_reset_link}}' => esc_html__('URL to reset password.', 'wp-user-avatar'),
155 ]
156 ],
157 [
158 'type' => self::ACCOUNT_EMAIL_TYPE,
159 'key' => 'new_user_admin_email',
160 'title' => esc_html__('New User Admin Notification', 'wp-user-avatar'),
161 'subject' => sprintf(esc_html__('[%s] New User Registration', 'wp-user-avatar'), $site_title),
162 'message' => ppress_new_user_admin_notification_message_default(),
163 'description' => esc_html__('Email that is sent to the admin when there is a new user registration.', 'wp-user-avatar'),
164 'recipient' => ppress_get_admin_notification_emails(),
165 'placeholders' => [
166 '{{username}}' => esc_html__('Username of the newly registered user.', 'wp-user-avatar'),
167 '{{email}}' => esc_html__('Email address of the newly registered user.', 'wp-user-avatar'),
168 '{{first_name}}' => esc_html__('First name of the newly registered user.', 'wp-user-avatar'),
169 '{{last_name}}' => esc_html__('Last name of the newly registered user.', 'wp-user-avatar'),
170 '{{site_title}}' => esc_html__('Website title or name.', 'wp-user-avatar'),
171 '{{field_key}}' => sprintf(
172 esc_html__('Replace "field_key" with the %scustom field key%s or usermeta key.', 'wp-user-avatar'),
173 '<a href="' . PPRESS_CUSTOM_FIELDS_SETTINGS_PAGE . '" target="_blank">', '</a>'
174 )
175 ]
176 ],
177 [
178 'type' => self::ORDER_EMAIL_TYPE,
179 'key' => 'new_order_receipt',
180 'title' => esc_html__('New Order Receipt', 'wp-user-avatar'),
181 'subject' => sprintf(esc_html__('New Order Receipt', 'wp-user-avatar'), $site_title),
182 'message' => $this->get_order_receipt_content(),
183 'description' => esc_html__('Email sent whenever a customer completes an order.', 'wp-user-avatar'),
184 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
185 'placeholders' => $this->get_order_placeholders()
186 ],
187 [
188 'type' => self::ORDER_EMAIL_TYPE,
189 'key' => 'renewal_order_receipt',
190 'title' => esc_html__('Renewal Order Receipt', 'wp-user-avatar'),
191 'subject' => sprintf(esc_html__('Subscription Renewal Receipt', 'wp-user-avatar'), $site_title),
192 'message' => $this->get_order_receipt_content(true),
193 'description' => esc_html__('Email sent to customer whenever a renewal order occurs.', 'wp-user-avatar'),
194 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
195 'placeholders' => $this->get_order_placeholders()
196 ],
197 [
198 'type' => self::ORDER_EMAIL_TYPE,
199 'key' => 'new_order_admin_notification',
200 'title' => esc_html__('New Order Admin Notification', 'wp-user-avatar'),
201 'subject' => sprintf(esc_html__('New Order #{{order_id}}', 'wp-user-avatar'), $site_title),
202 'message' => $this->get_new_order_admin_notification_content(),
203 'description' => esc_html__('Email sent to the admin when there is a new order.', 'wp-user-avatar'),
204 'recipient' => ppress_get_admin_notification_emails(),
205 'placeholders' => $this->get_order_placeholders()
206 ],
207 [
208 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
209 'key' => 'subscription_cancelled_notification',
210 'title' => esc_html__('Subscription Cancelled Notification', 'wp-user-avatar'),
211 'subject' => sprintf(esc_html__('Your subscription has been cancelled.', 'wp-user-avatar'), $site_title),
212 'message' => $this->get_subscription_cancelled_content(),
213 'description' => esc_html__('Email sent to customer whenever their subscription is cancelled.', 'wp-user-avatar'),
214 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
215 'placeholders' => $this->get_subscription_placeholders()
216 ],
217 [
218 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
219 'key' => 'subscription_expired_notification',
220 'title' => esc_html__('Subscription Expired Notification', 'wp-user-avatar'),
221 'subject' => sprintf(esc_html__('Your subscription has expired.', 'wp-user-avatar'), $site_title),
222 'message' => $this->get_subscription_expired_content(),
223 'description' => esc_html__('Email sent to customer whenever their subscription expires.', 'wp-user-avatar'),
224 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
225 'placeholders' => $this->get_subscription_placeholders()
226 ],
227 [
228 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
229 'key' => 'subscription_completed_notification',
230 'title' => esc_html__('Subscription Completed Notification', 'wp-user-avatar'),
231 'subject' => sprintf(esc_html__('Your subscription is now complete.', 'wp-user-avatar'), $site_title),
232 'message' => $this->get_subscription_completed_content(),
233 'description' => esc_html__('Email sent to customer whenever they complete their subscription payments.', 'wp-user-avatar'),
234 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
235 'placeholders' => $this->get_subscription_placeholders()
236 ],
237 [
238 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
239 'key' => 'subscription_renewal_reminder',
240 'title' => esc_html__('Upcoming Renewal Reminder', 'wp-user-avatar'),
241 'subject' => sprintf(esc_html__('Your subscription is renewing soon.', 'wp-user-avatar'), $site_title),
242 'message' => $this->get_subscription_renewal_reminder_content(),
243 'description' => esc_html__('Email sent to customer to remind them that their subscription is approaching its renewal.', 'wp-user-avatar'),
244 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
245 'placeholders' => $this->get_subscription_placeholders(),
246 'reminder_days' => '1'
247 ],
248 [
249 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
250 'key' => 'subscription_expiration_reminder',
251 'title' => esc_html__('Upcoming Expiration Reminder', 'wp-user-avatar'),
252 'subject' => sprintf(esc_html__('Your subscription is expiring soon.', 'wp-user-avatar'), $site_title),
253 'message' => $this->get_subscription_renewal_reminder_content(true),
254 'description' => esc_html__('Email sent to customer to remind them that their subscription is approaching its expiration.', 'wp-user-avatar'),
255 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
256 'placeholders' => $this->get_subscription_placeholders(),
257 'reminder_days' => '1'
258 ],
259 [
260 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
261 'key' => 'subscription_after_expired_reminder',
262 'title' => esc_html__('After Subscription Expired Notification', 'wp-user-avatar'),
263 'subject' => sprintf(esc_html__('Your subscription has expired.', 'wp-user-avatar'), $site_title),
264 'message' => $this->get_subscription_expired_content(),
265 'description' => esc_html__('Email sent to customer few days after their subscription expires.', 'wp-user-avatar'),
266 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
267 'placeholders' => $this->get_subscription_placeholders(),
268 'reminder_days' => '2'
269 ],
270 ]);
271
272 if ( ! empty($type)) {
273 return wp_list_filter($notifications, ['type' => $type]);
274 }
275
276 return $notifications;
277 }
278
279 public function email_edit_screen_setup()
280 {
281 $key = sanitize_text_field($_GET['type']);
282 $data = wp_list_filter($this->email_notifications(), ['key' => $key]);
283
284 $data = array_shift($data);
285
286 if (empty($data)) {
287 ppress_do_admin_redirect(PPRESS_SETTINGS_SETTING_GENERAL_PAGE);
288 }
289
290 $page_header = $data['title'];
291
292 $email_content_field_type = 'email_editor';
293 $content_type = ppress_get_setting('email_content_type', 'text/html');
294
295 if ($content_type == 'text/html' && ppress_get_setting('email_template_type', 'default') == 'default') {
296 $email_content_field_type = 'wp_editor';
297 }
298
299 if ($content_type == 'text/plain') {
300 $email_content_field_type = 'textarea';
301 }
302
303 add_action('wp_cspa_media_button', function () use ($key) {
304 add_action('media_buttons', function () use ($key) {
305 $url = add_query_arg([
306 'pp_email_preview' => $key,
307 '_wpnonce' => ppress_create_nonce()
308 ],
309 admin_url()
310 );
311
312 printf(
313 '<a target="_blank" href="%s" class="button"><span class="wp-media-buttons-icon dashicons dashicons-visibility"></span> %s</a>',
314 $url,
315 esc_html__('Preview Email', 'wp-user-avatar')
316 );
317 });
318 });
319
320 add_action('wp_cspa_after_wp_editor_field', function () use ($data) {
321 if (isset($data['placeholders'])) {
322 $this->placeholder_tags_table($data['placeholders']);
323 }
324 });
325
326 add_action('wp_cspa_after_email_editor_field', function () use ($data) {
327 if (isset($data['placeholders'])) {
328 $this->placeholder_tags_table($data['placeholders']);
329 }
330 });
331
332 $email_settings = [
333 [
334 $key . '_email_enabled' => [
335 'type' => 'checkbox',
336 'label' => esc_html__('Enable Notification', 'wp-user-avatar'),
337 'checkbox_label' => esc_html__('Enable', 'wp-user-avatar'),
338 'value' => 'on',
339 'default_value' => 'on',
340 'description' => esc_html__('Check to enable this email notification.', 'wp-user-avatar')
341 ],
342 $key . '_email_subject' => [
343 'type' => 'text',
344 'value' => $data['subject'],
345 'label' => esc_html__('Subject Line', 'wp-user-avatar'),
346 'description' => esc_html__('Enter the subject or title of the email.', 'wp-user-avatar')
347 ],
348 $key . '_email_content' => [
349 'type' => $email_content_field_type,
350 'value' => $data['message'],
351 'label' => esc_html__('Message Body', 'wp-user-avatar'),
352 ],
353 ]
354 ];
355
356 if ($key == 'new_order_receipt') {
357 $email_settings[0][$key . '_disable_free_orders'] = [
358 'type' => 'checkbox',
359 'checkbox_label' => esc_html__('Check to Disable', 'wp-user-avatar'),
360 'label' => esc_html__('Disable for Free Orders', 'wp-user-avatar'),
361 'description' => esc_html__('Optionally disable sending email receipts for free orders.', 'wp-user-avatar')
362 ];
363 }
364
365 if ($key == 'subscription_renewal_reminder') {
366 $email_settings[0][$key . '_reminder_days'] = [
367 'type' => 'number',
368 'value' => $data['reminder_days'],
369 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
370 'description' => esc_html__('The number of days before the upcoming payment due date to notify the customer.', 'wp-user-avatar')
371 ];
372 }
373
374 if ($key == 'subscription_expiration_reminder') {
375 $email_settings[0][$key . '_reminder_days'] = [
376 'type' => 'number',
377 'value' => $data['reminder_days'],
378 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
379 'description' => esc_html__('The number of days before the subscription expiration due date to notify the customer.', 'wp-user-avatar')
380 ];
381 }
382
383 if ($key == 'subscription_after_expired_reminder') {
384 $email_settings[0][$key . '_reminder_days'] = [
385 'type' => 'number',
386 'value' => $data['reminder_days'],
387 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
388 'description' => esc_html__('The number of days after the subscription expired to notify the customer.', 'wp-user-avatar')
389 ];
390 }
391
392 return [
393 'page_header' => $page_header,
394 'email_settings' => $email_settings
395 ];
396 }
397
398 public function emails_admin_page()
399 {
400 if ( ! isset($_GET['type'])) {
401 add_filter('wp_cspa_main_content_area', function () {
402 ob_start();
403 $this->email_notification_list_table->prepare_items();
404 $this->email_notification_list_table->display();
405
406 return ob_get_clean();
407 });
408 }
409
410 $page_header = $this->get_admin_title();
411
412 $email_settings = [];
413
414 if (isset($_GET['type'])) {
415
416 $edit_screen_setup_args = $this->email_edit_screen_setup();
417
418 $page_header = $edit_screen_setup_args['page_header'];
419
420 $email_settings = $edit_screen_setup_args['email_settings'];
421 }
422
423 $this->settingsPageInstance->page_header($page_header);
424 $this->settingsPageInstance->main_content($email_settings);
425 $this->settingsPageInstance->remove_white_design();
426 $this->settingsPageInstance->header_without_frills();
427 $this->settingsPageInstance->build(true);
428
429 $this->toggle_field_js_script();
430 }
431
432 public function email_settings_admin_page()
433 {
434 $email_settings = [
435 [
436 'admin_email_addresses' => [
437 'label' => esc_html__('Admin Email Address(es)', 'wp-user-avatar'),
438 'description' => esc_html__('The Email address to receive admin notifications. Use comma to separate multiple email addresses.', 'wp-user-avatar'),
439 'type' => 'text',
440 'value' => ppress_admin_email()
441 ],
442 'email_sender_name' => [
443 'label' => esc_html__('Sender Name', 'wp-user-avatar'),
444 'description' => esc_html__('The name to use as the sender of all ProfilePress emails. Preferably your website name.', 'wp-user-avatar'),
445 'type' => 'text',
446 'value' => ppress_site_title()
447 ],
448 'email_sender_email' => [
449 'value' => ppress_admin_email(),
450 'label' => esc_html__('Sender Email Address', 'wp-user-avatar'),
451 'description' => esc_html__('The email address to use as the sender of all ProfilePress emails.', 'wp-user-avatar'),
452 'type' => 'text'
453 ],
454 'email_content_type' => [
455 'type' => 'select',
456 'options' => [
457 'text/html' => esc_html__('HTML', 'wp-user-avatar'),
458 'text/plain' => esc_html__('Plain Text', 'wp-user-avatar')
459 ],
460 'value' => 'text/html',
461 'label' => esc_html__('Content Type', 'wp-user-avatar'),
462 'description' => esc_html__('Choose whether to send ProfilePress emails in HTML or plain text. HTML is recommended.', 'wp-user-avatar')
463 ],
464 'email_template_type' => [
465 'type' => 'select',
466 'options' => [
467 'default' => esc_html__('Default Template', 'wp-user-avatar'),
468 'custom' => esc_html__('Custom Email Template', 'wp-user-avatar')
469 ],
470 'value' => 'default',
471 'label' => esc_html__('Email Template', 'wp-user-avatar'),
472 'description' => esc_html__('Choose "Custom Email Template" if you want to code your own email template from scratch.', 'wp-user-avatar')
473 ],
474 'customize_default_template' => [
475 'type' => 'custom_field_block',
476 'data' => sprintf(
477 '<a href="%s" target="_blank" class="button load-customize"><span style="margin-top: 3px;margin-right: 3px;" class="dashicons dashicons-edit"></span> <span>%s</span></a>',
478 add_query_arg(['ppress-preview-template' => 'true'], admin_url('customize.php')),
479 esc_html__('Customize Default Template', 'wp-user-avatar')
480 ),
481 ]
482 ],
483 ];
484
485 $this->settingsPageInstance->page_header($this->get_admin_title());
486 $this->settingsPageInstance->main_content($email_settings);
487 $this->settingsPageInstance->remove_white_design();
488 $this->settingsPageInstance->header_without_frills();
489 $this->settingsPageInstance->build(true);
490
491 $this->toggle_field_js_script();
492 }
493
494 public function handle_email_preview()
495 {
496 if ( ! isset($_GET['pp_email_preview']) || empty($_GET['pp_email_preview'])) return;
497
498 if ( ! current_user_can('manage_options')) return;
499
500 ppress_verify_nonce();
501
502 $key = sanitize_text_field($_GET['pp_email_preview']);
503
504 $data = wp_list_filter($this->email_notifications(), ['key' => $key]);
505
506 $data = array_shift($data);
507
508 $subject = ppress_get_setting($key . '_email_subject', $data['subject'], true);
509 $content = ppress_get_setting($key . '_email_content', $data['message'], true);
510 echo (new SendEmail('', $subject, $content))->templatified_email();
511 exit;
512 }
513
514 protected function placeholder_tags_table($placeholders)
515 {
516 ?>
517 <div class="ppress-placeholder-tags">
518 <table class="widefat striped">
519 <tbody>
520 <tr>
521 <th colspan="2"><?= esc_html__('Available placeholders for subject and message body', 'wp-user-avatar'); ?></th>
522 </tr>
523 <?php foreach ($placeholders as $tag => $description) : ?>
524 <tr>
525 <td><?= $tag ?></td>
526 <td><?= $description ?></td>
527 </tr>
528 <?php endforeach; ?>
529 </tbody>
530 </table>
531 </div>
532 <?php
533 }
534
535 public function toggle_field_js_script()
536 {
537 ?>
538 <script type="text/javascript">
539 (function ($) {
540
541 $('#email_template_type').on('change', function () {
542 var cache = $('#customize_default_template_row');
543 cache.hide();
544 if (this.value === 'default') {
545 cache.show();
546 }
547 }).trigger('change');
548
549 $('#email_content_type').on('change', function () {
550 var cache = $('#email_template_type_row, #customize_default_template_row');
551 cache.hide();
552 if (this.value === 'text/html') {
553 cache.show();
554 $('#email_template_type').trigger('change');
555 }
556
557 }).trigger('change');
558 })(jQuery);
559 </script>
560 <?php
561 }
562
563 public static function get_instance()
564 {
565 static $instance = null;
566
567 if (is_null($instance)) {
568 $instance = new self();
569 }
570
571 return $instance;
572 }
573 }