PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.17.0
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.17.0
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 6 days ago WPListTable.php 4 years ago email-template-preview.php 5 years ago
EmailSettingsPage.php
583 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 customers 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 customers 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 customers 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_payment_failed_notification',
230 'title' => esc_html__('Subscription Payment Failed Notification', 'wp-user-avatar'),
231 'subject' => sprintf(esc_html__('Your subscription payment failed.', 'wp-user-avatar'), $site_title),
232 'message' => $this->get_subscription_payment_failed_content(),
233 'description' => esc_html__('Email sent to customers whenever a recurring payment that should renew their subscription fails or goes unpaid.', '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_completed_notification',
240 'title' => esc_html__('Subscription Completed Notification', 'wp-user-avatar'),
241 'subject' => sprintf(esc_html__('Your subscription is now complete.', 'wp-user-avatar'), $site_title),
242 'message' => $this->get_subscription_completed_content(),
243 'description' => esc_html__('Email sent to customers whenever they complete their subscription payments.', 'wp-user-avatar'),
244 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
245 'placeholders' => $this->get_subscription_placeholders()
246 ],
247 [
248 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
249 'key' => 'subscription_renewal_reminder',
250 'title' => esc_html__('Upcoming Renewal Reminder', 'wp-user-avatar'),
251 'subject' => sprintf(esc_html__('Your subscription is renewing soon.', 'wp-user-avatar'), $site_title),
252 'message' => $this->get_subscription_renewal_reminder_content(),
253 'description' => esc_html__('Email sent to customers to remind them that their subscription is approaching its renewal.', 'wp-user-avatar'),
254 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
255 'placeholders' => $this->get_subscription_placeholders(),
256 'reminder_days' => '1'
257 ],
258 [
259 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
260 'key' => 'subscription_expiration_reminder',
261 'title' => esc_html__('Upcoming Expiration Reminder', 'wp-user-avatar'),
262 'subject' => sprintf(esc_html__('Your subscription is expiring soon.', 'wp-user-avatar'), $site_title),
263 'message' => $this->get_subscription_renewal_reminder_content(true),
264 'description' => esc_html__('Email sent to customers to remind them that their subscription is approaching its expiration.', 'wp-user-avatar'),
265 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
266 'placeholders' => $this->get_subscription_placeholders(),
267 'reminder_days' => '1'
268 ],
269 [
270 'type' => self::SUBSCRIPTION_EMAIL_TYPE,
271 'key' => 'subscription_after_expired_reminder',
272 'title' => esc_html__('After Subscription Expired Notification', 'wp-user-avatar'),
273 'subject' => sprintf(esc_html__('Your subscription has expired.', 'wp-user-avatar'), $site_title),
274 'message' => $this->get_subscription_expired_content(),
275 'description' => esc_html__('Email sent to customers few days after their subscription expires.', 'wp-user-avatar'),
276 'recipient' => esc_html__('Customers', 'wp-user-avatar'),
277 'placeholders' => $this->get_subscription_placeholders(),
278 'reminder_days' => '2'
279 ],
280 ]);
281
282 if ( ! empty($type)) {
283 return wp_list_filter($notifications, ['type' => $type]);
284 }
285
286 return $notifications;
287 }
288
289 public function email_edit_screen_setup()
290 {
291 $key = sanitize_text_field($_GET['type']);
292 $data = wp_list_filter($this->email_notifications(), ['key' => $key]);
293
294 $data = array_shift($data);
295
296 if (empty($data)) {
297 ppress_do_admin_redirect(PPRESS_SETTINGS_SETTING_GENERAL_PAGE);
298 }
299
300 $page_header = $data['title'];
301
302 $email_content_field_type = 'email_editor';
303 $content_type = ppress_get_setting('email_content_type', 'text/html');
304
305 if ($content_type == 'text/html' && ppress_get_setting('email_template_type', 'default') == 'default') {
306 $email_content_field_type = 'wp_editor';
307 }
308
309 if ($content_type == 'text/plain') {
310 $email_content_field_type = 'textarea';
311 }
312
313 add_action('wp_cspa_media_button', function () use ($key) {
314 add_action('media_buttons', function () use ($key) {
315 $url = add_query_arg([
316 'pp_email_preview' => $key,
317 '_wpnonce' => ppress_create_nonce()
318 ],
319 admin_url()
320 );
321
322 printf(
323 '<a target="_blank" href="%s" class="button"><span class="wp-media-buttons-icon dashicons dashicons-visibility"></span> %s</a>',
324 $url,
325 esc_html__('Preview Email', 'wp-user-avatar')
326 );
327 });
328 });
329
330 add_action('wp_cspa_after_wp_editor_field', function () use ($data) {
331 if (isset($data['placeholders'])) {
332 $this->placeholder_tags_table($data['placeholders']);
333 }
334 });
335
336 add_action('wp_cspa_after_email_editor_field', function () use ($data) {
337 if (isset($data['placeholders'])) {
338 $this->placeholder_tags_table($data['placeholders']);
339 }
340 });
341
342 $email_settings = [
343 [
344 $key . '_email_enabled' => [
345 'type' => 'checkbox',
346 'label' => esc_html__('Enable Notification', 'wp-user-avatar'),
347 'checkbox_label' => esc_html__('Enable', 'wp-user-avatar'),
348 'value' => 'on',
349 'default_value' => 'on',
350 'description' => esc_html__('Check to enable this email notification.', 'wp-user-avatar')
351 ],
352 $key . '_email_subject' => [
353 'type' => 'text',
354 'value' => $data['subject'],
355 'label' => esc_html__('Subject Line', 'wp-user-avatar'),
356 'description' => esc_html__('Enter the subject or title of the email.', 'wp-user-avatar')
357 ],
358 $key . '_email_content' => [
359 'type' => $email_content_field_type,
360 'value' => $data['message'],
361 'label' => esc_html__('Message Body', 'wp-user-avatar'),
362 ],
363 ]
364 ];
365
366 if ($key == 'new_order_receipt') {
367 $email_settings[0][$key . '_disable_free_orders'] = [
368 'type' => 'checkbox',
369 'checkbox_label' => esc_html__('Check to Disable', 'wp-user-avatar'),
370 'label' => esc_html__('Disable for Free Orders', 'wp-user-avatar'),
371 'description' => esc_html__('Optionally disable sending email receipts for free orders.', 'wp-user-avatar')
372 ];
373 }
374
375 if ($key == 'subscription_renewal_reminder') {
376 $email_settings[0][$key . '_reminder_days'] = [
377 'type' => 'number',
378 'value' => $data['reminder_days'],
379 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
380 'description' => esc_html__('The number of days before the upcoming payment due date to notify the customer.', 'wp-user-avatar')
381 ];
382 }
383
384 if ($key == 'subscription_expiration_reminder') {
385 $email_settings[0][$key . '_reminder_days'] = [
386 'type' => 'number',
387 'value' => $data['reminder_days'],
388 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
389 'description' => esc_html__('The number of days before the subscription expiration due date to notify the customer.', 'wp-user-avatar')
390 ];
391 }
392
393 if ($key == 'subscription_after_expired_reminder') {
394 $email_settings[0][$key . '_reminder_days'] = [
395 'type' => 'number',
396 'value' => $data['reminder_days'],
397 'label' => esc_html__('Reminder Days', 'wp-user-avatar'),
398 'description' => esc_html__('The number of days after the subscription expired to notify the customer.', 'wp-user-avatar')
399 ];
400 }
401
402 return [
403 'page_header' => $page_header,
404 'email_settings' => $email_settings
405 ];
406 }
407
408 public function emails_admin_page()
409 {
410 if ( ! isset($_GET['type'])) {
411 add_filter('wp_cspa_main_content_area', function () {
412 ob_start();
413 $this->email_notification_list_table->prepare_items();
414 $this->email_notification_list_table->display();
415
416 return ob_get_clean();
417 });
418 }
419
420 $page_header = $this->get_admin_title();
421
422 $email_settings = [];
423
424 if (isset($_GET['type'])) {
425
426 $edit_screen_setup_args = $this->email_edit_screen_setup();
427
428 $page_header = $edit_screen_setup_args['page_header'];
429
430 $email_settings = $edit_screen_setup_args['email_settings'];
431 }
432
433 $this->settingsPageInstance->page_header($page_header);
434 $this->settingsPageInstance->main_content($email_settings);
435 $this->settingsPageInstance->remove_white_design();
436 $this->settingsPageInstance->header_without_frills();
437 $this->settingsPageInstance->build(true);
438
439 $this->toggle_field_js_script();
440 }
441
442 public function email_settings_admin_page()
443 {
444 $email_settings = [
445 [
446 'admin_email_addresses' => [
447 'label' => esc_html__('Admin Email Address(es)', 'wp-user-avatar'),
448 'description' => esc_html__('The Email address to receive admin notifications. Use comma to separate multiple email addresses.', 'wp-user-avatar'),
449 'type' => 'text',
450 'value' => ppress_admin_email()
451 ],
452 'email_sender_name' => [
453 'label' => esc_html__('Sender Name', 'wp-user-avatar'),
454 'description' => esc_html__('The name to use as the sender of all ProfilePress emails. Preferably your website name.', 'wp-user-avatar'),
455 'type' => 'text',
456 'value' => ppress_site_title()
457 ],
458 'email_sender_email' => [
459 'value' => ppress_admin_email(),
460 'label' => esc_html__('Sender Email Address', 'wp-user-avatar'),
461 'description' => esc_html__('The email address to use as the sender of all ProfilePress emails.', 'wp-user-avatar'),
462 'type' => 'text'
463 ],
464 'email_content_type' => [
465 'type' => 'select',
466 'options' => [
467 'text/html' => esc_html__('HTML', 'wp-user-avatar'),
468 'text/plain' => esc_html__('Plain Text', 'wp-user-avatar')
469 ],
470 'value' => 'text/html',
471 'label' => esc_html__('Content Type', 'wp-user-avatar'),
472 'description' => esc_html__('Choose whether to send ProfilePress emails in HTML or plain text. HTML is recommended.', 'wp-user-avatar')
473 ],
474 'email_template_type' => [
475 'type' => 'select',
476 'options' => [
477 'default' => esc_html__('Default Template', 'wp-user-avatar'),
478 'custom' => esc_html__('Custom Email Template', 'wp-user-avatar')
479 ],
480 'value' => 'default',
481 'label' => esc_html__('Email Template', 'wp-user-avatar'),
482 'description' => esc_html__('Choose "Custom Email Template" if you want to code your own email template from scratch.', 'wp-user-avatar')
483 ],
484 'customize_default_template' => [
485 'type' => 'custom_field_block',
486 'data' => sprintf(
487 '<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>',
488 add_query_arg(['ppress-preview-template' => 'true'], admin_url('customize.php')),
489 esc_html__('Customize Default Template', 'wp-user-avatar')
490 ),
491 ]
492 ],
493 ];
494
495 $this->settingsPageInstance->page_header($this->get_admin_title());
496 $this->settingsPageInstance->main_content($email_settings);
497 $this->settingsPageInstance->remove_white_design();
498 $this->settingsPageInstance->header_without_frills();
499 $this->settingsPageInstance->build(true);
500
501 $this->toggle_field_js_script();
502 }
503
504 public function handle_email_preview()
505 {
506 if ( ! isset($_GET['pp_email_preview']) || empty($_GET['pp_email_preview'])) return;
507
508 if ( ! current_user_can('manage_options')) return;
509
510 ppress_verify_nonce();
511
512 $key = sanitize_text_field($_GET['pp_email_preview']);
513
514 $data = wp_list_filter($this->email_notifications(), ['key' => $key]);
515
516 $data = array_shift($data);
517
518 $subject = ppress_get_setting($key . '_email_subject', $data['subject'], true);
519 $content = ppress_get_setting($key . '_email_content', $data['message'], true);
520 echo (new SendEmail('', $subject, $content))->templatified_email();
521 exit;
522 }
523
524 protected function placeholder_tags_table($placeholders)
525 {
526 ?>
527 <div class="ppress-placeholder-tags">
528 <table class="widefat striped">
529 <tbody>
530 <tr>
531 <th colspan="2"><?= esc_html__('Available placeholders for subject and message body', 'wp-user-avatar'); ?></th>
532 </tr>
533 <?php foreach ($placeholders as $tag => $description) : ?>
534 <tr>
535 <td><?= $tag ?></td>
536 <td><?= $description ?></td>
537 </tr>
538 <?php endforeach; ?>
539 </tbody>
540 </table>
541 </div>
542 <?php
543 }
544
545 public function toggle_field_js_script()
546 {
547 ?>
548 <script type="text/javascript">
549 (function ($) {
550
551 $('#email_template_type').on('change', function () {
552 var cache = $('#customize_default_template_row');
553 cache.hide();
554 if (this.value === 'default') {
555 cache.show();
556 }
557 }).trigger('change');
558
559 $('#email_content_type').on('change', function () {
560 var cache = $('#email_template_type_row, #customize_default_template_row');
561 cache.hide();
562 if (this.value === 'text/html') {
563 cache.show();
564 $('#email_template_type').trigger('change');
565 }
566
567 }).trigger('change');
568 })(jQuery);
569 </script>
570 <?php
571 }
572
573 public static function get_instance()
574 {
575 static $instance = null;
576
577 if (is_null($instance)) {
578 $instance = new self();
579 }
580
581 return $instance;
582 }
583 }