| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Notification Settings |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Class MainWP_Notification_Settings |
| 17 |
* |
| 18 |
* @package MainWP\Dashboard |
| 19 |
*/ |
| 20 |
class MainWP_Notification_Settings { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 21 |
|
| 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; |
| 31 |
|
| 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; |
| 40 |
|
| 41 |
|
| 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; |
| 50 |
|
| 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; |
| 59 |
|
| 60 |
|
| 61 |
/** |
| 62 |
* Get class name. |
| 63 |
* |
| 64 |
* @return string Class name. |
| 65 |
*/ |
| 66 |
public static function get_class_name() { |
| 67 |
return __CLASS__; |
| 68 |
} |
| 69 |
|
| 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 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* MainWP_Notification_Settings constructor. |
| 84 |
* |
| 85 |
* Run each time the class is called. |
| 86 |
*/ |
| 87 |
public function __construct() { |
| 88 |
} |
| 89 |
|
| 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 |
} |
| 103 |
|
| 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; |
| 108 |
|
| 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 ); |
| 117 |
|
| 118 |
MainWP_Utility::update_option( 'mainwp_settings_notification_emails', $emails_settings ); |
| 119 |
|
| 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 ); |
| 128 |
|
| 129 |
return true; |
| 130 |
} |
| 131 |
return false; |
| 132 |
} |
| 133 |
|
| 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 ) { |
| 148 |
|
| 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 |
} |
| 153 |
|
| 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 |
} |
| 160 |
|
| 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"> </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 ); |
| 188 |
|
| 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"> </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 |
} |
| 239 |
|
| 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 ) { |
| 259 |
|
| 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 |
} |
| 264 |
|
| 265 |
$emails_settings = get_option( 'mainwp_settings_notification_emails' ); |
| 266 |
if ( ! is_array( $emails_settings ) ) { |
| 267 |
$emails_settings = array(); |
| 268 |
} |
| 269 |
|
| 270 |
$options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array(); |
| 271 |
|
| 272 |
$default = static::get_default_emails_fields( $type, '', true ); |
| 273 |
$options = array_merge( $default, $options ); |
| 274 |
|
| 275 |
$title = static::get_notification_types( $type ); |
| 276 |
|
| 277 |
$email_description = static::get_settings_desc( $type ); |
| 278 |
|
| 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 |
} |
| 415 |
|
| 416 |
|
| 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 |
} |
| 439 |
|
| 440 |
$addition_desc = apply_filters( 'mainwp_notification_type_desc', '', $type ); |
| 441 |
if ( ! empty( $addition_desc ) ) { |
| 442 |
$email_description = $addition_desc; |
| 443 |
} |
| 444 |
|
| 445 |
return $email_description; |
| 446 |
} |
| 447 |
|
| 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 |
} |
| 499 |
|
| 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 |
); |
| 515 |
|
| 516 |
$enable_http_check = get_option( 'mainwp_check_http_response', 0 ); |
| 517 |
|
| 518 |
if ( $enable_http_check ) { |
| 519 |
$types['http_check'] = esc_html__( 'After Updates HTTP Check Email', 'mainwp' ); |
| 520 |
} |
| 521 |
|
| 522 |
$addition_types = apply_filters( 'mainwp_notification_types', array(), $type ); |
| 523 |
if ( ! empty( $addition_types ) ) { |
| 524 |
$types = array_merge( $types, $addition_types ); |
| 525 |
} |
| 526 |
|
| 527 |
if ( empty( $type ) ) { |
| 528 |
return $types; |
| 529 |
} else { |
| 530 |
return ( isset( $types[ $type ] ) ) ? $types[ $type ] : false; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 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 |
} |
| 548 |
|
| 549 |
$options = isset( $settings[ $type ] ) ? $settings[ $type ] : array(); |
| 550 |
$default = static::get_default_emails_fields( $type, '', true ); |
| 551 |
return array_merge( $default, $options ); |
| 552 |
} |
| 553 |
|
| 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 |
} |
| 569 |
|
| 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 |
} |
| 577 |
|
| 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 |
} |
| 587 |
|
| 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 |
} |
| 606 |
|
| 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 |
} |
| 627 |
|
| 628 |
if ( ! is_array( $settings ) ) { |
| 629 |
$settings = array(); |
| 630 |
} |
| 631 |
|
| 632 |
$options = isset( $settings[ $type ] ) ? $settings[ $type ] : array(); |
| 633 |
$default = static::get_default_emails_fields( $type ); |
| 634 |
$options = array_merge( $default, $options ); |
| 635 |
|
| 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 |
} |
| 641 |
|
| 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 |
} |
| 647 |
|
| 648 |
return $options; |
| 649 |
} |
| 650 |
|
| 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. |
| 663 |
|
| 664 |
$recipients = MainWP_System_Utility::get_notification_email(); |
| 665 |
$disable = $general ? 0 : 1; |
| 666 |
|
| 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 |
); |
| 705 |
|
| 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 |
} |
| 710 |
|
| 711 |
if ( ! empty( $type ) && ! empty( $field ) ) { |
| 712 |
return isset( $default_fields[ $type ] ) && isset( $default_fields[ $type ][ $field ] ) ? $default_fields[ $type ][ $field ] : ''; |
| 713 |
} |
| 714 |
|
| 715 |
if ( ! empty( $type ) && empty( $field ) ) { |
| 716 |
return isset( $default_fields[ $type ] ) ? $default_fields[ $type ] : array(); |
| 717 |
} |
| 718 |
|
| 719 |
return array(); |
| 720 |
} |
| 721 |
|
| 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. |
| 734 |
|
| 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 |
} |
| 747 |
|
| 748 |
$boilerplate_tokens = static::$boilerplate_tokens_loaded; |
| 749 |
|
| 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 |
} |
| 757 |
|
| 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 |
} |
| 770 |
|
| 771 |
$report_tokens = static::$report_tokens_loaded; |
| 772 |
|
| 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 |
} |
| 780 |
|
| 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 |
} |
| 793 |
|
| 794 |
$client_report_tokens = static::$client_report_tokens_loaded; |
| 795 |
|
| 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 |
} |
| 803 |
|
| 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 |
} |
| 851 |
} |
| 852 |
|