PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-notification-settings.php +767 -606 5.0.2 → 6.2.2 View file →
@@ -6,685 +6,846 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Notification_Settings
12 17 *
13 18 * @package MainWP\Dashboard
14 19 */
15 -class MainWP_Notification_Settings {
20 +class MainWP_Notification_Settings { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16 21
17 - /**
18 - * Private static variable to hold the single instance of the class.
19 - *
20 - * @static
21 - *
22 - * @var mixed Default null.
23 - */
24 - private static $instance = null;
25 22
23 + /**
24 + * Private static variable to hold the single instance of the class.
25 + *
26 + * @static
27 + *
28 + * @var mixed Default null.
29 + */
30 + private static $instance = null;
26 31
27 - /**
28 - * Get class name.
29 - *
30 - * @return string Class name.
31 - */
32 - public static function get_class_name() {
33 - return __CLASS__;
34 - }
32 + /**
33 + * Private static variable to hold the single instance.
34 + *
35 + * @static
36 + *
37 + * @var mixed Default null.
38 + */
39 + private static $boilerplate_tokens_loaded = null;
35 40
36 - /**
37 - * Create a new self instance.
38 - *
39 - * @return mixed self::$instance
40 - */
41 - public static function instance() {
42 - if ( null === self::$instance ) {
43 - self::$instance = new self();
44 - }
45 - return self::$instance;
46 - }
47 41
48 - /**
49 - * MainWP_Notification_Settings constructor.
50 - *
51 - * Run each time the class is called.
52 - */
53 - public function __construct() {
54 - }
42 + /**
43 + * Private static variable to hold the single instance.
44 + *
45 + * @static
46 + *
47 + * @var mixed Default null.
48 + */
49 + private static $report_tokens_loaded = null;
55 50
56 - /**
57 - * Manage general email settings.
58 - *
59 - * @return bool True if saved successfully, false if not.
60 - *
61 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
62 - */
63 - public static function emails_general_settings_handle() {
64 - if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsEmail' ) ) {
65 - $emails_settings = get_option( 'mainwp_settings_notification_emails' );
66 - if ( ! is_array( $emails_settings ) ) {
67 - $emails_settings = array();
68 - }
51 + /**
52 + * Private static variable to hold the single instance.
53 + *
54 + * @static
55 + *
56 + * @var mixed Default null.
57 + */
58 + private static $client_report_tokens_loaded = null;
69 59
70 - $type = isset( $_POST['mainwp_setting_emails_type'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_setting_emails_type'] ) ) : '';
71 - $update_settings = isset( $_POST['mainwp_settingEmails'][ $type ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_settingEmails'][ $type ] ) ) : '';
72 - $update_settings['disable'] = ( isset( $_POST['mainwp_settingEmails'][ $type ] ) && isset( $_POST['mainwp_settingEmails'][ $type ]['disable'] ) ) ? 0 : 1; // to set 'disable' values.
73 - $emails_settings[ $type ] = $update_settings;
74 60
75 - /**
76 - * Action: mainwp_before_save_email_settings
77 - *
78 - * Fires before save email settings.
79 - *
80 - * @since 4.1
81 - */
82 - do_action( 'mainwp_before_save_email_settings', $type, $update_settings );
61 + /**
62 + * Get class name.
63 + *
64 + * @return string Class name.
65 + */
66 + public static function get_class_name() {
67 + return __CLASS__;
68 + }
83 69
84 - MainWP_Utility::update_option( 'mainwp_settings_notification_emails', $emails_settings );
70 + /**
71 + * Create a new self instance.
72 + *
73 + * @return mixed static::$instance
74 + */
75 + public static function instance() {
76 + if ( null === static::$instance ) {
77 + static::$instance = new self();
78 + }
79 + return static::$instance;
80 + }
85 81
86 - /**
87 - * Action: mainwp_after_save_email_settings
88 - *
89 - * Fires after save email settings.
90 - *
91 - * @since 4.1
92 - */
93 - do_action( 'mainwp_after_save_email_settings', $emails_settings );
82 + /**
83 + * MainWP_Notification_Settings constructor.
84 + *
85 + * Run each time the class is called.
86 + */
87 + public function __construct() {
88 + }
94 89
95 - return true;
96 - }
97 - return false;
98 - }
90 + /**
91 + * Manage general email settings.
92 + *
93 + * @return bool True if saved successfully, false if not.
94 + *
95 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
96 + */
97 + public static function emails_general_settings_handle() {
98 + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsEmail' ) ) {
99 + $emails_settings = get_option( 'mainwp_settings_notification_emails' );
100 + if ( ! is_array( $emails_settings ) ) {
101 + $emails_settings = array();
102 + }
99 103
100 - /**
101 - * Render all email settings options.
102 - *
103 - * Credits.
104 - *
105 - * Plugin-Name: WooCommerce.
106 - * Plugin URI: https://woocommerce.com/.
107 - * Author: Automattic.
108 - * Author URI: https://woocommerce.com.
109 - * License: GPLv3 or later.
110 - *
111 - * @param bool $updated True if page loaded after update, false if not.
112 - */
113 - public function render_all_settings( $updated ) {
104 + $type = isset( $_POST['mainwp_setting_emails_type'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_setting_emails_type'] ) ) : '';
105 + $update_settings = isset( $_POST['mainwp_settingEmails'][ $type ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_settingEmails'][ $type ] ) ) : '';
106 + $update_settings['disable'] = ( isset( $_POST['mainwp_settingEmails'][ $type ] ) && isset( $_POST['mainwp_settingEmails'][ $type ]['disable'] ) ) ? 0 : 1; // to set 'disable' values.
107 + $emails_settings[ $type ] = $update_settings;
114 108
115 - if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
116 - mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
117 - return;
118 - }
109 + /**
110 + * Action: mainwp_before_save_email_settings
111 + *
112 + * Fires before save email settings.
113 + *
114 + * @since 4.1
115 + */
116 + do_action( 'mainwp_before_save_email_settings', $type, $update_settings );
119 117
120 - $email_description = '';
121 - $notification_emails = self::get_notification_types();
122 - $emails_settings = get_option( 'mainwp_settings_notification_emails' );
123 - if ( ! is_array( $emails_settings ) ) {
124 - $emails_settings = array();
125 - }
118 + MainWP_Utility::update_option( 'mainwp_settings_notification_emails', $emails_settings );
126 119
127 - ?>
128 - <div id="mainwp-all-emails-settings" class="ui segment">
129 - <?php if ( $updated ) : ?>
130 - <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
131 - <?php endif; ?>
132 - <div class="ui info message">
133 - <?php printf( esc_html__( 'Email notifications sent from MainWP Dashboard are listed below. Click on an email to configure it. For additional help, please see %1$sthis help document%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/email-settings/">', '</a> <i class="external alternate icon"></i>' ); ?>
134 - </div>
135 - <table class="ui unstackable table" id="mainwp-emails-settings-table">
136 - <thead>
137 - <tr>
138 - <th class="collapsing"><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
139 - <th data-priority="1"><?php esc_html_e( 'Email', 'mainwp' ); ?></th>
140 - <th><?php esc_html_e( 'Description', 'mainwp' ); ?></th>
141 - <th ><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></th>
142 - <th class="no-sort collapsing" data-priority="2" style="text-align:right">&nbsp;</th>
143 - </tr>
144 - </thead>
145 - <tbody>
146 - <?php foreach ( $notification_emails as $type => $name ) : ?>
147 - <?php
148 - $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
149 - $default = self::get_default_emails_fields( $type, '', true );
150 - $options = array_merge( $default, $options );
120 + /**
121 + * Action: mainwp_after_save_email_settings
122 + *
123 + * Fires after save email settings.
124 + *
125 + * @since 4.1
126 + */
127 + do_action( 'mainwp_after_save_email_settings', $emails_settings );
151 128
152 - $email_description = self::get_settings_desc( $type );
153 - ?>
154 - <tr>
155 - <td><?php echo ( ! $options['disable'] ) ? '<span data-tooltip="Enabled." data-position="right center" data-inverted=""><i class="circular green check inverted icon"></i></span>' : '<span data-tooltip="Disabled." data-position="right center" data-inverted=""><i class="circular x icon inverted disabled"></i></span>'; ?></td>
156 - <td><a href="admin.php?page=SettingsEmail&edit-email=<?php echo esc_html( rawurlencode( $type ) ); ?>" data-tooltip="<?php esc_attr_e( 'Click to configure the email.', 'mainwp' ); ?>" data-position="right center" data-inverted=""><?php echo esc_html( $name ); ?></a></td>
157 - <td><?php echo esc_html( $email_description ); ?></td>
158 - <td><?php echo esc_html( $options['recipients'] ); ?></td>
159 - <td style="text-align:right"><a href="admin.php?page=SettingsEmail&edit-email=<?php echo esc_html( rawurlencode( $type ) ); ?>" data-tooltip="<?php esc_attr_e( 'Click to configure the email.', 'mainwp' ); ?>" data-position="left center" data-inverted="" class="ui green mini button"><?php esc_html_e( 'Manage', 'mainwp' ); ?></a></td>
160 - </tr>
161 - <?php endforeach; ?>
162 - </tbody>
163 - <tfoot>
164 - <tr>
165 - <th class="collapsing"><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
166 - <th><?php esc_html_e( 'Email', 'mainwp' ); ?></th>
167 - <th><?php esc_html_e( 'Description', 'mainwp' ); ?></th>
168 - <th><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></th>
169 - <th>&nbsp;</th>
170 - </tr>
171 - </tfoot>
172 - </table>
173 - <?php
174 - /**
175 - * Action: mainwp_settings_email_settings
176 - *
177 - * Fires after the default email settings.
178 - *
179 - * @since 4.1
180 - */
181 - do_action( 'mainwp_settings_email_settings' );
182 - ?>
183 - <script type="text/javascript">
184 - var responsive = true;
185 - if( jQuery( window ).width() > 1140 ) {
186 - responsive = false;
187 - }
188 - jQuery( document ).ready( function() {
189 - jQuery( '#mainwp-emails-settings-table' ).DataTable( {
190 - "stateSave": true,
191 - "paging": false,
192 - "ordering": true,
193 - "columnDefs": [ { "orderable": false, "targets": [ 4 ] } ],
194 - "order": [ [ 2, "asc" ] ],
195 - "responsive": responsive,
196 - } );
197 - } );
198 - </script>
199 - </div>
200 - <?php
201 - }
129 + return true;
130 + }
131 + return false;
132 + }
202 133
203 - /**
204 - * Render email settings page.
205 - *
206 - * Credits.
207 - *
208 - * Plugin-Name: WooCommerce.
209 - * Plugin URI: https://woocommerce.com/.
210 - * Author: Automattic.
211 - * Author URI: https://woocommerce.com.
212 - * License: GPLv3 or later.
213 - *
214 - * @param string $type Email notification type.
215 - * @param bool $updated_templ True if page loaded after update, false if not.
216 - *
217 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::render_edit_template()
218 - * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_name_by_notification_type()
219 - * @uses \MainWP\Dashboard\MainWP_Notification_Template::is_overrided_template()
220 - */
221 - public function render_edit_settings( $type, $updated_templ ) {
134 + /**
135 + * Render all email settings options.
136 + *
137 + * Credits.
138 + *
139 + * Plugin-Name: WooCommerce.
140 + * Plugin URI: https://woocommerce.com/.
141 + * Author: Automattic.
142 + * Author URI: https://woocommerce.com.
143 + * License: GPLv3 or later.
144 + *
145 + * @param bool $updated True if page loaded after update, false if not.
146 + */
147 + public function render_all_settings( $updated ) {
222 148
223 - if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
224 - mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
225 - return;
226 - }
149 + if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
150 + \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
151 + return;
152 + }
227 153
228 - $emails_settings = get_option( 'mainwp_settings_notification_emails' );
229 - if ( ! is_array( $emails_settings ) ) {
230 - $emails_settings = array();
231 - }
154 + $email_description = '';
155 + $notification_emails = static::get_notification_types();
156 + $emails_settings = get_option( 'mainwp_settings_notification_emails' );
157 + if ( ! is_array( $emails_settings ) ) {
158 + $emails_settings = array();
159 + }
232 160
233 - $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
161 + ?>
162 + <div id="mainwp-all-emails-settings" class="ui padded segment">
163 + <?php if ( $updated ) : ?>
164 + <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
165 + <?php endif; ?>
166 + <div class="ui info message">
167 + <?php
168 + /* translators: 1: Opening anchor tag, 2: Closing anchor tag with external link icon */
169 + printf( esc_html__( 'Email notifications sent from MainWP Dashboard are listed below. Click on an email to configure it. For additional help, please see %1$sthis help document%2$s.', 'mainwp' ), '<a href="https://docs.mainwp.com/sites/management/mainwp-dashboard-settings#manage-email-settings">', '</a> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe.
170 + ?>
171 + </div>
172 + <table class="ui unstackable table" id="mainwp-emails-settings-table">
173 + <thead>
174 + <tr>
175 + <th scope="col" class="collapsing"><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
176 + <th scope="col" data-priority="1"><?php esc_html_e( 'Email', 'mainwp' ); ?></th>
177 + <th scope="col"><?php esc_html_e( 'Description', 'mainwp' ); ?></th>
178 + <th scope="col"><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></th>
179 + <th scope="col" class="no-sort collapsing" data-priority="2" style="text-align:right">&nbsp;</th>
180 + </tr>
181 + </thead>
182 + <tbody>
183 + <?php foreach ( $notification_emails as $type => $name ) : ?>
184 + <?php
185 + $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
186 + $default = static::get_default_emails_fields( $type, '', true );
187 + $options = array_merge( $default, $options );
234 188
235 - $default = self::get_default_emails_fields( $type, '', true );
236 - $options = array_merge( $default, $options );
189 + $email_description = static::get_settings_desc( $type );
190 + ?>
191 + <tr>
192 + <td><?php echo ( ! $options['disable'] ) ? '<span data-tooltip="Enabled." data-position="right center" data-inverted=""><i class="circular green check inverted icon"></i></span>' : '<span data-tooltip="Disabled." data-position="right center" data-inverted=""><i class="circular x icon inverted disabled"></i></span>'; ?></td>
193 + <td><a href="admin.php?page=SettingsEmail&edit-email=<?php echo esc_html( rawurlencode( $type ) ); ?>" data-tooltip="<?php esc_attr_e( 'Click to configure the email.', 'mainwp' ); ?>" data-position="right center" data-inverted=""><?php echo esc_html( $name ); ?></a></td>
194 + <td><?php echo esc_html( $email_description ); ?></td>
195 + <td><?php echo esc_html( $options['recipients'] ); ?></td>
196 + <td style="text-align:right"><a href="admin.php?page=SettingsEmail&edit-email=<?php echo esc_html( rawurlencode( $type ) ); ?>" data-tooltip="<?php esc_attr_e( 'Click to configure the email.', 'mainwp' ); ?>" data-position="left center" data-inverted="" class="ui green mini button"><?php esc_html_e( 'Manage', 'mainwp' ); ?></a></td>
197 + </tr>
198 + <?php endforeach; ?>
199 + </tbody>
200 + <tfoot>
201 + <tr>
202 + <th scope="col" class="collapsing"><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
203 + <th scope="col"><?php esc_html_e( 'Email', 'mainwp' ); ?></th>
204 + <th scope="col"><?php esc_html_e( 'Description', 'mainwp' ); ?></th>
205 + <th scope="col"><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></th>
206 + <th scope="col">&nbsp;</th>
207 + </tr>
208 + </tfoot>
209 + </table>
210 + <?php
211 + /**
212 + * Action: mainwp_settings_email_settings
213 + *
214 + * Fires after the default email settings.
215 + *
216 + * @since 4.1
217 + */
218 + do_action( 'mainwp_settings_email_settings' );
219 + ?>
220 + <script type="text/javascript">
221 + var responsive = true;
222 + if( jQuery( window ).width() > 1140 ) {
223 + responsive = false;
224 + }
225 + jQuery( document ).ready( function() {
226 + jQuery( '#mainwp-emails-settings-table' ).DataTable( {
227 + "stateSave": true,
228 + "paging": false,
229 + "ordering": true,
230 + "columnDefs": [ { "orderable": false, "targets": [ 4 ] } ],
231 + "order": [ [ 2, "asc" ] ],
232 + "responsive": responsive,
233 + } );
234 + } );
235 + </script>
236 + </div>
237 + <?php
238 + }
237 239
238 - $title = self::get_notification_types( $type );
240 + /**
241 + * Render email settings page.
242 + *
243 + * Credits.
244 + *
245 + * Plugin-Name: WooCommerce.
246 + * Plugin URI: https://woocommerce.com/.
247 + * Author: Automattic.
248 + * Author URI: https://woocommerce.com.
249 + * License: GPLv3 or later.
250 + *
251 + * @param string $type Email notification type.
252 + * @param bool $updated_templ True if page loaded after update, false if not.
253 + *
254 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::render_edit_template()
255 + * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_name_by_notification_type()
256 + * @uses \MainWP\Dashboard\MainWP_Notification_Template::is_overrided_template()
257 + */
258 + public function render_edit_settings( $type, $updated_templ ) {
239 259
240 - $email_description = self::get_settings_desc( $type );
260 + if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
261 + \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
262 + return;
263 + }
241 264
242 - ?>
243 - <div id="mainwp-emails-settings" class="ui segment">
244 - <?php self::render_update_template_message( $updated_templ ); ?>
245 - <div class="ui form">
246 - <form method="POST" action="admin.php?page=SettingsEmail">
247 - <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'SettingsEmail' ) ); ?>" />
248 - <input type="hidden" name="mainwp_setting_emails_type" value="<?php echo esc_html( $type ); ?>" />
249 - <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-email-tokens-info-message' ) ) : ?>
250 - <div class="ui info message">
251 - <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-manage-updates-message"></i>
252 - <?php printf( esc_html__( '%1$sBoilerplate%2$s and %3$sReports%4$s extensions tokens are supported in the email settings and templates if Extensions are in use.', 'mainwp' ), '<a href="https://mainwp.com/extension/boilerplate/" target="_blank">', '</a> <i class="external alternate icon"></i>', '<a href="https://mainwp.com/extension/pro-reports/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?>
253 - </div>
254 - <?php endif; ?>
255 - <h3 class="ui header"><?php echo esc_html( $title ); ?></h3>
256 - <div class="sub header"><?php echo esc_html( $email_description ); ?></h3></div>
257 - <div class="ui divider"></div>
258 - <div class="ui grid field">
259 - <label class="six wide column middle aligned"><?php esc_html_e( 'Enable', 'mainwp' ); ?></label>
260 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable this email notification.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
261 - <input type="checkbox" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][disable]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][disable]" <?php echo ( 0 === (int) $options['disable'] ) ? 'checked="true"' : ''; ?>/>
262 - </div>
263 - </div>
264 - <div class="ui grid field">
265 - <label class="six wide column middle aligned"><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></label>
266 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'You can add multiple emails by separating them with comma.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
267 - <input type="text" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][recipients]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][recipients]" value="<?php echo esc_html( $options['recipients'] ); ?>"/>
268 - </div>
269 - </div>
270 - <div class="ui grid field">
271 - <label class="six wide column middle aligned"><?php esc_html_e( 'Subject', 'mainwp' ); ?></label>
272 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enter the email subject.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
273 - <input type="text" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][subject]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][subject]" value="<?php echo esc_html( $options['subject'] ); ?>"/>
274 - </div>
275 - </div>
276 - <div class="ui grid field">
277 - <label class="six wide column middle aligned"><?php esc_html_e( 'Email heading', 'mainwp' ); ?></label>
278 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enter the email heading.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
279 - <input type="text" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][heading]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][heading]" value="<?php echo esc_html( $options['heading'] ); ?>"/>
280 - </div>
281 - </div>
282 - <div class="ui grid field" >
283 - <label class="six wide column middle aligned"><?php esc_html_e( 'HTML template', 'mainwp' ); ?></label>
284 - <div class="ui ten wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
285 - <?php
286 - $templ = MainWP_Notification_Template::get_template_name_by_notification_type( $type );
287 - $overrided = MainWP_Notification_Template::instance()->is_overrided_template( $type );
288 - /**
289 - *
290 - * Use mainwp_notification_template_copy_message instead.
291 - *
292 - * @deprecated Since v4.3.
293 - */
294 - $copy_message = apply_filters( 'minwp_notification_template_copy_message', '', $templ, $type, $overrided );
295 - /**
296 - *
297 - * Filter mainwp_notification_template_copy_message.
298 - *
299 - * @since v4.3
300 - */
301 - $copy_message = apply_filters( 'mainwp_notification_template_copy_message', $copy_message, $templ, $type, $overrided );
302 - if ( empty( $copy_message ) ) {
303 - $copy_message = $overrided ? esc_html__( 'This template has been overridden and can be found in:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . '</code>' : esc_html__( 'To override and edit this email template copy:', 'mainwp' ) . ' <code>mainwp/templates/' . esc_html( $templ ) . '</code> ' . esc_html__( 'to the folder:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . '</code>';
304 - }
305 - echo $copy_message; // phpcs:ignore WordPress.Security.EscapeOutput
306 - ?>
307 - </div>
308 - </div>
309 - <div class="ui grid field" >
310 - <label class="six wide column middle aligned"></label>
311 - <div class="ui ten wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
312 - <?php if ( $overrided ) : ?>
313 - <a href="<?php echo esc_url( wp_nonce_url( 'admin.php?page=SettingsEmail&edit-email=' . $type, 'delete-email-template' ) ); ?>" onclick="mainwp_confirm('<?php echo esc_js( 'Are you sure you want to delete this template file?', 'mainwp' ); ?>', function(){ window.location = jQuery('a#email-delete-template').attr('href');}); return false;" id="email-delete-template" class="ui button"><?php esc_html_e( 'Return to Default Template', 'mainwp' ); ?></a>
314 - <?php else : ?>
315 - <a href="<?php echo esc_url( wp_nonce_url( 'admin.php?page=SettingsEmail&edit-email=' . $type, 'copy-email-template' ) ); ?>" class="ui button"><?php esc_html_e( 'Copy file to uploads', 'mainwp' ); ?></a>
316 - <?php endif; ?>
317 - <?php if ( $overrided ) : ?>
318 - <a href="javascript:void(0)" class="ui button" onclick="mainwp_view_template('<?php echo esc_js( $type ); ?>', true ); return false;"><?php esc_html_e( 'Edit Template', 'mainwp' ); ?></a>
319 - <?php else : ?>
320 - <a href="javascript:void(0)" class="ui button" onclick="mainwp_view_template('<?php echo esc_js( $type ); ?>', true ); return false;"><?php esc_html_e( 'View Template', 'mainwp' ); ?></a>
321 - <?php endif; ?>
322 - </div>
323 - </div>
324 - <div class="ui divider"></div>
325 - <a href="admin.php?page=SettingsEmail" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
326 - <input type="submit" name="submit" id="submit" class="ui green big button right floated" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
327 - <div style="clear:both"></div>
328 - </form>
329 - </div>
330 - </div>
331 - <?php MainWP_Manage_Sites_View::render_edit_template( $type ); ?>
332 - <?php
333 - }
265 + $emails_settings = get_option( 'mainwp_settings_notification_emails' );
266 + if ( ! is_array( $emails_settings ) ) {
267 + $emails_settings = array();
268 + }
334 269
270 + $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
335 271
336 - /**
337 - * Get email settings description.
338 - *
339 - * @param string $type Email notification type.
340 - *
341 - * @return string $email_description Email settings Description.
342 - */
343 - public static function get_settings_desc( $type ) {
344 - $email_description = '';
345 - if ( 'daily_digest' === $type ) {
346 - $email_description = esc_html__( 'Daily notification about available updates and disconnected sites.', 'mainwp' );
347 - } elseif ( 'uptime' === $type ) {
348 - $email_description = esc_html__( 'Alert if any of your websites is down.', 'mainwp' );
349 - } elseif ( 'site_health' === $type ) {
350 - $email_description = esc_html__( 'Alert if any of your websites site health goes under the threshold.', 'mainwp' );
351 - } elseif ( 'http_check' === $type ) {
352 - $email_description = esc_html__( 'Alert if any of your websites return unexpected HTTP status after running updates.', 'mainwp' );
353 - } elseif ( 'deactivated_license_alert' === $type ) {
354 - $email_description = esc_html__( 'Receive a notification when an extension\'s license is deactivated.', 'mainwp' );
355 - }
272 + $default = static::get_default_emails_fields( $type, '', true );
273 + $options = array_merge( $default, $options );
356 274
357 - $addition_desc = apply_filters( 'mainwp_notification_type_desc', '', $type );
358 - if ( ! empty( $addition_desc ) ) {
359 - $email_description = $addition_desc;
360 - }
275 + $title = static::get_notification_types( $type );
361 276
362 - return $email_description;
363 - }
277 + $email_description = static::get_settings_desc( $type );
364 278
365 - /**
366 - * Render the notification after the update process.
367 - *
368 - * @param int $updated Update code (copied, saved or deleted).
369 - */
370 - public static function render_update_template_message( $updated ) {
371 - ?>
372 - <?php if ( 1 === (int) $updated ) : ?>
373 - <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Custom email template deleted successfully.', 'mainwp' ); ?></div>
374 - <?php endif; ?>
375 - <?php if ( 2 === (int) $updated ) : ?>
376 - <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Email template copied successfully.', 'mainwp' ); ?></div>
377 - <?php endif; ?>
378 - <?php if ( 3 === (int) $updated ) : ?>
379 - <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Email template updated successfully.', 'mainwp' ); ?></div>
380 - <?php endif; ?>
381 - <?php
382 - }
279 + ?>
280 + <div id="mainwp-emails-settings" class="ui segment">
281 + <?php static::render_update_template_message( $updated_templ ); ?>
282 + <div class="ui form">
283 + <form method="POST" action="admin.php?page=SettingsEmail">
284 + <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'SettingsEmail' ) ); ?>" />
285 + <input type="hidden" name="mainwp_setting_emails_type" value="<?php echo esc_html( $type ); ?>" />
286 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-email-tokens-info-message' ) ) : ?>
287 + <div class="ui info message">
288 + <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-manage-updates-message"></i>
289 + <?php
290 + /* translators: 1: Opening anchor tag for Boilerplate, 2: Closing anchor tag, 3: Opening anchor tag for Reports, 4: Closing anchor tag */
291 + printf( esc_html__( '%1$sBoilerplate%2$s and %3$sReports%4$s extensions tokens are supported in the email settings and templates if Extensions are in use.', 'mainwp' ), '<a href="https://mainwp.com/extension/boilerplate/" target="_blank">', '</a> <i class="external alternate icon"></i>', '<a href="https://mainwp.com/extension/pro-reports/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe.
292 + ?>
293 + </div>
294 + <?php endif; ?>
295 + <h3 class="ui header">
296 + <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-email-' . esc_attr( $type ) ); ?>
297 + <?php echo esc_html( $title ); ?></h3>
298 + <div class="sub header"><?php echo esc_html( $email_description ); ?></h3></div>
299 + <div class="ui divider"></div>
300 + <?php
301 + $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'disable' );
302 + ?>
303 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-email-<?php echo esc_attr( $type ); ?>" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
304 + <label class="six wide column middle aligned">
305 + <?php
306 + MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'disable', (int) $options['disable'] );
307 + esc_html_e( 'Enable', 'mainwp' );
308 + ?>
309 + </label>
310 + <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable this email notification.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
311 + <input type="checkbox" inverted-value="1" class="settings-field-value-change-handler" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][disable]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][disable]" <?php echo ( 0 === (int) $options['disable'] ) ? 'checked="true"' : ''; ?>/>
312 + </div>
313 + </div>
314 + <?php
315 + $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'recipients' );
316 + ?>
317 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-email-<?php echo esc_attr( $type ); ?>" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
318 + <label class="six wide column middle aligned">
319 + <?php
320 + MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'recipients', $options['recipients'] );
321 + esc_html_e( 'Recipient(s)', 'mainwp' );
322 + ?>
323 + </label>
324 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'You can add multiple emails by separating them with comma.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
325 + <input type="text" class="settings-field-value-change-handler" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][recipients]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][recipients]" value="<?php echo esc_html( $options['recipients'] ); ?>"/>
326 + </div>
327 + </div>
328 + <?php
329 + $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'subject' );
330 + ?>
331 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-email-<?php echo esc_attr( $type ); ?>" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
332 + <label class="six wide column middle aligned">
333 + <?php
334 + MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'subject', $options['subject'] );
335 + esc_html_e( 'Subject', 'mainwp' );
336 + ?>
337 + </label>
338 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enter the email subject.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
339 + <input type="text" class="settings-field-value-change-handler" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][subject]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][subject]" value="<?php echo esc_html( $options['subject'] ); ?>"/>
340 + </div>
341 + </div>
342 + <?php
343 + $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'heading' );
344 + ?>
345 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-email-<?php echo esc_attr( $type ); ?>" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
346 + <label class="six wide column middle aligned">
347 + <?php
348 + MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'heading', $options['heading'] );
349 + esc_html_e( 'Email heading', 'mainwp' );
350 + ?>
351 + </label>
352 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enter the email heading.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
353 + <input type="text" class="settings-field-value-change-handler" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][heading]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][heading]" value="<?php echo esc_html( $options['heading'] ); ?>"/>
354 + </div>
355 + </div>
356 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-email-<?php echo esc_attr( $type ); ?>" >
357 + <?php
358 + $templ = MainWP_Notification_Template::get_template_name_by_notification_type( $type );
359 + $overrided = MainWP_Notification_Template::instance()->is_overrided_template( $type );
360 + ?>
361 + <label class="six wide column middle aligned">
362 + <?php
363 + MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'overrided', (int) $overrided );
364 + esc_html_e( 'HTML template', 'mainwp' );
365 + ?>
366 + </label>
367 + <div class="ui ten wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
368 + <?php
369 + /**
370 + *
371 + * Use mainwp_notification_template_copy_message instead.
372 + *
373 + * @deprecated Since v4.3.
374 + */
375 + $copy_message = apply_filters( 'minwp_notification_template_copy_message', '', $templ, $type, $overrided );
376 + /**
377 + *
378 + * Filter mainwp_notification_template_copy_message.
379 + *
380 + * @since v4.3
381 + */
382 + $copy_message = apply_filters( 'mainwp_notification_template_copy_message', $copy_message, $templ, $type, $overrided );
383 + if ( empty( $copy_message ) ) {
384 + $copy_message = $overrided ? esc_html__( 'This template has been overridden and can be found in:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . '</code>' : esc_html__( 'To override and edit this email template copy:', 'mainwp' ) . ' <code>mainwp/templates/' . esc_html( $templ ) . '</code> ' . esc_html__( 'to the folder:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . '</code>';
385 + }
386 + echo $copy_message; // phpcs:ignore WordPress.Security.EscapeOutput
387 + ?>
388 + </div>
389 + </div>
390 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-email-<?php echo esc_attr( $type ); ?>" >
391 + <label class="six wide column middle aligned"></label>
392 + <div class="ui ten wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
393 + <?php if ( $overrided ) : ?>
394 + <a href="<?php echo esc_url( wp_nonce_url( 'admin.php?page=SettingsEmail&edit-email=' . $type, 'delete-email-template' ) ); ?>" onclick="mainwp_confirm('<?php echo esc_js( 'Are you sure you want to delete this template file?', 'mainwp' ); ?>', function(){ window.location = jQuery('a#email-delete-template').attr('href');}); return false;" id="email-delete-template" class="ui button"><?php esc_html_e( 'Return to Default Template', 'mainwp' ); ?></a>
395 + <?php else : ?>
396 + <a href="<?php echo esc_url( wp_nonce_url( 'admin.php?page=SettingsEmail&edit-email=' . $type, 'copy-email-template' ) ); ?>" class="ui button"><?php esc_html_e( 'Copy file to uploads', 'mainwp' ); ?></a>
397 + <?php endif; ?>
398 + <?php if ( $overrided ) : ?>
399 + <a href="javascript:void(0)" class="ui button" onclick="mainwp_view_template('<?php echo esc_js( $type ); ?>', true ); return false;"><?php esc_html_e( 'Edit Template', 'mainwp' ); ?></a>
400 + <?php else : ?>
401 + <a href="javascript:void(0)" class="ui button" onclick="mainwp_view_template('<?php echo esc_js( $type ); ?>', true ); return false;"><?php esc_html_e( 'View Template', 'mainwp' ); ?></a>
402 + <?php endif; ?>
403 + </div>
404 + </div>
405 + <div class="ui divider"></div>
406 + <a href="admin.php?page=SettingsEmail" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
407 + <input type="submit" name="submit" id="submit" class="ui green big button right floated" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
408 + <div style="clear:both"></div>
409 + </form>
410 + </div>
411 + </div>
412 + <?php MainWP_Manage_Sites_View::render_edit_template( $type ); ?>
413 + <?php
414 + }
383 415
384 - /**
385 - * Get email notification types.
386 - *
387 - * @param string $type Email notification type.
388 - *
389 - * @return mixed Notification types.
390 - */
391 - public static function get_notification_types( $type = '' ) {
392 - $types = array(
393 - 'daily_digest' => esc_html__( 'Daily Digest Email', 'mainwp' ),
394 - 'uptime' => esc_html__( 'Basic Uptime Monitoring Email', 'mainwp' ),
395 - 'site_health' => esc_html__( 'Site Health Monitoring Email', 'mainwp' ),
396 - 'deactivated_license_alert' => esc_html__( 'Extension License Deactivation Notification Email', 'mainwp' ),
397 - );
398 416
399 - $enable_http_check = get_option( 'mainwp_check_http_response', 0 );
417 + /**
418 + * Get email settings description.
419 + *
420 + * @param string $type Email notification type.
421 + *
422 + * @return string $email_description Email settings Description.
423 + */
424 + public static function get_settings_desc( $type ) {
425 + $email_description = '';
426 + if ( 'daily_digest' === $type ) {
427 + $email_description = esc_html__( 'Daily notification about available updates and disconnected sites.', 'mainwp' );
428 + } elseif ( 'uptime' === $type ) {
429 + $email_description = esc_html__( 'Alert if any of your websites is down.', 'mainwp' );
430 + } elseif ( 'site_health' === $type ) {
431 + $email_description = esc_html__( 'Alert if any of your websites site health goes under the threshold.', 'mainwp' );
432 + } elseif ( 'http_check' === $type ) {
433 + $email_description = esc_html__( 'Alert if any of your websites return unexpected HTTP status after running updates.', 'mainwp' );
434 + } elseif ( 'deactivated_license_alert' === $type ) {
435 + $email_description = esc_html__( 'Receive a notification when an extension\'s license is deactivated.', 'mainwp' );
436 + } elseif ( 'auto_updates' === $type ) {
437 + $email_description = esc_html__( 'Receive a notification about auto-updates.', 'mainwp' );
438 + }
400 439
401 - if ( $enable_http_check ) {
402 - $types['http_check'] = esc_html__( 'After Updates HTTP Check Email', 'mainwp' );
403 - }
440 + $addition_desc = apply_filters( 'mainwp_notification_type_desc', '', $type );
441 + if ( ! empty( $addition_desc ) ) {
442 + $email_description = $addition_desc;
443 + }
404 444
405 - $addition_types = apply_filters( 'mainwp_notification_types', array(), $type );
406 - if ( ! empty( $addition_types ) ) {
407 - $types = array_merge( $types, $addition_types );
408 - }
445 + return $email_description;
446 + }
409 447
410 - if ( empty( $type ) ) {
411 - return $types;
412 - } else {
413 - return ( isset( $types[ $type ] ) ) ? $types[ $type ] : false;
414 - }
415 - }
448 + /**
449 + * Render the notification after the update process.
450 + *
451 + * @param int $updated Update code (copied, saved or deleted).
452 + */
453 + public static function render_update_template_message( $updated ) {
454 + switch ( (int) $updated ) {
455 + case 1:
456 + ?>
457 + <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Custom email template deleted successfully.', 'mainwp' ); ?></div>
458 + <?php
459 + break;
460 + case 2:
461 + ?>
462 + <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Email template copied successfully.', 'mainwp' ); ?></div>
463 + <?php
464 + break;
465 + case 3:
466 + ?>
467 + <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Email template updated successfully.', 'mainwp' ); ?></div>
468 + <?php
469 + break;
470 + case 31:
471 + ?>
472 + <div class="ui message yellow"><i class="close icon"></i> <?php esc_html_e( 'Email template update failed. Please try again.', 'mainwp' ); ?></div>
473 + <?php
474 + break;
475 + case 32:
476 + ?>
477 + <div class="ui message yellow"><i class="close icon"></i> <?php esc_html_e( 'Email template failed to open. Please try again.', 'mainwp' ); ?></div>
478 + <?php
479 + break;
480 + case 33:
481 + ?>
482 + <div class="ui message yellow"><i class="close icon"></i> <?php esc_html_e( 'Email template is not writable. Please try again.', 'mainwp' ); ?></div>
483 + <?php
484 + break;
485 + case 34:
486 + ?>
487 + <div class="ui message yellow"><i class="close icon"></i> <?php esc_html_e( 'The destination email template is invalid and could not be saved. Please try again.', 'mainwp' ); ?></div>
488 + <?php
489 + break;
490 + case 35:
491 + ?>
492 + <div class="ui message yellow"><i class="close icon"></i> <?php esc_html_e( 'Email template update failed. Please ensure you have theme editing permissions and try again.', 'mainwp' ); ?></div>
493 + <?php
494 + break;
495 + default:
496 + break;
497 + }
498 + }
416 499
417 - /**
418 - * Get general email notifications settings.
419 - *
420 - * @param string $type Email type.
421 - *
422 - * @see function get_notification_types()
423 - *
424 - * @return array An array containing the email settings.
425 - */
426 - public static function get_general_email_settings( $type ) {
427 - $settings = get_option( 'mainwp_settings_notification_emails', array() );
428 - if ( ! is_array( $settings ) ) {
429 - $settings = array();
430 - }
500 + /**
501 + * Get email notification types.
502 + *
503 + * @param string $type Email notification type.
504 + *
505 + * @return mixed Notification types.
506 + */
507 + public static function get_notification_types( $type = '' ) {
508 + $types = array(
509 + 'daily_digest' => esc_html__( 'Daily Digest Email', 'mainwp' ),
510 + 'auto_updates' => esc_html__( 'Auto Updates Email', 'mainwp' ),
511 + 'uptime' => esc_html__( 'Uptime Monitoring Email', 'mainwp' ),
512 + 'site_health' => esc_html__( 'Site Health Monitoring Email', 'mainwp' ),
513 + 'deactivated_license_alert' => esc_html__( 'Extension License Deactivation Notification Email', 'mainwp' ),
514 + );
431 515
432 - $options = isset( $settings[ $type ] ) ? $settings[ $type ] : array();
433 - $default = self::get_default_emails_fields( $type, '', true );
434 - return array_merge( $default, $options );
435 - }
516 + $enable_http_check = get_option( 'mainwp_check_http_response', 0 );
436 517
437 - /**
438 - * Get general notification email.
439 - *
440 - * @return string|empty recipients.
441 - */
442 - public static function get_general_email() {
443 - $gen_email_settings = self::get_general_email_settings( 'daily_digest' );
444 - return isset( $gen_email_settings['recipients'] ) ? $gen_email_settings['recipients'] : '';
445 - }
518 + if ( $enable_http_check ) {
519 + $types['http_check'] = esc_html__( 'After Updates HTTP Check Email', 'mainwp' );
520 + }
446 521
447 - /**
448 - * Update general notification email.
449 - *
450 - * @param string $emails Emails.
451 - *
452 - * @return void
453 - */
454 - public static function update_general_email( $emails ) {
455 - $emails_settings = get_option( 'mainwp_settings_notification_emails' );
456 - if ( ! is_array( $emails_settings ) ) {
457 - $emails_settings = array();
458 - }
459 - $type = 'daily_digest';
460 - $update_settings = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
461 - $update_settings['recipients'] = $emails;
462 - $emails_settings[ $type ] = $update_settings;
463 - MainWP_Utility::update_option( 'mainwp_settings_notification_emails', $emails_settings );
464 - }
522 + $addition_types = apply_filters( 'mainwp_notification_types', array(), $type );
523 + if ( ! empty( $addition_types ) ) {
524 + $types = array_merge( $types, $addition_types );
525 + }
465 526
466 - /**
467 - * Get email settings for a single site.
468 - *
469 - * @param string $type Email type.
470 - * @param object $website Object containing the child site information.
471 - *
472 - * @return array An array containing the email settings.
473 - *
474 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_tokens_site_values()
475 - * @uses \MainWP\Dashboard\MainWP_System_Utility::replace_tokens_values()
476 - */
477 - public static function get_site_email_settings( $type, $website ) {
478 - if ( empty( $website ) || ! property_exists( $website, 'settings_notification_emails' ) ) {
479 - return array( 'disable' => 1 );
480 - }
481 - $settings = array();
482 - if ( ! empty( $website->settings_notification_emails ) ) {
483 - $settings = json_decode( $website->settings_notification_emails, true );
484 - }
527 + if ( empty( $type ) ) {
528 + return $types;
529 + } else {
530 + return ( isset( $types[ $type ] ) ) ? $types[ $type ] : false;
531 + }
532 + }
485 533
486 - if ( ! is_array( $settings ) ) {
487 - $settings = array();
488 - }
534 + /**
535 + * Get general email notifications settings.
536 + *
537 + * @param string $type Email type.
538 + *
539 + * @see function get_notification_types()
540 + *
541 + * @return array An array containing the email settings.
542 + */
543 + public static function get_general_email_settings( $type ) {
544 + $settings = get_option( 'mainwp_settings_notification_emails', array() );
545 + if ( ! is_array( $settings ) ) {
546 + $settings = array();
547 + }
489 548
490 - $options = isset( $settings[ $type ] ) ? $settings[ $type ] : array();
491 - $default = self::get_default_emails_fields( $type );
492 - $options = array_merge( $default, $options );
549 + $options = isset( $settings[ $type ] ) ? $settings[ $type ] : array();
550 + $default = static::get_default_emails_fields( $type, '', true );
551 + return array_merge( $default, $options );
552 + }
493 553
494 - if ( preg_match( '/\[[^\]]+\]/is', $options['subject'] . $options['heading'], $matches ) ) {
495 - $tokens_values = MainWP_System_Utility::get_tokens_site_values( $website );
496 - $options['subject'] = MainWP_System_Utility::replace_tokens_values( $options['subject'], $tokens_values );
497 - $options['heading'] = MainWP_System_Utility::replace_tokens_values( $options['heading'], $tokens_values );
498 - }
554 + /**
555 + * Prepare general email notifications settings.
556 + *
557 + * @param array $options Email settings.
558 + * @param object $website Site data.
559 + *
560 + * @return void.
561 + */
562 + public static function prepare_general_email_settings_for_site( &$options, $website ) {
563 + if ( is_array( $options ) && isset( $options['subject'] ) && isset( $options['heading'] ) && isset( $options['recipients'] ) ) {
564 + if ( preg_match( '/\[[^\]]+\]/is', $options['subject'] . $options['heading'], $matches ) ) {
565 + $tokens_values = MainWP_System_Utility::get_tokens_site_values( $website, true );
566 + $options['subject'] = MainWP_System_Utility::replace_tokens_values( $options['subject'], $tokens_values );
567 + $options['heading'] = MainWP_System_Utility::replace_tokens_values( $options['heading'], $tokens_values );
568 + }
499 569
500 - if ( preg_match( '/\[[^\]]+\]/is', $options['recipients'] . $options['subject'] . $options['heading'], $matches ) ) {
501 - // support boilerplate and reports tokens.
502 - $fields = array( 'recipients', 'subject', 'heading' );
503 - $options = self::replace_tokens_for_settings( $options, $fields, $website );
504 - }
570 + if ( preg_match( '/\[[^\]]+\]/is', $options['recipients'] . $options['subject'] . $options['heading'], $matches ) ) {
571 + // support boilerplate and reports tokens.
572 + $fields = array( 'recipients', 'subject', 'heading' );
573 + $options = static::replace_tokens_for_settings( $options, $fields, $website );
574 + }
575 + }
576 + }
505 577
506 - return $options;
507 - }
578 + /**
579 + * Get general notification email.
580 + *
581 + * @return string|empty recipients.
582 + */
583 + public static function get_general_email() {
584 + $gen_email_settings = static::get_general_email_settings( 'daily_digest' );
585 + return isset( $gen_email_settings['recipients'] ) ? $gen_email_settings['recipients'] : '';
586 + }
508 587
509 - /**
510 - * Get default email notifications values.
511 - *
512 - * @param string $type Email type.
513 - * @param string $field Field name.
514 - * @param bool $general General or individual site settings.
515 - *
516 - * @return array|string Email field settings value.
517 - *
518 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_notification_email()
519 - */
520 - public static function get_default_emails_fields( $type, $field = '', $general = false ) {
588 + /**
589 + * Update general notification email.
590 + *
591 + * @param string $emails Emails.
592 + *
593 + * @return void
594 + */
595 + public static function update_general_email( $emails ) {
596 + $emails_settings = get_option( 'mainwp_settings_notification_emails' );
597 + if ( ! is_array( $emails_settings ) ) {
598 + $emails_settings = array();
599 + }
600 + $type = 'daily_digest';
601 + $update_settings = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
602 + $update_settings['recipients'] = $emails;
603 + $emails_settings[ $type ] = $update_settings;
604 + MainWP_Utility::update_option( 'mainwp_settings_notification_emails', $emails_settings );
605 + }
521 606
522 - $recipients = MainWP_System_Utility::get_notification_email();
523 - $disable = $general ? 0 : 1;
607 + /**
608 + * Get email settings for a single site.
609 + *
610 + * @param string $type Email type.
611 + * @param object $website Object containing the child site information.
612 + * @param mixed $website_status Object containing the child site status.
613 + *
614 + * @return array An array containing the email settings.
615 + *
616 + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_tokens_site_values()
617 + * @uses \MainWP\Dashboard\MainWP_System_Utility::replace_tokens_values()
618 + */
619 + public static function get_site_email_settings( $type, $website, $website_status = false ) {
620 + if ( empty( $website ) || ! property_exists( $website, 'settings_notification_emails' ) ) {
621 + return array( 'disable' => 1 );
622 + }
623 + $settings = array();
624 + if ( ! empty( $website->settings_notification_emails ) ) {
625 + $settings = json_decode( $website->settings_notification_emails, true );
626 + }
524 627
525 - $default_fields = array(
526 - 'daily_digest' => array(
527 - 'disable' => $disable,
528 - 'recipients' => $recipients,
529 - 'subject' => $general ? 'Daily Digest' : '[site.name] Daily Digest',
530 - 'heading' => $general ? 'Daily Digest' : '[site.name] Daily Digest',
531 - ),
532 - 'uptime' => array(
533 - 'disable' => $disable,
534 - 'recipients' => $recipients,
535 - 'subject' => $general ? 'Uptime Monitoring' : '[site.name] Uptime Monitoring',
536 - 'heading' => $general ? 'Uptime Monitoring' : '[site.name] Uptime Monitoring',
537 - ),
538 - 'site_health' => array(
539 - 'disable' => $disable,
540 - 'recipients' => $recipients,
541 - 'subject' => $general ? 'Site Health Monitoring' : '[site.name] Site Health Monitoring',
542 - 'heading' => $general ? 'Site Health Monitoring' : '[site.name] Site Health Monitoring',
543 - ),
544 - 'http_check' => array(
545 - 'disable' => $disable,
546 - 'recipients' => $recipients,
547 - 'subject' => 'HTTP response check',
548 - 'heading' => 'Sites Check',
549 - ),
550 - 'deactivated_license_alert' => array(
551 - 'disable' => $disable,
552 - 'recipients' => $recipients,
553 - 'subject' => 'Extension License Deactivation Notification',
554 - 'heading' => 'Extension License Deactivation Notification',
555 - ),
556 - );
628 + if ( ! is_array( $settings ) ) {
629 + $settings = array();
630 + }
557 631
558 - $addition_default_fields = apply_filters( 'mainwp_default_emails_fields', array(), $recipients, $type, $field, $general );
559 - if ( ! empty( $addition_default_fields ) ) {
560 - $default_fields = array_merge( $default_fields, $addition_default_fields );
561 - }
632 + $options = isset( $settings[ $type ] ) ? $settings[ $type ] : array();
633 + $default = static::get_default_emails_fields( $type );
634 + $options = array_merge( $default, $options );
562 635
563 - if ( ! empty( $type ) && ! empty( $field ) ) {
564 - return isset( $default_fields[ $type ] ) && isset( $default_fields[ $type ][ $field ] ) ? $default_fields[ $type ][ $field ] : '';
565 - }
636 + if ( preg_match( '/\[[^\]]+\]/is', $options['subject'] . $options['heading'], $matches ) ) {
637 + $tokens_values = MainWP_System_Utility::get_tokens_site_values( $website, true, $website_status );
638 + $options['subject'] = MainWP_System_Utility::replace_tokens_values( $options['subject'], $tokens_values );
639 + $options['heading'] = MainWP_System_Utility::replace_tokens_values( $options['heading'], $tokens_values );
640 + }
566 641
567 - if ( ! empty( $type ) && empty( $field ) ) {
568 - return isset( $default_fields[ $type ] ) ? $default_fields[ $type ] : array();
569 - }
642 + if ( preg_match( '/\[[^\]]+\]/is', $options['recipients'] . $options['subject'] . $options['heading'], $matches ) ) {
643 + // support boilerplate and reports tokens.
644 + $fields = array( 'recipients', 'subject', 'heading' );
645 + $options = static::replace_tokens_for_settings( $options, $fields, $website );
646 + }
570 647
571 - return array();
572 - }
648 + return $options;
649 + }
573 650
574 - /**
575 - * Replace site tokens for settings.
576 - *
577 - * @param array $options array of fields to find and replace tokens.
578 - * @param array $fields fields names to find.
579 - * @param object $website The website.
580 - *
581 - * @return array $options array of fields.
582 - *
583 - * @uses \MainWP\Dashboard\MainWP_System_Utility::replace_tokens_values()
584 - */
585 - public static function replace_tokens_for_settings( $options, $fields, $website ) {
651 + /**
652 + * Get default email notifications values.
653 + *
654 + * @param string $type Email type.
655 + * @param string $field Field name.
656 + * @param bool $general General or individual site settings.
657 + *
658 + * @return array|string Email field settings value.
659 + *
660 + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_notification_email()
661 + */
662 + public static function get_default_emails_fields( $type, $field = '', $general = false ) { // phpcs:ignore -- NOSONAR - complex.
586 663
587 - /**
588 - * Filter: mainwp_boilerplate_get_tokens
589 - *
590 - * Enables and filters the Boilerplate extension tokens.
591 - *
592 - * @param object $website Object containing the child site data.
593 - *
594 - * @since 4.1
595 - */
596 - $boilerplate_tokens = apply_filters( 'mainwp_boilerplate_get_tokens', false, $website );
664 + $recipients = MainWP_System_Utility::get_notification_email();
665 + $disable = $general ? 0 : 1;
597 666
598 - if ( is_array( $boilerplate_tokens ) ) {
599 - foreach ( $fields as $field ) {
600 - if ( isset( $options[ $field ] ) ) {
601 - $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $boilerplate_tokens );
602 - }
603 - }
604 - }
667 + $default_fields = array(
668 + 'daily_digest' => array(
669 + 'disable' => $disable,
670 + 'recipients' => $recipients,
671 + 'subject' => $general ? 'Daily Digest from Your MainWP Dashboard' : '[site.name] Daily Digest from Your MainWP Dashboard',
672 + 'heading' => $general ? 'Daily Digest' : '[site.name] Daily Digest',
673 + ),
674 + 'auto_updates' => array(
675 + 'disable' => $disable,
676 + 'recipients' => $recipients,
677 + 'subject' => $general ? 'Auto Updates Notification from Your MainWP Dashboard' : '[site.name] Auto Updates Notification from Your MainWP Dashboard',
678 + 'heading' => $general ? 'Auto Updates Notification' : '[site.name] Auto Updates Notification',
679 + ),
680 + 'uptime' => array(
681 + 'disable' => $disable,
682 + 'recipients' => $recipients,
683 + 'subject' => $general ? 'Uptime Monitoring Alert from your MainWP Dashboard' : '[site.name] Uptime Monitoring Alert from your MainWP Dashboard',
684 + 'heading' => $general ? 'Uptime Monitoring' : '[site.name] Uptime Monitoring',
685 + ),
686 + 'site_health' => array(
687 + 'disable' => $disable,
688 + 'recipients' => $recipients,
689 + 'subject' => $general ? 'Site Health Monitoring Alert from Your MainWP Dashboard' : '[site.name] Site Health Monitoring Alert from Your MainWP Dashboard',
690 + 'heading' => $general ? 'Site Health Monitoring' : '[site.name] Site Health Monitoring',
691 + ),
692 + 'http_check' => array(
693 + 'disable' => $disable,
694 + 'recipients' => $recipients,
695 + 'subject' => 'HTTP response check',
696 + 'heading' => 'Sites Check',
697 + ),
698 + 'deactivated_license_alert' => array(
699 + 'disable' => $disable,
700 + 'recipients' => $recipients,
701 + 'subject' => 'Extension License Deactivation Notification from Your MainWP Dashboard',
702 + 'heading' => 'Extension License Deactivation Notification',
703 + ),
704 + );
605 705
606 - /**
607 - * Filter: mainwp_pro_reports_get_site_tokens
608 - *
609 - * Enables and filters the Pro Reports extension tokens.
610 - *
611 - * @param object $website Object containing the child site data.
612 - *
613 - * @since 4.1
614 - */
615 - $report_tokens = apply_filters( 'mainwp_pro_reports_get_site_tokens', false, $website->id );
706 + $addition_default_fields = apply_filters( 'mainwp_default_emails_fields', array(), $recipients, $type, $field, $general );
707 + if ( ! empty( $addition_default_fields ) ) {
708 + $default_fields = array_merge( $default_fields, $addition_default_fields );
709 + }
616 710
617 - if ( is_array( $report_tokens ) ) {
618 - foreach ( $fields as $field ) {
619 - if ( isset( $options[ $field ] ) ) {
620 - $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $report_tokens );
621 - }
622 - }
623 - }
711 + if ( ! empty( $type ) && ! empty( $field ) ) {
712 + return isset( $default_fields[ $type ] ) && isset( $default_fields[ $type ][ $field ] ) ? $default_fields[ $type ][ $field ] : '';
713 + }
624 714
625 - /**
626 - * Filter: mainwp_client_report_get_site_tokens
627 - *
628 - * Enables and filters the Client Reports extension tokens.
629 - *
630 - * @param object $website Object containing the child site data.
631 - *
632 - * @since 4.1
633 - */
634 - $client_report_tokens = apply_filters( 'mainwp_client_report_get_site_tokens', false, $website->id );
635 - if ( is_array( $client_report_tokens ) ) {
636 - foreach ( $fields as $field ) {
637 - if ( isset( $options[ $field ] ) ) {
638 - $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $client_report_tokens );
639 - }
640 - }
641 - }
715 + if ( ! empty( $type ) && empty( $field ) ) {
716 + return isset( $default_fields[ $type ] ) ? $default_fields[ $type ] : array();
717 + }
642 718
643 - return $options;
644 - }
719 + return array();
720 + }
645 721
646 - /**
647 - * Replace site tokens for content.
648 - *
649 - * @param string $content content to find and replace tokens.
650 - * @param object $website The website.
651 - *
652 - * @return string $content after replaced tokens.
653 - *
654 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_tokens_site_values()
655 - * @uses \MainWP\Dashboard\MainWP_System_Utility::replace_tokens_values()
656 - */
657 - public static function replace_tokens_for_content( $content, $website ) {
722 + /**
723 + * Replace site tokens for settings.
724 + *
725 + * @param array $options array of fields to find and replace tokens.
726 + * @param array $fields fields names to find.
727 + * @param object $website The website.
728 + *
729 + * @return array $options array of fields.
730 + *
731 + * @uses \MainWP\Dashboard\MainWP_System_Utility::replace_tokens_values()
732 + */
733 + public static function replace_tokens_for_settings( $options, $fields, $website ) { // phpcs:ignore -- NOSONAR - complex.
658 734
659 - $tokens_values = MainWP_System_Utility::get_tokens_site_values( $website );
735 + if ( null === static::$boilerplate_tokens_loaded ) {
736 + /**
737 + * Filter: mainwp_boilerplate_get_tokens
738 + *
739 + * Enables and filters the Boilerplate extension tokens.
740 + *
741 + * @param object $website Object containing the child site data.
742 + *
743 + * @since 4.1
744 + */
745 + static::$boilerplate_tokens_loaded = apply_filters( 'mainwp_boilerplate_get_tokens', false, $website );
746 + }
660 747
661 - $content = MainWP_System_Utility::replace_tokens_values( $content, $tokens_values );
748 + $boilerplate_tokens = static::$boilerplate_tokens_loaded;
662 749
663 - // if tokens existed.
664 - if ( preg_match( '/\[[^\]]+\]/is', $content, $matches ) ) {
750 + if ( is_array( $boilerplate_tokens ) ) {
751 + foreach ( $fields as $field ) {
752 + if ( isset( $options[ $field ] ) ) {
753 + $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $boilerplate_tokens );
754 + }
755 + }
756 + }
665 757
666 - /** This filter is documented in ../class/class-mainwp-notification-settings.php */
667 - $boilerplate_tokens = apply_filters( 'mainwp_boilerplate_get_tokens', false, $website );
758 + if ( null === static::$report_tokens_loaded ) {
759 + /**
760 + * Filter: mainwp_pro_reports_get_site_tokens
761 + *
762 + * Enables and filters the Pro Reports extension tokens.
763 + *
764 + * @param object $website Object containing the child site data.
765 + *
766 + * @since 4.1
767 + */
768 + static::$report_tokens_loaded = apply_filters( 'mainwp_pro_reports_get_site_tokens', false, $website->id );
769 + }
668 770
669 - if ( is_array( $boilerplate_tokens ) ) {
670 - $content = MainWP_System_Utility::replace_tokens_values( $content, $boilerplate_tokens );
671 - }
771 + $report_tokens = static::$report_tokens_loaded;
672 772
673 - /** This filter is documented in ../class/class-mainwp-notification-settings.php */
674 - $report_tokens = apply_filters( 'mainwp_pro_reports_get_site_tokens', false, $website->id );
773 + if ( is_array( $report_tokens ) ) {
774 + foreach ( $fields as $field ) {
775 + if ( isset( $options[ $field ] ) ) {
776 + $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $report_tokens );
777 + }
778 + }
779 + }
675 780
676 - if ( is_array( $report_tokens ) ) {
677 - $content = MainWP_System_Utility::replace_tokens_values( $content, $report_tokens );
678 - }
781 + if ( null === static::$client_report_tokens_loaded ) {
782 + /**
783 + * Filter: mainwp_client_report_get_site_tokens
784 + *
785 + * Enables and filters the Client Reports extension tokens.
786 + *
787 + * @param object $website Object containing the child site data.
788 + *
789 + * @since 4.1
790 + */
791 + static::$client_report_tokens_loaded = apply_filters( 'mainwp_client_report_get_site_tokens', false, $website->id );
792 + }
679 793
680 - /** This filter is documented in ../class/class-mainwp-notification-settings.php */
681 - $client_report_tokens = apply_filters( 'mainwp_client_report_get_site_tokens', false, $website->id );
794 + $client_report_tokens = static::$client_report_tokens_loaded;
682 795
683 - if ( is_array( $client_report_tokens ) ) {
684 - $content = MainWP_System_Utility::replace_tokens_values( $content, $client_report_tokens );
685 - }
686 - }
796 + if ( is_array( $client_report_tokens ) ) {
797 + foreach ( $fields as $field ) {
798 + if ( isset( $options[ $field ] ) ) {
799 + $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $client_report_tokens );
800 + }
801 + }
802 + }
687 803
688 - return $content;
689 - }
804 + return $options;
805 + }
806 +
807 + /**
808 + * Replace site tokens for content.
809 + *
810 + * @param string $content content to find and replace tokens.
811 + * @param object $website The website.
812 + *
813 + * @return string $content after replaced tokens.
814 + *
815 + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_tokens_site_values()
816 + * @uses \MainWP\Dashboard\MainWP_System_Utility::replace_tokens_values()
817 + */
818 + public static function replace_tokens_for_content( $content, $website ) {
819 +
820 + $tokens_values = MainWP_System_Utility::get_tokens_site_values( $website, true );
821 +
822 + $content = MainWP_System_Utility::replace_tokens_values( $content, $tokens_values );
823 +
824 + // if tokens existed.
825 + if ( preg_match( '/\[[^\]]+\]/is', $content, $matches ) ) {
826 +
827 + /** This filter is documented in ../class/class-mainwp-notification-settings.php */
828 + $boilerplate_tokens = apply_filters( 'mainwp_boilerplate_get_tokens', false, $website );
829 +
830 + if ( is_array( $boilerplate_tokens ) ) {
831 + $content = MainWP_System_Utility::replace_tokens_values( $content, $boilerplate_tokens );
832 + }
833 +
834 + /** This filter is documented in ../class/class-mainwp-notification-settings.php */
835 + $report_tokens = apply_filters( 'mainwp_pro_reports_get_site_tokens', false, $website->id );
836 +
837 + if ( is_array( $report_tokens ) ) {
838 + $content = MainWP_System_Utility::replace_tokens_values( $content, $report_tokens );
839 + }
840 +
841 + /** This filter is documented in ../class/class-mainwp-notification-settings.php */
842 + $client_report_tokens = apply_filters( 'mainwp_client_report_get_site_tokens', false, $website->id );
843 +
844 + if ( is_array( $client_report_tokens ) ) {
845 + $content = MainWP_System_Utility::replace_tokens_values( $content, $client_report_tokens );
846 + }
847 + }
848 +
849 + return $content;
850 + }
690 851 }