PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.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 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-notification-settings.php

class-mainwp-notification-settings.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.1, at class/class-mainwp-notification-settings.php

632 lines 24.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Notification Settings
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Notification_Settings
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Notification_Settings {
16
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
26
27 /**
28 * Get class name.
29 *
30 * @return string Class name.
31 */
32 public static function get_class_name() {
33 return __CLASS__;
34 }
35
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
48 /**
49 * MainWP_Notification_Settings constructor.
50 *
51 * Run each time the class is called.
52 */
53 public function __construct() {
54 }
55
56 /**
57 * Manage general email settings.
58 *
59 * @return bool True if saved successfully, false if not.
60 */
61 public static function emails_general_settings_handle() {
62 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsEmail' ) ) {
63 $emails_settings = get_option( 'mainwp_settings_notification_emails' );
64 if ( ! is_array( $emails_settings ) ) {
65 $emails_settings = array();
66 }
67
68 // to fix incorrect field name.
69 if ( isset( $emails_settings['daily_digets'] ) ) {
70 $emails_settings['daily_digest'] = $emails_settings['daily_digets'];
71 unset( $emails_settings['daily_digets'] );
72 }
73
74 $type = isset( $_POST['mainwp_setting_emails_type'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_setting_emails_type'] ) ) : '';
75 $update_settings = isset( $_POST['mainwp_settingEmails'][ $type ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_settingEmails'][ $type ] ) ) : '';
76 $update_settings['disable'] = ( isset( $_POST['mainwp_settingEmails'][ $type ] ) && isset( $_POST['mainwp_settingEmails'][ $type ]['disable'] ) ) ? 0 : 1; // to set 'disable' values.
77 $emails_settings[ $type ] = $update_settings;
78
79 /**
80 * Action: mainwp_before_save_email_settings
81 *
82 * Fires before save email settings.
83 *
84 * @since 4.1
85 */
86 do_action( 'mainwp_before_save_email_settings', $type, $update_settings );
87
88 MainWP_Utility::update_option( 'mainwp_settings_notification_emails', $emails_settings );
89
90 /**
91 * Action: mainwp_after_save_email_settings
92 *
93 * Fires after save email settings.
94 *
95 * @since 4.1
96 */
97 do_action( 'mainwp_after_save_email_settings', $emails_settings );
98
99 return true;
100 }
101 return false;
102 }
103
104 /**
105 * Render all email settings options.
106 *
107 * Credits.
108 *
109 * Plugin-Name: WooCommerce.
110 * Plugin URI: https://woocommerce.com/.
111 * Author: Automattic.
112 * Author URI: https://woocommerce.com.
113 * License: GPLv3 or later.
114 *
115 * @param bool $updated True if page loaded after update, false if not.
116 */
117 public function render_all_settings( $updated ) {
118
119 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
120 mainwp_do_not_have_permissions( __( 'manage dashboard settings', 'mainwp' ) );
121 return;
122 }
123
124 $email_description = '';
125 $notification_emails = self::get_notification_types();
126 $emails_settings = get_option( 'mainwp_settings_notification_emails' );
127 if ( ! is_array( $emails_settings ) ) {
128 $emails_settings = array();
129 }
130
131 // to fix incorrect field name.
132 if ( isset( $emails_settings['daily_digets'] ) ) {
133 $emails_settings['daily_digest'] = $emails_settings['daily_digets'];
134 unset( $emails_settings['daily_digets'] );
135 }
136
137 ?>
138 <div id="mainwp-all-emails-settings" class="ui segment">
139 <?php if ( $updated ) : ?>
140 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
141 <?php endif; ?>
142 <div class="ui info message">
143 <?php _e( 'Email notifications sent from MainWP Dashboard are listed below. Click on an email to configure it. For additional help, please see <a href="https://kb.mainwp.com/docs/email-settings/">this help document</a>.', 'mainwp' ); ?>
144 </div>
145 <table class="ui single line table" id="mainwp-emails-settings-table">
146 <thead>
147 <tr>
148 <th class="collapsing"><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
149 <th><?php esc_html_e( 'Email', 'mainwp' ); ?></th>
150 <th><?php esc_html_e( 'Description', 'mainwp' ); ?></th>
151 <th><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></th>
152 <th style="text-align:right"></th>
153 </tr>
154 </thead>
155 <tbody>
156 <?php foreach ( $notification_emails as $type => $name ) : ?>
157 <?php
158 $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
159 $default = self::get_default_emails_fields( $type, '', true );
160 $options = array_merge( $default, $options );
161
162 $email_description = self::get_settings_desc( $type );
163 ?>
164 <tr>
165 <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>
166 <td><a href="admin.php?page=SettingsEmail&edit-email=<?php echo 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>
167 <td><?php echo esc_html( $email_description ); ?></td>
168 <td><?php echo esc_html( $options['recipients'] ); ?></td>
169 <td style="text-align:right"><a href="admin.php?page=SettingsEmail&edit-email=<?php echo 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>
170 </tr>
171 <?php endforeach; ?>
172 </tbody>
173 <tfoot>
174 <tr>
175 <th class="collapsing"><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
176 <th><?php esc_html_e( 'Email', 'mainwp' ); ?></th>
177 <th><?php esc_html_e( 'Description', 'mainwp' ); ?></th>
178 <th><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></th>
179 <th></th>
180 </tr>
181 </tfoot>
182 </table>
183 <?php
184 /**
185 * Action: mainwp_settings_email_settings
186 *
187 * Fires after the default email settings.
188 *
189 * @since 4.1
190 */
191 do_action( 'mainwp_settings_email_settings' );
192 ?>
193 <script type="text/javascript">
194 jQuery( document ).ready( function() {
195 jQuery( '#mainwp-emails-settings-table' ).DataTable( {
196 "stateSave": true,
197 "paging": false,
198 "ordering": true,
199 "columnDefs": [ { "orderable": false, "targets": [ 0, 3 ] } ],
200 "order": [ [ 2, "asc" ] ]
201 } );
202 } );
203 </script>
204 </div>
205 <?php
206 }
207
208 /**
209 * Render email settings page.
210 *
211 * Credits.
212 *
213 * Plugin-Name: WooCommerce.
214 * Plugin URI: https://woocommerce.com/.
215 * Author: Automattic.
216 * Author URI: https://woocommerce.com.
217 * License: GPLv3 or later.
218 *
219 * @param string $type Email notification type.
220 * @param bool $updated_templ True if page loaded after update, false if not.
221 */
222 public function render_edit_settings( $type, $updated_templ ) {
223
224 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
225 mainwp_do_not_have_permissions( __( 'manage dashboard settings', 'mainwp' ) );
226 return;
227 }
228
229 $emails_settings = get_option( 'mainwp_settings_notification_emails' );
230 if ( ! is_array( $emails_settings ) ) {
231 $emails_settings = array();
232 }
233
234 // to fix incorrect field name.
235 if ( isset( $emails_settings['daily_digets'] ) ) {
236 $emails_settings['daily_digest'] = $emails_settings['daily_digets'];
237 }
238
239 // to fix incorrect field name.
240 if ( isset( $emails_settings['daily_digets'] ) ) {
241 $emails_settings['daily_digest'] = $emails_settings['daily_digets'];
242 unset( $emails_settings['daily_digets'] );
243 }
244
245 $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
246
247 $default = self::get_default_emails_fields( $type, '', true );
248 $options = array_merge( $default, $options );
249
250 $title = self::get_notification_types( $type );
251
252 $email_description = self::get_settings_desc( $type );
253
254 ?>
255 <div id="mainwp-emails-settings" class="ui segment">
256 <?php self::render_update_template_message( $updated_templ ); ?>
257 <div class="ui form">
258 <form method="POST" action="admin.php?page=SettingsEmail">
259 <input type="hidden" name="wp_nonce" value="<?php echo wp_create_nonce( 'SettingsEmail' ); ?>" />
260 <input type="hidden" name="mainwp_setting_emails_type" value="<?php echo esc_html( $type ); ?>" />
261 <div class="ui info message"><?php _e( '<a href="https://mainwp.com/extension/boilerplate/" target="_blank">Boilerplate</a> and <a href="https://mainwp.com/extension/pro-reports/" target="_blank">Reports</a> extensions tokens are supported in the email settings and templates if extensions are in use.', 'mainwp' ); ?></div>
262 <h3 class="ui header"><?php echo $title; ?></h3>
263 <div class="sub header"><?php echo $email_description; ?></h3></div>
264 <div class="ui divider"></div>
265 <div class="ui grid field">
266 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable', 'mainwp' ); ?></label>
267 <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">
268 <input type="checkbox" name="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][disable]" id="mainwp_settingEmails[<?php echo esc_html( $type ); ?>][disable]" <?php echo ( 0 == $options['disable'] ) ? 'checked="true"' : ''; ?>/>
269 </div>
270 </div>
271 <div class="ui grid field">
272 <label class="six wide column middle aligned"><?php esc_html_e( 'Recipient(s)', 'mainwp' ); ?></label>
273 <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">
274 <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'] ); ?>"/>
275 </div>
276 </div>
277 <div class="ui grid field">
278 <label class="six wide column middle aligned"><?php esc_html_e( 'Subject', 'mainwp' ); ?></label>
279 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enter the email subject.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
280 <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'] ); ?>"/>
281 </div>
282 </div>
283 <div class="ui grid field">
284 <label class="six wide column middle aligned"><?php esc_html_e( 'Email heading', 'mainwp' ); ?></label>
285 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enter the email heading.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
286 <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'] ); ?>"/>
287 </div>
288 </div>
289 <div class="ui grid field" >
290 <label class="six wide column middle aligned"><?php esc_html_e( 'HTML template', 'mainwp' ); ?></label>
291 <div class="ui ten wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
292 <?php
293 $templ = MainWP_Notification_Template::get_template_name_by_notification_type( $type );
294 $overrided = MainWP_Notification_Template::instance()->is_overrided_template( $type );
295 echo $overrided ? esc_html__( 'This template has been overridden and can be found in:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . $templ . '</code>' : esc_html__( 'To override and edit this email template copy:', 'mainwp' ) . ' <code>mainwp/templates/' . $templ . '</code> ' . esc_html__( 'to the folder:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . $templ . '</code>';
296 ?>
297 </div>
298 </div>
299 <div class="ui grid field" >
300 <label class="six wide column middle aligned"></label>
301 <div class="ui ten wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
302 <?php
303 if ( $overrided ) {
304 ?>
305 <a href="<?php echo 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( 'Delete Template', 'mainwp' ); ?></a>
306 <?php
307 } else {
308 ?>
309 <a href="<?php echo 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>
310 <?php
311 }
312 ?>
313 <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>
314 </div>
315 </div>
316 <div class="ui divider"></div>
317 <a href="admin.php?page=SettingsEmail" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
318 <input type="submit" name="submit" id="submit" class="ui green big button right floated" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
319 <div style="clear:both"></div>
320 </form>
321 </div>
322 </div>
323 <?php MainWP_Manage_Sites_View::render_edit_template( $type ); ?>
324 <?php
325 }
326
327
328 /**
329 * Get email settings description.
330 *
331 * @param string $type Email notification type.
332 *
333 * @return string $email_description Email settings Description.
334 */
335 public static function get_settings_desc( $type ) {
336 $email_description = '';
337 if ( 'daily_digest' === $type ) {
338 $email_description = esc_html__( 'Daily notification about available updates and disconnected sites.', 'mainwp' );
339 } elseif ( 'uptime' === $type ) {
340 $email_description = esc_html__( 'Alert if any of your websites is down.', 'mainwp' );
341 } elseif ( 'site_health' === $type ) {
342 $email_description = esc_html__( 'Alert if any of your websites site health goes under the threshold.', 'mainwp' );
343 } elseif ( 'http_check' === $type ) {
344 $email_description = esc_html__( 'Alert if any of your websites return unexpected HTTP status after running updates.', 'mainwp' );
345 }
346 return $email_description;
347 }
348
349 /**
350 * Render the notification after the update process.
351 *
352 * @param int $updated Update code (copied, saved or deleted).
353 */
354 public static function render_update_template_message( $updated ) {
355 ?>
356 <?php if ( 1 == $updated ) : ?>
357 <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Custom email template deleted successfully.', 'mainwp' ); ?></div>
358 <?php endif; ?>
359 <?php if ( 2 == $updated ) : ?>
360 <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Email template copied successfully.', 'mainwp' ); ?></div>
361 <?php endif; ?>
362 <?php if ( 3 == $updated ) : ?>
363 <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Email template updated successfully.', 'mainwp' ); ?></div>
364 <?php endif; ?>
365 <?php
366 }
367
368 /**
369 * Get email notification types.
370 *
371 * @param string $type Email notification type.
372 *
373 * @return mixed Notification types.
374 */
375 public static function get_notification_types( $type = '' ) {
376 $types = array(
377 'daily_digest' => __( 'Daily Digest Email', 'mainwp' ),
378 'uptime' => __( 'Basic Uptime Monitoring Email', 'mainwp' ),
379 'site_health' => __( 'Site Health Monitoring Email', 'mainwp' ),
380 );
381
382 $enable_http_check = get_option( 'mainwp_check_http_response', 0 );
383
384 if ( $enable_http_check ) {
385 $types['http_check'] = __( 'After Updates HTTP Check Email', 'mainwp' );
386 }
387
388 if ( empty( $type ) ) {
389 return $types;
390 } else {
391 return ( isset( $types[ $type ] ) ) ? $types[ $type ] : false;
392 }
393 }
394
395 /**
396 * Get general email notifications settings.
397 *
398 * @param string $type Email type.
399 *
400 * @see function get_notification_types()
401 *
402 * @return array An array containing the email settings.
403 */
404 public static function get_general_email_settings( $type ) {
405 $settings = get_option( 'mainwp_settings_notification_emails', array() );
406 if ( ! is_array( $settings ) ) {
407 $settings = array();
408 }
409
410 // to fix incorrect field name.
411 if ( isset( $settings['daily_digets'] ) ) {
412 $settings['daily_digest'] = $settings['daily_digets'];
413 unset( $settings['daily_digets'] );
414 }
415
416 $options = isset( $settings[ $type ] ) ? $settings[ $type ] : array();
417 $default = self::get_default_emails_fields( $type, '', true );
418 return array_merge( $default, $options );
419 }
420
421 /**
422 * Get email settings for a single site.
423 *
424 * @param string $type Email type.
425 * @param object $website Object containing the child site information.
426 *
427 * @return array An array containing the email settings.
428 */
429 public static function get_site_email_settings( $type, $website ) {
430 if ( empty( $website ) || ! property_exists( $website, 'settings_notification_emails' ) ) {
431 return array( 'disable' => 1 );
432 }
433 $settings = json_decode( $website->settings_notification_emails, true );
434 if ( ! is_array( $settings ) ) {
435 $settings = array();
436 }
437
438 // to fix incorrect field name.
439 if ( isset( $settings['daily_digets'] ) ) {
440 $settings['daily_digest'] = $settings['daily_digets'];
441 unset( $settings['daily_digets'] );
442 }
443
444 $options = isset( $settings[ $type ] ) ? $settings[ $type ] : array();
445 $default = self::get_default_emails_fields( $type );
446 $options = array_merge( $default, $options );
447
448 if ( preg_match( '/\[[^\]]+\]/is', $options['subject'] . $options['heading'], $matches ) ) {
449 $tokens_values = MainWP_System_Utility::get_tokens_site_values( $website );
450 $options['subject'] = MainWP_System_Utility::replace_tokens_values( $options['subject'], $tokens_values );
451 $options['heading'] = MainWP_System_Utility::replace_tokens_values( $options['heading'], $tokens_values );
452 }
453
454 if ( preg_match( '/\[[^\]]+\]/is', $options['recipients'] . $options['subject'] . $options['heading'], $matches ) ) {
455 // support boilerplate and reports tokens.
456 $fields = array( 'recipients', 'subject', 'heading' );
457 $options = self::replace_tokens_for_settings( $options, $fields, $website );
458 }
459
460 return $options;
461 }
462
463 /**
464 * Get default email notifications values.
465 *
466 * @param string $type Email type.
467 * @param string $field Field name.
468 * @param bool $general General or individual site settings.
469 *
470 * @return string Email field settings value.
471 */
472 public static function get_default_emails_fields( $type, $field = '', $general = false ) {
473
474 $important_noti = get_option( 'mainwp_setup_important_notification' );
475 if ( false === $important_noti ) {
476 $important_noti = get_option( 'mwp_setup_importantNotification' ); // going to outdated.
477 }
478
479 $recipients = MainWP_System_Utility::get_notification_email();
480 $disable = $general && $important_noti ? 0 : 1;
481
482 $default_fields = array(
483 'daily_digest' => array(
484 'disable' => $disable,
485 'recipients' => $recipients,
486 'subject' => $general ? 'Daily Digest' : '[site.name] Daily Digest',
487 'heading' => $general ? 'Daily Digest' : '[site.name] Daily Digest',
488 ),
489 'uptime' => array(
490 'disable' => $disable,
491 'recipients' => $recipients,
492 'subject' => $general ? 'Uptime Monitoring' : '[site.name] Uptime Monitoring',
493 'heading' => $general ? 'Uptime Monitoring' : '[site.name] Uptime Monitoring',
494 ),
495 'site_health' => array(
496 'disable' => $disable,
497 'recipients' => $recipients,
498 'subject' => $general ? 'Site Health Monitoring' : '[site.name] Site Health Monitoring',
499 'heading' => $general ? 'Site Health Monitoring' : '[site.name] Site Health Monitoring',
500 ),
501 'http_check' => array(
502 'disable' => $disable,
503 'recipients' => $recipients,
504 'subject' => 'HTTP response check',
505 'heading' => 'Sites Check',
506 ),
507 );
508
509 if ( ! empty( $type ) && ! empty( $field ) ) {
510 return isset( $default_fields[ $type ] ) && isset( $default_fields[ $type ][ $field ] ) ? $default_fields[ $type ][ $field ] : '';
511 }
512
513 if ( ! empty( $type ) && empty( $field ) ) {
514 return isset( $default_fields[ $type ] ) ? $default_fields[ $type ] : false;
515 }
516
517 return false;
518 }
519
520 /**
521 * Replace site tokens for settings.
522 *
523 * @param array $options array of fields to find and replace tokens.
524 * @param array $fields fields names to find.
525 * @param object $website The website.
526 *
527 * @return array $options array of fields.
528 */
529 public static function replace_tokens_for_settings( $options, $fields = array(), $website ) {
530
531 /**
532 * Filter: mainwp_boilerplate_get_tokens
533 *
534 * Enables and filters the Boilerplate extension tokens.
535 *
536 * @param object $website Object containing the child site data.
537 *
538 * @since 4.1
539 */
540 $boilerplate_tokens = apply_filters( 'mainwp_boilerplate_get_tokens', false, $website );
541
542 if ( is_array( $boilerplate_tokens ) ) {
543 foreach ( $fields as $field ) {
544 if ( isset( $options[ $field ] ) ) {
545 $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $boilerplate_tokens );
546 }
547 }
548 }
549
550 /**
551 * Filter: mainwp_pro_reports_get_site_tokens
552 *
553 * Enables and filters the Pro Reports extension tokens.
554 *
555 * @param object $website Object containing the child site data.
556 *
557 * @since 4.1
558 */
559 $report_tokens = apply_filters( 'mainwp_pro_reports_get_site_tokens', false, $website->id );
560
561 if ( is_array( $report_tokens ) ) {
562 foreach ( $fields as $field ) {
563 if ( isset( $options[ $field ] ) ) {
564 $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $report_tokens );
565 }
566 }
567 }
568
569 /**
570 * Filter: mainwp_client_report_get_site_tokens
571 *
572 * Enables and filters the Client Reports extension tokens.
573 *
574 * @param object $website Object containing the child site data.
575 *
576 * @since 4.1
577 */
578 $client_report_tokens = apply_filters( 'mainwp_client_report_get_site_tokens', false, $website->id );
579 if ( is_array( $client_report_tokens ) ) {
580 foreach ( $fields as $field ) {
581 if ( isset( $options[ $field ] ) ) {
582 $options[ $field ] = MainWP_System_Utility::replace_tokens_values( $options[ $field ], $client_report_tokens );
583 }
584 }
585 }
586
587 return $options;
588 }
589
590 /**
591 * Replace site tokens for content.
592 *
593 * @param string $content content to find and replace tokens.
594 * @param object $website The website.
595 *
596 * @return string $content after replaced tokens.
597 */
598 public static function replace_tokens_for_content( $content, $website ) {
599
600 $tokens_values = MainWP_System_Utility::get_tokens_site_values( $website );
601
602 $content = MainWP_System_Utility::replace_tokens_values( $content, $tokens_values );
603
604 // if tokens existed.
605 if ( preg_match( '/\[[^\]]+\]/is', $content, $matches ) ) {
606
607 /** This filter is documented in ../class/class-mainwp-notification-settings.php */
608 $boilerplate_tokens = apply_filters( 'mainwp_boilerplate_get_tokens', false, $website );
609
610 if ( is_array( $boilerplate_tokens ) ) {
611 $content = MainWP_System_Utility::replace_tokens_values( $content, $boilerplate_tokens );
612 }
613
614 /** This filter is documented in ../class/class-mainwp-notification-settings.php */
615 $report_tokens = apply_filters( 'mainwp_pro_reports_get_site_tokens', false, $website->id );
616
617 if ( is_array( $report_tokens ) ) {
618 $content = MainWP_System_Utility::replace_tokens_values( $content, $report_tokens );
619 }
620
621 /** This filter is documented in ../class/class-mainwp-notification-settings.php */
622 $client_report_tokens = apply_filters( 'mainwp_client_report_get_site_tokens', false, $website->id );
623
624 if ( is_array( $client_report_tokens ) ) {
625 $content = MainWP_System_Utility::replace_tokens_values( $content, $client_report_tokens );
626 }
627 }
628
629 return $content;
630 }
631 }
632