PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.0.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.0.3
4.17.3 4.17.2 4.17.1 4.17.0 4.16.19 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 4 years ago EmailSettingsPage.php 4 years ago WPListTable.php 4 years ago email-template-preview.php 5 years ago
EmailSettingsPage.php
560 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 '{{email}}' => esc_html__('Email address of the registered user.', 'wp-user-avatar'),
129 '{{password}}' => esc_html__('Password of the registered user.', 'wp-user-avatar'),
130 '{{site_title}}' => esc_html__('Website title or name.', 'wp-user-avatar'),
131 '{{first_name}}' => esc_html__('First Name entered by user on registration.', 'wp-user-avatar'),
132 '{{last_name}}' => esc_html__('Last Name entered by user on registration.', 'wp-user-avatar'),
133 '{{password_reset_link}}' => esc_html__('URL to reset password.', 'wp-user-avatar'),
134 '{{login_link}}' => esc_html__('URL to login.', 'wp-user-avatar'),
135 ],
136 ],
137 [
138 'type' => self::ACCOUNT_EMAIL_TYPE,
139 'key' => 'password_reset',
140 'title' => esc_html__('Password Reset Email', 'wp-user-avatar'),
141 'subject' => sprintf(esc_html__('[%s] Password Reset', 'wp-user-avatar'), $site_title),
142 'message' => ppress_password_reset_content_default(),
143 'description' => esc_html__('Email that is sent to the user upon password reset request.', 'wp-user-avatar'),
144 'recipient' => esc_html__('Users', 'wp-user-avatar'),
145 'placeholders' => [
146 '{{username}}' => esc_html__('Username of user.', 'wp-user-avatar'),
147 '{{email}}' => esc_html__('Email address of the registered user.', 'wp-user-avatar'),
148 '{{site_title}}' => esc_html__('Website title or name.', 'wp-user-avatar'),
149 '{{password_reset_link}}' => esc_html__('URL to reset password.', 'wp-user-avatar'),
150 ]
151 ],
152 [
153 'type' => self::ACCOUNT_EMAIL_TYPE,
154 'key' => 'new_user_admin_email',
155 'title' => esc_html__('New User Admin Notification', 'wp-user-avatar'),
156 'subject' => sprintf(esc_html__('[%s] New User Registration', 'wp-user-avatar'), $site_title),
157 'message' => ppress_new_user_admin_notification_message_default(),
158 'description' => esc_html__('Email that is sent to the admin when there is a new user registration.', 'wp-user-avatar'),
159 'recipient' => ppress_get_admin_notification_emails(),
160 'placeholders' => [
161 '{{username}}' => esc_html__('Username of the newly registered user.', 'wp-user-avatar'),
162 '{{email}}' => esc_html__('Email address of the newly registered user.', 'wp-user-avatar'),
163 '{{first_name}}' => esc_html__('First name of the newly registered user.', 'wp-user-avatar'),
164 '{{last_name}}' => esc_html__('Last name of the newly registered user.', 'wp-user-avatar'),
165 '{{site_title}}' => esc_html__('Website title or name.', 'wp-user-avatar'),
166 '{{field_key}}' => sprintf(
167 esc_html__('Replace "field_key" with the %scustom field key%s or usermeta key.', 'wp-user-avatar'),
168 '<a href="' . PPRESS_CUSTOM_FIELDS_SETTINGS_PAGE . '" target="_blank">', '</a>'
169 )
170 ]
171 ],
172 [
173 'type' => self::ORDER_EMAIL_TYPE,
174 'key' => 'new_order_receipt',
175 'title' => esc_html__('New Order Receipt', 'wp-user-avatar'),
176 'subject' => sprintf(esc_html__('New Order Receipt', 'wp-user-avatar'), $site_title),
177 'message' => $this->get_order_receipt_content(),
178 'description' => esc_html__('Email sent whenever a customer completes an order.', 'wp-user-avatar'),
179 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
180 'placeholders' => $this->get_order_placeholders()
181 ],
182 [
183 'type' => self::ORDER_EMAIL_TYPE,
184 'key' => 'renewal_order_receipt',
185 'title' => esc_html__('Renewal Order Receipt', 'wp-user-avatar'),
186 'subject' => sprintf(esc_html__('Subscription Renewal Receipt', 'wp-user-avatar'), $site_title),
187 'message' => $this->get_order_receipt_content(true),
188 'description' => esc_html__('Email sent to customer whenever a renewal order occurs.', 'wp-user-avatar'),
189 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
190 'placeholders' => $this->get_order_placeholders()
191 ],
192 [
193 'type' => self::ORDER_EMAIL_TYPE,
194 'key' => 'new_order_admin_notification',
195 'title' => esc_html__('New Order Admin Notification', 'wp-user-avatar'),
196 'subject' => sprintf(esc_html__('New Order #{{order_id}}', 'wp-user-avatar'), $site_title),
197 'message' => $this->get_new_order_admin_notification_content(),
198 'description' => esc_html__('Email sent to the admin when there is a new order.', 'wp-user-avatar'),
199 'recipient' => ppress_get_admin_notification_emails(),
200 'placeholders' => $this->get_order_placeholders()
201 ],
202 [
203 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
204 'key' => 'subscription_cancelled_notification',
205 'title' => esc_html__('Subscription Cancelled Notification', 'wp-user-avatar'),
206 'subject' => sprintf(esc_html__('Your subscription has been cancelled.', 'wp-user-avatar'), $site_title),
207 'message' => $this->get_subscription_cancelled_content(),
208 'description' => esc_html__('Email sent to customer whenever their subscription is cancelled.', 'wp-user-avatar'),
209 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
210 'placeholders' => $this->get_subscription_placeholders()
211 ],
212 [
213 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
214 'key' => 'subscription_expired_notification',
215 'title' => esc_html__('Subscription Expired Notification', 'wp-user-avatar'),
216 'subject' => sprintf(esc_html__('Your subscription has expired.', 'wp-user-avatar'), $site_title),
217 'message' => $this->get_subscription_expired_content(),
218 'description' => esc_html__('Email sent to customer whenever their subscription expires.', 'wp-user-avatar'),
219 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
220 'placeholders' => $this->get_subscription_placeholders()
221 ],
222 [
223 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
224 'key' => 'subscription_completed_notification',
225 'title' => esc_html__('Subscription Completed Notification', 'wp-user-avatar'),
226 'subject' => sprintf(esc_html__('Your subscription is now complete.', 'wp-user-avatar'), $site_title),
227 'message' => $this->get_subscription_completed_content(),
228 'description' => esc_html__('Email sent to customer whenever they complete their subscription payments.', 'wp-user-avatar'),
229 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
230 'placeholders' => $this->get_subscription_placeholders()
231 ],
232 [
233 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
234 'key' => 'subscription_renewal_reminder',
235 'title' => esc_html__('Upcoming Renewal Reminder', 'wp-user-avatar'),
236 'subject' => sprintf(esc_html__('Your subscription is renewing soon.', 'wp-user-avatar'), $site_title),
237 'message' => $this->get_subscription_renewal_reminder_content(),
238 'description' => esc_html__('Email sent to customer to remind them that their subscription is approaching its renewal.', 'wp-user-avatar'),
239 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
240 'placeholders' => $this->get_subscription_placeholders(),
241 'reminder_days' => '1'
242 ],
243 [
244 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
245 'key' => 'subscription_expiration_reminder',
246 'title' => esc_html__('Upcoming Expiration Reminder', 'wp-user-avatar'),
247 'subject' => sprintf(esc_html__('Your subscription is expiring soon.', 'wp-user-avatar'), $site_title),
248 'message' => $this->get_subscription_renewal_reminder_content(true),
249 'description' => esc_html__('Email sent to customer to remind them that their subscription is approaching its expiration.', 'wp-user-avatar'),
250 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
251 'placeholders' => $this->get_subscription_placeholders(),
252 'reminder_days' => '1'
253 ],
254 [
255 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
256 'key' => 'subscription_after_expired_reminder',
257 'title' => esc_html__('After Subscription Expired Notification', 'wp-user-avatar'),
258 'subject' => sprintf(esc_html__('Your subscription has expired.', 'wp-user-avatar'), $site_title),
259 'message' => $this->get_subscription_expired_content(),
260 'description' => esc_html__('Email sent to customer few days after their subscription expires.', 'wp-user-avatar'),
261 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
262 'placeholders' => $this->get_subscription_placeholders(),
263 'reminder_days' => '2'
264 ],
265 ]);
266
267 if ( ! empty($type)) {
268 return wp_list_filter($notifications, ['type' => $type]);
269 }
270
271 return $notifications;
272 }
273
274 public function email_edit_screen_setup()
275 {
276 $key = sanitize_text_field($_GET['type']);
277 $data = wp_list_filter($this->email_notifications(), ['key' => $key]);
278
279 $data = array_shift($data);
280
281 if (empty($data)) {
282 wp_safe_redirect(PPRESS_SETTINGS_SETTING_PAGE);
283 exit;
284 }
285
286 $page_header = $data['title'];
287
288 $email_content_field_type = 'email_editor';
289 $content_type = ppress_get_setting('email_content_type', 'text/html');
290
291 if ($content_type == 'text/html' && ppress_get_setting('email_template_type', 'default') == 'default') {
292 $email_content_field_type = 'wp_editor';
293 }
294
295 if ($content_type == 'text/plain') {
296 $email_content_field_type = 'textarea';
297 }
298
299 add_action('wp_cspa_media_button', function () use ($key) {
300 add_action('media_buttons', function () use ($key) {
301 $url = add_query_arg([
302 'pp_email_preview' => $key,
303 '_wpnonce' => ppress_create_nonce()
304 ],
305 admin_url()
306 );
307
308 printf(
309 '<a target="_blank" href="%s" class="button"><span class="wp-media-buttons-icon dashicons dashicons-visibility"></span> %s</a>',
310 $url,
311 esc_html__('Preview Email', 'wp-user-avatar')
312 );
313 });
314 });
315
316 add_action('wp_cspa_after_wp_editor_field', function () use ($data) {
317 if (isset($data['placeholders'])) {
318 $this->placeholder_tags_table($data['placeholders']);
319 }
320 });
321
322 add_action('wp_cspa_after_email_editor_field', function () use ($data) {
323 if (isset($data['placeholders'])) {
324 $this->placeholder_tags_table($data['placeholders']);
325 }
326 });
327
328 $email_settings = [
329 [
330 $key . '_email_enabled' => [
331 'type' => 'checkbox',
332 'label' => esc_html__('Enable Notification', 'wp-user-avatar'),
333 'checkbox_label' => esc_html__('Enable', 'wp-user-avatar'),
334 'value' => 'on',
335 'default_value' => 'on',
336 'description' => esc_html__('Check to enable this email notification.', 'wp-user-avatar')
337 ],
338 $key . '_email_subject' => [
339 'type' => 'text',
340 'value' => $data['subject'],
341 'label' => esc_html__('Subject Line', 'wp-user-avatar'),
342 'description' => esc_html__('Enter the subject or title for the welcome message email.', 'wp-user-avatar')
343 ],
344 $key . '_email_content' => [
345 'type' => $email_content_field_type,
346 'value' => $data['message'],
347 'label' => esc_html__('Message Body', 'wp-user-avatar'),
348 ],
349 ]
350 ];
351
352 if ($key == 'subscription_renewal_reminder') {
353 $email_settings[0][$key . '_reminder_days'] = [
354 'type' => 'number',
355 'value' => $data['reminder_days'],
356 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
357 'description' => esc_html__('The number of days before the upcoming payment due date to notify the customer.', 'wp-user-avatar')
358 ];
359 }
360
361 if ($key == 'subscription_expiration_reminder') {
362 $email_settings[0][$key . '_reminder_days'] = [
363 'type' => 'number',
364 'value' => $data['reminder_days'],
365 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
366 'description' => esc_html__('The number of days before the subscription expiration due date to notify the customer.', 'wp-user-avatar')
367 ];
368 }
369
370 if ($key == 'subscription_after_expired_reminder') {
371 $email_settings[0][$key . '_reminder_days'] = [
372 'type' => 'number',
373 'value' => $data['reminder_days'],
374 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
375 'description' => esc_html__('The number of days after the subscription expired to notify the customer.', 'wp-user-avatar')
376 ];
377 }
378
379 return [
380 'page_header' => $page_header,
381 'email_settings' => $email_settings
382 ];
383 }
384
385 public function emails_admin_page()
386 {
387 if ( ! isset($_GET['type'])) {
388 add_filter('wp_cspa_main_content_area', function () {
389 ob_start();
390 $this->email_notification_list_table->prepare_items();
391 $this->email_notification_list_table->display();
392
393 return ob_get_clean();
394 });
395 }
396
397 $page_header = $this->get_admin_title();
398
399 $email_settings = [];
400
401 if (isset($_GET['type'])) {
402
403 $edit_screen_setup_args = $this->email_edit_screen_setup();
404
405 $page_header = $edit_screen_setup_args['page_header'];
406
407 $email_settings = $edit_screen_setup_args['email_settings'];
408 }
409
410 $this->settingsPageInstance->page_header($page_header);
411 $this->settingsPageInstance->main_content($email_settings);
412 $this->settingsPageInstance->remove_white_design();
413 $this->settingsPageInstance->header_without_frills();
414 $this->settingsPageInstance->build(true);
415
416 $this->toggle_field_js_script();
417 }
418
419 public function email_settings_admin_page()
420 {
421 $email_settings = [
422 [
423 'admin_email_addresses' => [
424 'label' => esc_html__('Admin Email Address(es)', 'wp-user-avatar'),
425 'description' => esc_html__('The Email address to receive admin notifications. Use comma to separate multiple email addresses.', 'wp-user-avatar'),
426 'type' => 'text',
427 'value' => ppress_admin_email()
428 ],
429 'email_sender_name' => [
430 'label' => esc_html__('Sender Name', 'wp-user-avatar'),
431 'description' => esc_html__('The name to use as the sender of all ProfilePress emails. Preferably your website name.', 'wp-user-avatar'),
432 'type' => 'text',
433 'value' => ppress_site_title()
434 ],
435 'email_sender_email' => [
436 'value' => ppress_admin_email(),
437 'label' => esc_html__('Sender Email Address', 'wp-user-avatar'),
438 'description' => esc_html__('The email address to use as the sender of all ProfilePress emails.', 'wp-user-avatar'),
439 'type' => 'text'
440 ],
441 'email_content_type' => [
442 'type' => 'select',
443 'options' => [
444 'text/html' => esc_html__('HTML', 'wp-user-avatar'),
445 'text/plain' => esc_html__('Plain Text', 'wp-user-avatar')
446 ],
447 'value' => 'text/html',
448 'label' => esc_html__('Content Type', 'wp-user-avatar'),
449 'description' => esc_html__('Choose whether to send ProfilePress emails in HTML or plain text. HTML is recommended.', 'wp-user-avatar')
450 ],
451 'email_template_type' => [
452 'type' => 'select',
453 'options' => [
454 'default' => esc_html__('Default Template', 'wp-user-avatar'),
455 'custom' => esc_html__('Custom Email Template', 'wp-user-avatar')
456 ],
457 'value' => 'default',
458 'label' => esc_html__('Email Template', 'wp-user-avatar'),
459 'description' => esc_html__('Choose "Custom Email Template" if you want to code your own email template from scratch.', 'wp-user-avatar')
460 ],
461 'customize_default_template' => [
462 'type' => 'custom_field_block',
463 'data' => sprintf(
464 '<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>',
465 add_query_arg(['ppress-preview-template' => 'true'], admin_url('customize.php')),
466 esc_html__('Customize Default Template', 'wp-user-avatar')
467 ),
468 ]
469 ],
470 ];
471
472 $this->settingsPageInstance->page_header($this->get_admin_title());
473 $this->settingsPageInstance->main_content($email_settings);
474 $this->settingsPageInstance->remove_white_design();
475 $this->settingsPageInstance->header_without_frills();
476 $this->settingsPageInstance->build(true);
477
478 $this->toggle_field_js_script();
479 }
480
481 public function handle_email_preview()
482 {
483 if ( ! isset($_GET['pp_email_preview']) || empty($_GET['pp_email_preview'])) return;
484
485 if ( ! current_user_can('manage_options')) return;
486
487 ppress_verify_nonce();
488
489 $key = sanitize_text_field($_GET['pp_email_preview']);
490
491 $data = wp_list_filter($this->email_notifications(), ['key' => $key]);
492
493 $data = array_shift($data);
494
495 $subject = ppress_get_setting($key . '_email_subject', $data['subject'], true);
496 $content = ppress_get_setting($key . '_email_content', $data['message'], true);
497 echo (new SendEmail('', $subject, $content))->templatified_email();
498 exit;
499 }
500
501 protected function placeholder_tags_table($placeholders)
502 {
503 ?>
504 <div class="ppress-placeholder-tags">
505 <table class="widefat striped">
506 <tbody>
507 <tr>
508 <th colspan="2"><?= esc_html__('Available placeholders for subject and message body', 'wp-user-avatar'); ?></th>
509 </tr>
510 <?php foreach ($placeholders as $tag => $description) : ?>
511 <tr>
512 <td><?= $tag ?></td>
513 <td><?= $description ?></td>
514 </tr>
515 <?php endforeach; ?>
516 </tbody>
517 </table>
518 </div>
519 <?php
520 }
521
522 public function toggle_field_js_script()
523 {
524 ?>
525 <script type="text/javascript">
526 (function ($) {
527
528 $('#email_template_type').change(function () {
529 var cache = $('#customize_default_template_row');
530 cache.hide();
531 if (this.value === 'default') {
532 cache.show();
533 }
534 }).change();
535
536 $('#email_content_type').change(function () {
537 var cache = $('#email_template_type_row, #customize_default_template_row');
538 cache.hide();
539 if (this.value === 'text/html') {
540 cache.show();
541 $('#email_template_type').change();
542 }
543
544 }).change();
545 })(jQuery);
546 </script>
547 <?php
548 }
549
550 public static function get_instance()
551 {
552 static $instance = null;
553
554 if (is_null($instance)) {
555 $instance = new self();
556 }
557
558 return $instance;
559 }
560 }