PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0
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 / pages / page-mainwp-settings.php

page-mainwp-settings.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0, at pages/page-mainwp-settings.php

1,660 lines 85.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Settings page
4 *
5 * This Class handles building/Managing the
6 * Settings MainWP DashboardPage & all SubPages.
7 *
8 * @package MainWP/Settings
9 */
10
11 namespace MainWP\Dashboard;
12
13 /**
14 * Class MainWP_Settings
15 *
16 * @package MainWP\Dashboard
17 */
18 class MainWP_Settings {
19
20 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
21
22 /**
23 * Protected static variable to hold the single instance of the class.
24 *
25 * @var mixed Default null
26 */
27 protected static $instance = null;
28
29 /**
30 * Public static varable to hold Subpages information.
31 *
32 * @var array $subPages
33 */
34 public static $subPages;
35
36 /**
37 * Get Class Name
38 *
39 * @return __CLASS__
40 */
41 public static function get_class_name() {
42 return __CLASS__;
43 }
44
45 /**
46 * Return the single instance of the class.
47 *
48 * @return mixed $instance The single instance of the class.
49 */
50 public static function get_instance() {
51 if ( is_null( self::$instance ) ) {
52 self::$instance = new self();
53 }
54 return self::$instance;
55 }
56
57 /** Instantiate Hooks for the Settings Page. */
58 public static function init() {
59 /**
60 * This hook allows you to render the Settings page header via the 'mainwp_pageheader_settings' action.
61 *
62 * This hook is normally used in the same context of 'mainwp_getsubpages_settings'
63 *
64 * @see \MainWP_Settings::render_header
65 */
66 add_action( 'mainwp-pageheader-settings', array( self::get_class_name(), 'render_header' ) ); // deprecated, use mainwp_pageheader_settings.
67
68 add_action( 'mainwp_pageheader_settings', array( self::get_class_name(), 'render_header' ) );
69
70 /**
71 * This hook allows you to render the Settings page footer via the 'mainwp-pagefooter-settings' action.
72 *
73 * This hook is normally used in the same context of 'mainwp-getsubpages-settings'
74 *
75 * @see \MainWP_Settings::render_footer
76 */
77 add_action( 'mainwp-pagefooter-settings', array( self::get_class_name(), 'render_footer' ) ); // deprecated, use mainwp_pagefooter_settings.
78
79 add_action( 'mainwp_pagefooter_settings', array( self::get_class_name(), 'render_footer' ) );
80
81 add_action( 'admin_init', array( self::get_class_name(), 'admin_init' ) );
82
83 add_action( 'mainwp_help_sidebar_content', array( self::get_class_name(), 'mainwp_help_content' ) );
84 }
85
86 /** Run the export_sites method that exports the Child Sites .csv file */
87 public static function admin_init() {
88 self::export_sites();
89 if ( isset( $_GET['clearActivationData'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'clear_activation_data' ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
90 delete_option( 'mainwp_extensions_api_username' );
91 delete_option( 'mainwp_extensions_api_password' );
92 delete_option( 'mainwp_extensions_api_save_login' );
93 delete_option( 'mainwp_extensions_plan_info' );
94 MainWP_Keys_Manager::instance()->update_key_value( 'mainwp_extensions_master_api_key', false );
95
96 $new_extensions = array();
97 $extensions = get_option( 'mainwp_extensions', array() );
98
99 if ( is_array( $extensions ) ) {
100 foreach ( $extensions as $ext ) {
101 if ( isset( $ext['api'] ) && isset( $ext['apiManager'] ) && ! empty( $ext['apiManager'] ) ) {
102 if ( isset( $ext['api_key'] ) ) {
103 $ext['api_key'] = '';
104 }
105 if ( isset( $ext['activation_email'] ) ) {
106 $ext['activation_email'] = '';
107 }
108 if ( isset( $ext['activated_key'] ) ) {
109 $ext['activated_key'] = 'Deactivated';
110 }
111
112 $act_info = MainWP_Api_Manager::instance()->get_activation_info( $ext['api'] );
113 if ( isset( $act_info['api_key'] ) ) {
114 $act_info['api_key'] = '';
115 }
116 if ( isset( $act_info['activation_email'] ) ) {
117 $act_info['activation_email'] = '';
118 }
119 if ( isset( $act_info['activated_key'] ) ) {
120 $act_info['activated_key'] = 'Deactivated';
121 }
122 MainWP_Api_Manager::instance()->set_activation_info( $ext['api'], $act_info );
123 }
124 $new_extensions[] = $ext;
125 }
126 }
127
128 MainWP_Utility::update_option( 'mainwp_extensions', $new_extensions );
129 update_option( 'mainwp_extensions_all_activation_cached', '' );
130 wp_safe_redirect( esc_url( admin_url( 'admin.php?page=MainWPTools' ) ) );
131 die();
132 }
133 }
134
135 /**
136 * Instantiate the Settings Menu.
137 *
138 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
139 */
140 public static function init_menu() {
141 add_submenu_page(
142 'mainwp_tab',
143 __( 'Settings Global options', 'mainwp' ),
144 ' <span id="mainwp-Settings">' . esc_html__( 'Settings', 'mainwp' ) . '</span>',
145 'read',
146 'Settings',
147 array(
148 self::get_class_name(),
149 'render',
150 )
151 );
152
153 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) {
154 add_submenu_page(
155 'mainwp_tab',
156 __( 'Tools', 'mainwp' ),
157 ' <div class="mainwp-hidden">' . esc_html__( 'Tools', 'mainwp' ) . '</div>',
158 'read',
159 'MainWPTools',
160 array(
161 self::get_class_name(),
162 'render_mainwp_tools',
163 )
164 );
165 }
166
167 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) {
168 add_submenu_page(
169 'mainwp_tab',
170 __( 'Advanced Options', 'mainwp' ),
171 ' <div class="mainwp-hidden">' . esc_html__( 'Advanced Options', 'mainwp' ) . '</div>',
172 'read',
173 'SettingsAdvanced',
174 array(
175 self::get_class_name(),
176 'render_advanced',
177 )
178 );
179 }
180
181 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) {
182 add_submenu_page(
183 'mainwp_tab',
184 __( 'Email Settings', 'mainwp' ),
185 ' <div class="mainwp-hidden">' . esc_html__( 'Email Settings', 'mainwp' ) . '</div>',
186 'read',
187 'SettingsEmail',
188 array(
189 self::get_class_name(),
190 'render_email_settings',
191 )
192 );
193 }
194
195 /**
196 * Settings Subpages
197 *
198 * Filters subpages for the Settings page.
199 *
200 * @since Unknown
201 */
202 $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-settings', array( array() ), '4.0.7.2', 'mainwp_getsubpages_settings' ); // @deprecated Use 'mainwp_getsubpages_settings' instead.
203 self::$subPages = apply_filters( 'mainwp_getsubpages_settings', $sub_pages );
204
205 if ( isset( self::$subPages ) && is_array( self::$subPages ) ) {
206 foreach ( self::$subPages as $subPage ) {
207 if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
208 continue;
209 }
210 add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'Settings' . $subPage['slug'], $subPage['callback'] );
211 }
212 }
213 }
214
215 /**
216 * Instantiate Settings SubPages Menu.
217 *
218 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
219 */
220 public static function init_subpages_menu() {
221 ?>
222 <div id="menu-mainwp-Settings" class="mainwp-submenu-wrapper">
223 <div class="wp-submenu sub-open" style="">
224 <div class="mainwp_boxout">
225 <div class="mainwp_boxoutin"></div>
226 <a href="<?php echo esc_url( admin_url( 'admin.php?page=Settings' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></a>
227 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) { ?>
228 <a href="<?php echo esc_url( admin_url( 'admin.php?page=SettingsAdvanced' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Advanced Settings', 'mainwp' ); ?></a>
229 <?php } ?>
230 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) { ?>
231 <a href="<?php echo esc_url( admin_url( 'admin.php?page=SettingsEmail' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Email Settings', 'mainwp' ); ?></a>
232 <?php } ?>
233 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) { ?>
234 <a href="<?php echo esc_url( admin_url( 'admin.php?page=MainWPTools' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Tools', 'mainwp' ); ?></a>
235 <?php } ?>
236 <?php
237 if ( isset( self::$subPages ) && is_array( self::$subPages ) && ( count( self::$subPages ) > 0 ) ) {
238 foreach ( self::$subPages as $subPage ) {
239 if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
240 continue;
241 }
242 ?>
243 <a href="<?php echo esc_url( admin_url( 'admin.php?page=Settings' . $subPage['slug'] ) ); ?>" class="mainwp-submenu"><?php echo esc_html( $subPage['title'] ); ?></a>
244 <?php
245 }
246 }
247 ?>
248 </div>
249 </div>
250 </div>
251 <?php
252 }
253
254 /**
255 * Instantiate left menu
256 *
257 * Settings Page & SubPage link data.
258 *
259 * @param array $subPages SubPages Array.
260 *
261 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
262 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
263 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
264 */
265 public static function init_left_menu( $subPages = array() ) {
266 MainWP_Menu::add_left_menu(
267 array(
268 'title' => esc_html__( 'Settings', 'mainwp' ),
269 'parent_key' => 'mainwp_tab',
270 'slug' => 'Settings',
271 'href' => 'admin.php?page=Settings',
272 'icon' => '<i class="cog icon"></i>',
273 ),
274 0
275 );
276
277 $init_sub_subleftmenu = array(
278 array(
279 'title' => esc_html__( 'General Settings', 'mainwp' ),
280 'parent_key' => 'Settings',
281 'href' => 'admin.php?page=Settings',
282 'slug' => 'Settings',
283 'right' => '',
284 ),
285 array(
286 'title' => esc_html__( 'Advanced Settings', 'mainwp' ),
287 'parent_key' => 'Settings',
288 'href' => 'admin.php?page=SettingsAdvanced',
289 'slug' => 'SettingsAdvanced',
290 'right' => '',
291 ),
292 array(
293 'title' => esc_html__( 'Email Settings', 'mainwp' ),
294 'parent_key' => 'Settings',
295 'href' => 'admin.php?page=SettingsEmail',
296 'slug' => 'SettingsEmail',
297 'right' => '',
298 ),
299 array(
300 'title' => esc_html__( 'Tools', 'mainwp' ),
301 'parent_key' => 'Settings',
302 'href' => 'admin.php?page=MainWPTools',
303 'slug' => 'MainWPTools',
304 'right' => '',
305 ),
306 );
307
308 MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'Settings', 'Settings' );
309 foreach ( $init_sub_subleftmenu as $item ) {
310 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
311 continue;
312 }
313
314 MainWP_Menu::add_left_menu( $item, 2 );
315 }
316 }
317
318 /**
319 * Render Page Header.
320 *
321 * @param string $shownPage The page slug shown at this moment.
322 *
323 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
324 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
325 * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation()
326 */
327 public static function render_header( $shownPage = '' ) {
328
329 $params = array(
330 'title' => esc_html__( 'MainWP Settings', 'mainwp' ),
331 );
332
333 MainWP_UI::render_top_header( $params );
334
335 $renderItems = array();
336
337 $renderItems[] = array(
338 'title' => esc_html__( 'General Settings', 'mainwp' ),
339 'href' => 'admin.php?page=Settings',
340 'active' => ( '' === $shownPage ) ? true : false,
341 );
342
343 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) {
344 $renderItems[] = array(
345 'title' => esc_html__( 'Advanced Settings', 'mainwp' ),
346 'href' => 'admin.php?page=SettingsAdvanced',
347 'active' => ( 'Advanced' === $shownPage ) ? true : false,
348 );
349 }
350
351 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) {
352 $renderItems[] = array(
353 'title' => esc_html__( 'Email Settings', 'mainwp' ),
354 'href' => 'admin.php?page=SettingsEmail',
355 'active' => ( 'Emails' === $shownPage ) ? true : false,
356 );
357 }
358
359 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) {
360 $renderItems[] = array(
361 'title' => esc_html__( 'Tools', 'mainwp' ),
362 'href' => 'admin.php?page=MainWPTools',
363 'active' => ( 'MainWPTools' === $shownPage ) ? true : false,
364 );
365 }
366
367 if ( isset( self::$subPages ) && is_array( self::$subPages ) ) {
368 foreach ( self::$subPages as $subPage ) {
369 if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
370 continue;
371 }
372 $item = array();
373 $item['title'] = $subPage['title'];
374 $item['href'] = 'admin.php?page=Settings' . $subPage['slug'];
375 $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false;
376
377 if ( isset( $subPage['class'] ) ) {
378 $item['class'] = $subPage['class'];
379 }
380 $renderItems[] = $item;
381 }
382 }
383
384 MainWP_UI::render_page_navigation( $renderItems );
385 }
386
387 /**
388 * Close the HTML container.
389 */
390 public static function render_footer() {
391 echo '</div>';
392 }
393
394 /**
395 * Method handle_settings_post().
396 *
397 * This class handles the $_POST of Settings Options.
398 *
399 * @uses MainWP_DB::instance()
400 * @uses MainWP_Utility::update_option()
401 *
402 * @return boolean True|False Posts On True.
403 *
404 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
405 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
406 * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
407 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
408 */
409 public static function handle_settings_post() {
410 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) {
411 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
412 $userExtension->pluginDir = '';
413
414 MainWP_DB_Common::instance()->update_user_extension( $userExtension );
415 if ( MainWP_System_Utility::is_admin() ) {
416
417 /**
418 * Action: mainwp_before_save_general_settings
419 *
420 * Fires before general settings save.
421 *
422 * @since 4.1
423 */
424 do_action( 'mainwp_before_save_general_settings', $_POST );
425
426 $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) );
427 MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val );
428 $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) );
429 MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val );
430 $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) );
431 MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val );
432 $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 );
433 MainWP_Utility::update_option( 'mainwp_show_language_updates', $val );
434 $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) );
435 MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val );
436 $val = ( ! isset( $_POST['mainwp_backup_before_upgrade'] ) ? 0 : 1 );
437 MainWP_Utility::update_option( 'mainwp_backup_before_upgrade', $val );
438 $val = ( ! isset( $_POST['mainwp_backup_before_upgrade_days'] ) ? 7 : intval( $_POST['mainwp_backup_before_upgrade_days'] ) );
439 MainWP_Utility::update_option( 'mainwp_backup_before_upgrade_days', $val );
440
441 if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) {
442 MainWP_Utility::update_option( 'mainwp_maximumComments', isset( $_POST['mainwp_maximumComments'] ) ? intval( $_POST['mainwp_maximumComments'] ) : 50 );
443 }
444
445 $current_timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
446 $new_timeDailyUpdate = isset( $_POST['mainwp_timeDailyUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_timeDailyUpdate'] ) ) : '';
447
448 if ( $current_timeDailyUpdate !== $new_timeDailyUpdate ) {
449 MainWP_Utility::update_option( 'mainwp_timeDailyUpdate', $new_timeDailyUpdate );
450 }
451
452 $new_freq = ( isset( $_POST['mainwp_frequencyDailyUpdate'] ) ? intval( $_POST['mainwp_frequencyDailyUpdate'] ) : 2 );
453 MainWP_Utility::update_option( 'mainwp_frequencyDailyUpdate', $new_freq );
454
455 $new_delay = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 );
456 MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $new_delay );
457
458 $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 );
459 $user = wp_get_current_user();
460 if ( $user ) {
461 update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
462 }
463
464 MainWP_Utility::update_option( 'mainwp_numberdays_Outdate_Plugin_Theme', ! empty( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) ? intval( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) : 365 );
465 $ignore_http = isset( $_POST['mainwp_ignore_http_response_status'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_ignore_http_response_status'] ) ) : '';
466 MainWP_Utility::update_option( 'mainwp_ignore_HTTP_response_status', $ignore_http );
467
468 $check_http_response = ( isset( $_POST['mainwp_check_http_response'] ) ? 1 : 0 );
469 MainWP_Utility::update_option( 'mainwp_check_http_response', $check_http_response );
470
471 $actions_notification_enable = ( isset( $_POST['mainwp_site_actions_notification_enable'] ) ? 1 : 0 );
472 MainWP_Utility::update_option( 'mainwp_site_actions_notification_enable', $actions_notification_enable );
473
474 //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
475 // Handle custom date/time formats.
476 if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] )
477 && '\c\u\s\t\o\m' === wp_unslash( $_POST['date_format'] )
478 ) {
479 $_POST['date_format'] = wp_unslash( $_POST['date_format_custom'] );
480 }
481
482 if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] )
483 && '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] )
484 ) {
485 $_POST['time_format'] = wp_unslash( $_POST['time_format_custom'] );
486 }
487
488 if ( isset( $_POST['timezone_string'] ) ) {
489 // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
490 if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', wp_unslash( $_POST['timezone_string'] ) ) ) {
491 $_POST['gmt_offset'] = wp_unslash( $_POST['timezone_string'] );
492 $_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', wp_unslash( $_POST['gmt_offset'] ) ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
493 $_POST['timezone_string'] = '';
494 }
495
496 $options = array(
497 'gmt_offset',
498 'date_format',
499 'time_format',
500 'timezone_string',
501 );
502
503 foreach ( $options as $option ) {
504 $value = null;
505 if ( isset( $_POST[ $option ] ) ) {
506 $value = wp_unslash( $_POST[ $option ] );
507 if ( ! is_array( $value ) ) {
508 $value = trim( $value );
509 }
510 }
511 update_option( $option, $value );
512 }
513 }
514 //phpcs:enable
515
516 MainWP_Utility::update_option( 'mainwp_use_favicon', 1 );
517
518 /**
519 * Action: mainwp_after_save_general_settings
520 *
521 * Fires after save general settings.
522 *
523 * @since 4.1
524 */
525 do_action( 'mainwp_after_save_general_settings', $_POST );
526 }
527
528 return true;
529 }
530
531 return false;
532 }
533
534 /**
535 * Render the MainWP Settings Page.
536 *
537 * @uses \MainWP\Dashboard\MainWP_Monitoring_View
538 * @uses \MainWP\Dashboard\MainWP_Manage_Backups::render_settings()
539 * @uses \MainWP\Dashboard\MainWP_Utility::get_http_codes()
540 */
541 public static function render() { //phpcs:ignore -- complex method.
542 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
543 mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
544 return;
545 }
546
547 self::render_header( '' );
548 ?>
549 <div id="mainwp-general-settings" class="ui segment">
550 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-general-settings-info-message' ) ) : ?>
551 <div class="ui info message">
552 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-general-settings-info-message"></i>
553 <?php printf( esc_html__( 'Manage MainWP general settings. For additional help, review this %1$shelp document%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?>
554 </div>
555 <?php endif; ?>
556 <?php if ( isset( $_GET['message'] ) && 'saved' === $_GET['message'] ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
557 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
558 <?php endif; ?>
559 <div class="ui form">
560 <form method="POST" action="admin.php?page=Settings" id="mainwp-settings-page-form">
561 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
562 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'Settings' ) ); ?>" />
563 <?php
564 /**
565 * Action: mainwp_settings_form_top
566 *
567 * Fires at the top of settings form.
568 *
569 * @since 4.1
570 */
571 do_action( 'mainwp_settings_form_top' );
572 ?>
573 <h3 class="ui dividing header"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></h3>
574 <?php
575 $timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
576 $frequencyDailyUpdate = (int) get_option( 'mainwp_frequencyDailyUpdate', 2 );
577 $run_timestamp = MainWP_System_Cron_Jobs::get_timestamp_from_hh_mm( $timeDailyUpdate );
578 $delay_autoupdate = (int) get_option( 'mainwp_delay_autoupdate', 1 );
579
580 ?>
581 <div class="ui grid field">
582 <label class="six wide column middle aligned"><?php esc_html_e( 'Daily sync & update time', 'mainwp' ); ?></label>
583 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose a specific time to initiate the first daily synchronization and update process.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
584 <div class="time-selector">
585 <div class="ui input left icon">
586 <i class="clock icon"></i>
587 <input type="text" current-utc-datetime="<?php echo date( 'Y-m-d H:i:s' ); ?>" sync-time-local-datetime="<?php echo date( 'Y-m-d H:i:s', $run_timestamp ); ?>" local-datetime="<?php echo date( 'Y-m-d H:i:s', MainWP_Utility::get_timestamp() ); // phpcs:ignore -- to get local time. ?>" name="mainwp_timeDailyUpdate" id="mainwp_timeDailyUpdate" value="<?php echo esc_attr( $timeDailyUpdate ); ?>" />
588 </div>
589 </div>
590 <script type="text/javascript">
591 jQuery( document ).ready( function() {
592 jQuery( '.time-selector' ).calendar( {
593 type: 'time',
594 ampm: false,
595 formatter: {
596 time: 'H:mm',
597 cellTime: 'H:mm'
598 }
599 } );
600 } );
601 </script>
602 </div>
603 </div>
604 <div class="ui grid field">
605 <label class="six wide column middle aligned"><?php esc_html_e( 'Frequency of auto sync & updates', 'mainwp' ); ?></label>
606 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set the frequency for automatic synchronization and updates throughout the day.', 'mainwp' ); ?>" data-inverted="" data-position="top left" >
607 <select name="mainwp_frequencyDailyUpdate" id="mainwp_frequencyDailyUpdate" class="ui dropdown">
608 <option value="1" <?php echo ( 1 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Once per day', 'mainwp' ); ?></option>
609 <option value="2" <?php echo ( 2 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Twice per day', 'mainwp' ); ?></option>
610 <option value="3" <?php echo ( 3 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Three times per day', 'mainwp' ); ?></option>
611 <option value="4" <?php echo ( 4 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Four times per day', 'mainwp' ); ?></option>
612 <option value="5" <?php echo ( 5 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Five times per day', 'mainwp' ); ?></option>
613 <option value="6" <?php echo ( 6 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Six times per day', 'mainwp' ); ?></option>
614 <option value="7" <?php echo ( 7 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Seven times per day', 'mainwp' ); ?></option>
615 <option value="8" <?php echo ( 8 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Eight times per day', 'mainwp' ); ?></option>
616 <option value="9" <?php echo ( 9 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Nine times per day', 'mainwp' ); ?></option>
617 <option value="10" <?php echo ( 10 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Ten times per day', 'mainwp' ); ?></option>
618 <option value="11" <?php echo ( 11 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Eleven times per day', 'mainwp' ); ?></option>
619 <option value="12" <?php echo ( 12 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Twelve times per day', 'mainwp' ); ?></option>
620 </select>
621 </div>
622 </div>
623
624 <?php
625 self::render_timezone_settings();
626 self::render_datetime_settings();
627
628 $sidebarPosition = get_user_option( 'mainwp_sidebarPosition' );
629 if ( false === $sidebarPosition ) {
630 $sidebarPosition = 1;
631 }
632
633 ?>
634 <div class="ui grid field">
635 <label class="six wide column middle aligned"><?php esc_html_e( 'Sidebar position', 'mainwp' ); ?></label>
636 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Select if you want to show sidebar with option on left or right.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
637 <select name="mainwp_sidebarPosition" id="mainwp_sidebarPosition" class="ui dropdown">
638 <option value="1" <?php echo ( 1 === (int) $sidebarPosition ? 'selected' : '' ); ?>><?php esc_html_e( 'Right (default)', 'mainwp' ); ?></option>
639 <option value="0" <?php echo ( 0 === (int) $sidebarPosition ? 'selected' : '' ); ?>><?php esc_html_e( 'Left', 'mainwp' ); ?></option>
640 </select>
641 </div>
642 </div>
643 <?php MainWP_UI::render_screen_options(); ?>
644
645 <h3 class="ui dividing header"><?php esc_html_e( 'Updates Settings', 'mainwp' ); ?></h3>
646 <?php
647 $snAutomaticDailyUpdate = (int) get_option( 'mainwp_automaticDailyUpdate', 0 );
648 $snPluginAutomaticDailyUpdate = (int) get_option( 'mainwp_pluginAutomaticDailyUpdate', 0 );
649 $snThemeAutomaticDailyUpdate = (int) get_option( 'mainwp_themeAutomaticDailyUpdate', 0 );
650 $backup_before_upgrade = get_option( 'mainwp_backup_before_upgrade' );
651 $mainwp_backup_before_upgrade_days = get_option( 'mainwp_backup_before_upgrade_days' );
652 if ( empty( $mainwp_backup_before_upgrade_days ) || ! ctype_digit( $mainwp_backup_before_upgrade_days ) ) {
653 $mainwp_backup_before_upgrade_days = 7;
654 }
655
656 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
657
658 $update_time = self::get_websites_automatic_update_time();
659 $lastAutomaticUpdate = $update_time['last'];
660 $nextAutomaticUpdate = $update_time['next'];
661
662 $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
663 $primaryBackup = get_option( 'mainwp_primaryBackup' );
664 $disableUpdateConfirmations = (int) get_option( 'mainwp_disable_update_confirmations', 0 );
665
666 $http_error_codes = MainWP_Utility::get_http_codes();
667 ?>
668 <div class="ui grid field">
669 <label class="six wide column middle aligned"><?php esc_html_e( 'Plugin advanced automatic updates', 'mainwp' ); ?></label>
670 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic plugins updates. If enabled, MainWP will update only plugins that you have marked as Trusted.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
671 <select name="mainwp_pluginAutomaticDailyUpdate" id="mainwp_pluginAutomaticDailyUpdate" class="ui dropdown">
672 <option value="1" <?php echo ( 1 === $snPluginAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
673 <option value="0" <?php echo ( ( 0 === $snPluginAutomaticDailyUpdate ) || 2 === $snPluginAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
674 </select>
675 </div>
676 </div>
677 <div class="ui grid field">
678 <label class="six wide column middle aligned"><?php esc_html_e( 'Theme advanced automatic updates', 'mainwp' ); ?></label>
679 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic themes updates. If enabled, MainWP will update only themes that you have marked as Trusted.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
680 <select name="mainwp_themeAutomaticDailyUpdate" id="mainwp_themeAutomaticDailyUpdate" class="ui dropdown">
681 <option value="1" <?php echo ( 1 === $snThemeAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
682 <option value="0" <?php echo ( 0 === $snThemeAutomaticDailyUpdate || 2 === $snThemeAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
683 </select>
684 </div>
685 </div>
686 <div class="ui grid field">
687 <label class="six wide column middle aligned"><?php esc_html_e( 'WP Core advanced automatic updates', 'mainwp' ); ?></label>
688 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic WordPress core updates.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
689 <select name="mainwp_automaticDailyUpdate" id="mainwp_automaticDailyUpdate" class="ui dropdown">
690 <option value="1" <?php echo ( 1 === $snAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
691 <option value="0" <?php echo ( 0 === $snAutomaticDailyUpdate || 2 === (int) $snAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
692 </select>
693 </div>
694 </div>
695 <div class="ui grid field">
696 <label class="six wide column middle aligned"><?php esc_html_e( 'Advanced automatic updates delay', 'mainwp' ); ?></label>
697 <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'Set the number of days to delay automatic updates.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
698 <select name="mainwp_delay_autoupdate" id="mainwp_delay_autoupdate" class="ui dropdown">
699 <option value="0" <?php echo ( 0 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Delay off', 'mainwp' ); ?></option>
700 <option value="1" <?php echo ( 1 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '1 day', 'mainwp' ); ?></option>
701 <option value="2" <?php echo ( 2 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '2 days', 'mainwp' ); ?></option>
702 <option value="3" <?php echo ( 3 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '3 days', 'mainwp' ); ?></option>
703 <option value="4" <?php echo ( 4 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '4 days', 'mainwp' ); ?></option>
704 <option value="5" <?php echo ( 5 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '5 days', 'mainwp' ); ?></option>
705 <option value="6" <?php echo ( 6 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '6 days', 'mainwp' ); ?></option>
706 <option value="7" <?php echo ( 7 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '7 days', 'mainwp' ); ?></option>
707 <option value="14" <?php echo ( 14 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '14 days', 'mainwp' ); ?></option>
708 <option value="30" <?php echo ( 30 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '30 days', 'mainwp' ); ?></option>
709 </select>
710 </div>
711 </div>
712 <div class="ui grid field">
713 <label class="six wide column middle aligned"><?php esc_html_e( 'Show WordPress language updates', 'mainwp' ); ?></label>
714 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to manage Translation updates', 'mainwp' ); ?>" data-inverted="" data-position="top left">
715 <input type="checkbox" name="mainwp_show_language_updates" id="mainwp_show_language_updates" <?php echo ( 1 === (int) $mainwp_show_language_updates ? 'checked="true"' : '' ); ?>/>
716 </div>
717 </div>
718 <div class="ui grid field">
719 <label class="six wide column middle aligned"><?php esc_html_e( 'Update confirmations', 'mainwp' ); ?></label>
720 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Choose if you want to disable the popup confirmations when performing updates.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
721 <select name="mainwp_disable_update_confirmations" id="mainwp_disable_update_confirmations" class="ui dropdown">
722 <option value="0" <?php echo ( 0 === $disableUpdateConfirmations ? 'selected' : '' ); ?>><?php esc_html_e( 'Enable', 'mainwp' ); ?></option>
723 <option value="2" <?php echo ( 2 === $disableUpdateConfirmations ? 'selected' : '' ); ?>><?php esc_html_e( 'Disable', 'mainwp' ); ?></option>
724 <option value="1" <?php echo ( 1 === $disableUpdateConfirmations ? 'selected' : '' ); ?>><?php esc_html_e( 'Disable for single updates', 'mainwp' ); ?></option>
725 </select>
726 </div>
727 </div>
728 <div class="ui grid field">
729 <label class="six wide column middle aligned"><?php esc_html_e( 'Check site HTTP response after update', 'mainwp' ); ?></label>
730 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want your MainWP Dashboard to check child site header response after updates.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
731 <input type="checkbox" name="mainwp_check_http_response" id="mainwp_check_http_response" <?php echo ( ( 1 === (int) get_option( 'mainwp_check_http_response', 0 ) ) ? 'checked="true"' : '' ); ?>/>
732 </div>
733 </div>
734 <div class="ui grid field">
735 <label class="six wide column middle aligned"><?php esc_html_e( 'Ignored HTTP response statuses', 'mainwp' ); ?></label>
736 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Select response codes that you want your MainWP Dashboard to ignore.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
737 <div class="ui multiple selection dropdown" init-value="<?php echo esc_attr( ( get_option( 'mainwp_ignore_HTTP_response_status', '' ) ) ); ?>">
738 <input name="mainwp_ignore_http_response_status" type="hidden">
739 <i class="dropdown icon"></i>
740 <div class="default text"></div>
741 <div class="menu">
742 <?php
743 foreach ( $http_error_codes as $error_code => $label ) {
744 ?>
745 <div class="item" data-value="<?php echo esc_attr( $error_code ); ?>"><?php echo esc_html( $error_code . ' (' . $label . ')' ); ?></div>
746 <?php
747 }
748 ?>
749 </div>
750 </div>
751 </div>
752 </div>
753 <?php if ( ( ( $enableLegacyBackupFeature && empty( $primaryBackup ) ) || ( empty( $enableLegacyBackupFeature ) && ! empty( $primaryBackup ) ) ) ) { ?>
754 <div class="ui grid field mainwp-parent-toggle">
755 <label class="six wide column middle aligned"><?php esc_html_e( 'Require a backup before an update', 'mainwp' ); ?></label>
756 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will check if full backups exists before updating.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
757 <input type="checkbox" name="mainwp_backup_before_upgrade" id="mainwp_backup_before_upgrade" <?php echo ( 1 === (int) $backup_before_upgrade ? 'checked="true"' : '' ); ?>/>
758 </div>
759 </div>
760 <div class="ui grid field mainwp-child-field" <?php echo ( 1 === (int) $backup_before_upgrade ? '' : 'style="display:none"' ); ?> >
761 <label class="six wide column middle aligned"><?php esc_html_e( 'Days without of a full backup tolerance', 'mainwp' ); ?></label>
762 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set the number of days without of backup tolerance.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
763 <input type="text" name="mainwp_backup_before_upgrade_days" id="mainwp_backup_before_upgrade_days" value="<?php echo esc_attr( $mainwp_backup_before_upgrade_days ); ?>" />
764 </div>
765 </div>
766 <?php } ?>
767
768 <div class="ui grid field">
769 <label class="six wide column middle aligned"><?php esc_html_e( 'Abandoned plugins/themes tolerance', 'mainwp' ); ?></label>
770 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set how many days without an update before plugin or theme will be considered as abandoned.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
771 <input type="text" name="mainwp_numberdays_Outdate_Plugin_Theme" id="mainwp_numberdays_Outdate_Plugin_Theme" value="<?php echo ( ( false === get_option( 'mainwp_numberdays_Outdate_Plugin_Theme' ) ) ? 365 : intval( get_option( 'mainwp_numberdays_Outdate_Plugin_Theme' ) ) ); ?>"/>
772 </div>
773 </div>
774 <?php MainWP_Monitoring_View::render_settings(); ?>
775 <?php MainWP_Manage_Backups::render_settings(); ?>
776 <?php
777 /**
778 * Action: mainwp_settings_form_bottom
779 *
780 * Fires at the bottom of settings form.
781 *
782 * @since 4.1
783 */
784 do_action( 'mainwp_settings_form_bottom' );
785 ?>
786 <div class="ui divider"></div>
787 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
788 <div style="clear:both"></div>
789 </form>
790 </div>
791 </div>
792 <?php
793 self::render_footer( '' );
794 }
795
796 /**
797 * Render Timezone settings.
798 */
799 public static function render_timezone_settings() {
800
801 $current_offset = get_option( 'gmt_offset' );
802 $tzstring = get_option( 'timezone_string' );
803 $check_zone_info = true;
804
805 // Remove old Etc mappings. Fallback to gmt_offset.
806 if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
807 $tzstring = '';
808 }
809
810 if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists.
811 $check_zone_info = false;
812 if ( empty( $current_offset ) ) {
813 $tzstring = 'UTC+0';
814 } elseif ( $current_offset < 0 ) {
815 $tzstring = 'UTC' . $current_offset;
816 } else {
817 $tzstring = 'UTC+' . $current_offset;
818 }
819 }
820
821 $timezone_format = _x( 'Y-m-d H:i:s', 'timezone date format' );
822
823 ?>
824 <div class="ui grid field">
825 <label class="six wide column middle aligned"><?php esc_html_e( 'Timezone', 'mainwp' ); ?></label>
826 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose either a city in the same timezone as you or a %s (Coordinated Universal Time) time offset.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
827 <select id="timezone_string" class="ui dropdown" name="timezone_string" aria-describedby="timezone-description">
828 <?php echo wp_timezone_choice( $tzstring, get_user_locale() ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
829 </select>
830 <div class="ui hidden fitted divider"></div>
831 <div class="ui secondary segment">
832 <?php printf( esc_html__( 'Universal time is %s.' ), '<code>' . esc_html( date_i18n( $timezone_format, false, true ) ) . '</code>' ); ?>
833 <div class="ui hidden fitted divider"></div>
834 <?php if ( get_option( 'timezone_string' ) || ! empty( $current_offset ) ) : ?>
835 <?php printf( esc_html__( 'Local time is %s.' ), '<code>' . esc_html( date_i18n( $timezone_format ) ) . '</code>' ); ?>
836 <div class="ui hidden fitted divider"></div>
837 <?php endif; ?>
838 <?php if ( $check_zone_info && $tzstring ) : ?>
839 <?php
840 $now = new \DateTime( 'now', new \DateTimeZone( $tzstring ) );
841 $dst = (bool) $now->format( 'I' );
842
843 if ( $dst ) {
844 esc_html_e( 'This timezone is currently in daylight saving time.', 'mainwp' );
845 } else {
846 esc_html_e( 'This timezone is currently in standard time.', 'mainwp' );
847 }
848 ?>
849 <div class="ui hidden fitted divider"></div>
850 <?php
851 if ( in_array( $tzstring, timezone_identifiers_list(), true ) ) {
852 $transitions = timezone_transitions_get( timezone_open( $tzstring ), time() );
853
854 if ( ! empty( $transitions[1] ) ) {
855 echo ' ';
856 $message = $transitions[1]['isdst'] ? esc_html__( 'Daylight saving time begins on: %s.', 'mainwp' ) : esc_html__( 'Standard time begins on: %s.', 'mainwp' );
857 printf( $message, '<code>' . wp_date( esc_html__( 'F j, Y' ) . ' ' . esc_html__( 'g:i a' ), esc_html( $transitions[1]['ts'] ) ) . '</code>' ); // phpcs:ignore WordPress.Security.EscapeOutput
858 } else {
859 esc_html_e( 'This timezone does not observe daylight saving time.', 'mainwp' );
860 }
861 }
862 ?>
863 <?php endif; ?>
864 </div>
865 </div>
866 </div>
867 <?php
868 }
869
870 /**
871 * Render Date/Time settings.
872 */
873 public static function render_datetime_settings() {
874 ?>
875 <div class="ui grid field">
876 <label class="six wide column middle aligned"><?php esc_html_e( 'Date format', 'mainwp' ); ?></label>
877 <div class="ten wide column fieldset-wrapper" data-tooltip="<?php esc_attr_e( 'Choose the display format for date.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
878 <?php
879 /**
880 * Filters the default date formats.
881 *
882 * @since 2.7.0
883 * @since 4.0.0 Added ISO date standard YYYY-MM-DD format.
884 *
885 * @param string[] $default_date_formats Array of default date formats.
886 */
887 $date_formats = array_unique( apply_filters( 'date_formats', array( esc_html__( 'F j, Y' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) );
888
889 $custom = true;
890
891 foreach ( $date_formats as $format ) {
892 echo "\t<label><input type='radio' name='date_format' value='" . esc_attr( $format ) . "'";
893 if ( get_option( 'date_format' ) === $format ) { // checked() uses "==" rather than "===".
894 echo " checked='checked'";
895 $custom = false;
896 }
897 echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
898 }
899
900 echo '<label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
901 checked( $custom );
902 echo '/> <span class="date-time-text date-time-custom-text">' . esc_html__( 'Custom:' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom date format in the following field' ) . '</span></span></label>' .
903 '<label for="date_format_custom" class="screen-reader-text">' . esc_html__( 'Custom date format:' ) . '</label>' .
904 '<input type="text" name="date_format_custom" id="date_format_custom" value="' . esc_attr( get_option( 'date_format' ) ) . '" class="small-text" />' .
905 '<br />' .
906 '<em><strong>' . esc_html__( 'Preview:' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'date_format' ) ) ) . '</span>' .
907 "<span class='spinner'></span>\n" . '</em>';
908 ?>
909 </div>
910 </div>
911
912 <div class="ui grid field">
913 <label class="six wide column middle aligned"><?php esc_html_e( 'Time format', 'mainwp' ); ?></label>
914 <div class="ten wide column fieldset-wrapper" data-tooltip="<?php esc_attr_e( 'Choose the display format for time.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
915 <?php
916 /**
917 * Filters the default time formats.
918 *
919 * @since 2.7.0
920 *
921 * @param string[] $default_time_formats Array of default time formats.
922 */
923 $time_formats = array_unique( apply_filters( 'time_formats', array( esc_html__( 'g:i a' ), 'g:i A', 'H:i' ) ) );
924
925 $custom = true;
926
927 foreach ( $time_formats as $format ) {
928 echo "\t<label><input type='radio' name='time_format' value='" . esc_attr( $format ) . "'";
929 if ( get_option( 'time_format' ) === $format ) { // checked() uses "==" rather than "===".
930 echo " checked='checked'";
931 $custom = false;
932 }
933 echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
934 }
935 echo '<label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
936 checked( $custom );
937 echo '/> <span class="date-time-text date-time-custom-text">' . esc_html__( 'Custom:' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom time format in the following field' ) . '</span></span></label>' .
938 '<label for="time_format_custom" class="screen-reader-text">' . esc_html__( 'Custom time format:' ) . '</label>' .
939 '<input type="text" name="time_format_custom" id="time_format_custom" value="' . esc_attr( get_option( 'time_format' ) ) . '" class="small-text" />' .
940 '<br />' .
941 '<em><strong>' . esc_html__( 'Preview:' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'time_format' ) ) ) . '</span>' .
942 "<span class='spinner'></span>\n" . '</em>';
943 ?>
944 </div>
945 </div>
946 <script type="text/javascript">
947 jQuery(document).ready( function($) {
948 $( 'input[name="date_format"]' ).on( 'click', function() {
949 if ( 'date_format_custom_radio' !== $( this ).attr( 'id' ) )
950 $( 'input[name="date_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
951 } );
952
953 $( 'input[name="date_format_custom"]' ).on( 'click input', function() {
954 $( '#date_format_custom_radio' ).prop( 'checked', true );
955 } );
956
957 $( 'input[name="time_format"]' ).on( 'click', function() {
958 if ( 'time_format_custom_radio' !== $(this).attr( 'id' ) )
959 $( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
960 } );
961
962 $( 'input[name="time_format_custom"]' ).on( 'click input', function() {
963 $( '#time_format_custom_radio' ).prop( 'checked', true );
964 } );
965
966 $( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() {
967 var format = $( this ),
968 fieldset = format.closest( '.fieldset-wrapper' ),
969 example = fieldset.find( '.example' ),
970 spinner = fieldset.find( '.spinner' );
971
972 // Debounce the event callback while users are typing.
973 clearTimeout( $.data( this, 'timer' ) );
974 $( this ).data( 'timer', setTimeout( function() {
975 // If custom date is not empty.
976 if ( format.val() ) {
977 spinner.addClass( 'is-active' );
978
979 $.post( ajaxurl, {
980 action: 'date_format_custom' === format.attr( 'name' ) ? 'date_format' : 'time_format',
981 date : format.val()
982 }, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
983 }
984 }, 500 ) );
985 } );
986 });
987 </script>
988 <?php
989 }
990
991 /**
992 * Method get_websites_automatic_update_time()
993 *
994 * Get websites automatic update time.
995 *
996 * @return mixed array
997 *
998 * @uses \MainWP\Dashboard\MainWP_DB::get_websites_last_automatic_sync()
999 * @uses \MainWP\Dashboard\MainWP_DB::get_websites_count_where_dts_automatic_sync_smaller_then_start()
1000 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
1001 */
1002 public static function get_websites_automatic_update_time() {
1003 $lastAutomaticUpdate = MainWP_DB::instance()->get_websites_last_automatic_sync();
1004 $lasttimeAutomatic = get_option( 'mainwp_updatescheck_last_timestamp' );
1005 $lasttimeStartAutomatic = get_option( 'mainwp_updatescheck_start_last_timestamp' );
1006 $local_timestamp = MainWP_Utility::get_timestamp();
1007 $running = get_option( 'mainwp_cron_checksites_running' );
1008
1009 if ( empty( $lasttimeStartAutomatic ) && ! empty( $lasttimeAutomatic ) ) {
1010 $lasttimeStartAutomatic = $lasttimeAutomatic;
1011 }
1012
1013 if ( empty( $lastAutomaticUpdate ) ) {
1014 $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1015 } elseif ( 'yes' === $running && ( 0 < MainWP_DB::instance()->get_websites_count_where_dts_automatic_sync_smaller_then_start( $lasttimeStartAutomatic ) || 0 < MainWP_DB::instance()->get_websites_check_updates_count( $lasttimeStartAutomatic ) ) ) {
1016 $nextAutomaticUpdate = esc_html__( 'Processing your websites.', 'mainwp' );
1017 } else {
1018 $next_time = MainWP_System_Cron_Jobs::get_next_time_automatic_update_to_show();
1019 if ( $next_time < $local_timestamp + 5 * MINUTE_IN_SECONDS ) {
1020 $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1021 } else {
1022 $nextAutomaticUpdate = MainWP_Utility::format_timestamp( $next_time );
1023 }
1024 }
1025
1026 if ( empty( $lastAutomaticUpdate ) ) {
1027 $lastAutomaticUpdate = esc_html__( 'Never', 'mainwp' );
1028 } else {
1029 $lastAutomaticUpdate = MainWP_Utility::format_timestamp( $lastAutomaticUpdate );
1030 }
1031
1032 return array(
1033 'last' => $lastAutomaticUpdate,
1034 'next' => $nextAutomaticUpdate,
1035 );
1036 }
1037
1038 /**
1039 * Returns false or the location of the OpenSSL Lib File.
1040 *
1041 * @return mixed false|opensslLibLocation
1042 *
1043 * @uses \MainWP\Dashboard\MainWP_Server_Information_Handler::is_openssl_config_warning()
1044 */
1045 public static function show_openssl_lib_config() {
1046 if ( MainWP_Server_Information_Handler::is_openssl_config_warning() ) {
1047 return true;
1048 } else {
1049 return false;
1050 }
1051 }
1052
1053 /**
1054 * Render Advanced Options Subpage.
1055 *
1056 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
1057 */
1058 public static function render_advanced() { //phpcs:ignore -- complex method.
1059 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
1060 mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
1061 return;
1062 }
1063
1064 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) {
1065
1066 /**
1067 * Action: mainwp_before_save_advanced_settings
1068 *
1069 * Fires before save advanced settings.
1070 *
1071 * @since 4.1
1072 */
1073 do_action( 'mainwp_before_save_advanced_settings', $_POST );
1074
1075 MainWP_Utility::update_option( 'mainwp_maximumRequests', ! empty( $_POST['mainwp_maximumRequests'] ) ? intval( $_POST['mainwp_maximumRequests'] ) : 4 );
1076 MainWP_Utility::update_option( 'mainwp_minimumDelay', ! empty( $_POST['mainwp_minimumDelay'] ) ? intval( $_POST['mainwp_minimumDelay'] ) : 200 );
1077 MainWP_Utility::update_option( 'mainwp_maximumIPRequests', ! empty( $_POST['mainwp_maximumIPRequests'] ) ? intval( $_POST['mainwp_maximumIPRequests'] ) : 1 );
1078 MainWP_Utility::update_option( 'mainwp_minimumIPDelay', ! empty( $_POST['mainwp_minimumIPDelay'] ) ? intval( $_POST['mainwp_minimumIPDelay'] ) : 1000 );
1079 MainWP_Utility::update_option( 'mainwp_maximumSyncRequests', ! empty( $_POST['mainwp_maximumSyncRequests'] ) ? intval( $_POST['mainwp_maximumSyncRequests'] ) : 8 );
1080 MainWP_Utility::update_option( 'mainwp_maximumInstallUpdateRequests', ! empty( $_POST['mainwp_maximumInstallUpdateRequests'] ) ? intval( $_POST['mainwp_maximumInstallUpdateRequests'] ) : 3 );
1081 MainWP_Utility::update_option( 'mainwp_sslVerifyCertificate', isset( $_POST['mainwp_sslVerifyCertificate'] ) ? 1 : 0 );
1082 MainWP_Utility::update_option( 'mainwp_connect_signature_algo', isset( $_POST['mainwp_settings_openssl_alg'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_settings_openssl_alg'] ) ) : 0 );
1083 MainWP_Utility::update_option( 'mainwp_verify_connection_method', isset( $_POST['mainwp_settings_verify_connection_method'] ) ? intval( $_POST['mainwp_settings_verify_connection_method'] ) : 0 );
1084 MainWP_Utility::update_option( 'mainwp_forceUseIPv4', isset( $_POST['mainwp_forceUseIPv4'] ) ? 1 : 0 );
1085 MainWP_Utility::update_option( 'mainwp_wp_cron', ( ! isset( $_POST['mainwp_options_wp_cron'] ) ? 0 : 1 ) );
1086 MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) );
1087
1088 if ( isset( $_POST['mainwp_openssl_lib_location'] ) ) {
1089 $openssl_loc = ! empty( $_POST['mainwp_openssl_lib_location'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_openssl_lib_location'] ) ) : '';
1090 MainWP_Utility::update_option( 'mainwp_opensslLibLocation', $openssl_loc );
1091 }
1092
1093 /**
1094 * Action: mainwp_after_save_advanced_settings
1095 *
1096 * Fires after advanced settings save.
1097 *
1098 * @since 4.1
1099 */
1100 do_action( 'mainwp_after_save_advanced_settings', $_POST );
1101 }
1102 self::render_header( 'Advanced' );
1103 ?>
1104
1105 <div id="mainwp-advanced-settings" class="ui segment">
1106 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-advanced-settings-info-notice' ) ) : ?>
1107 <div class="ui info message">
1108 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-advanced-settings-info-notice"></i>
1109 <?php echo esc_html__( 'Set how many requests are performed at once and delay between requests in order to optimize your MainWP Dashboard performance. Both Cross IP and IP Settings handle the majority of work connecting to your Child sites, while the sync, update, and installation request have specialized options under the Frontend Requests Settings section.', 'mainwp' ); ?>
1110 </div>
1111 <?php endif; ?>
1112 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) : ?>
1113 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
1114 <?php endif; ?>
1115 <div class="ui form">
1116 <form method="POST" action="">
1117 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1118 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'SettingsAdvanced' ) ); ?>" />
1119 <?php
1120
1121 /**
1122 * Action: mainwp_advanced_settings_form_top
1123 *
1124 * Fires at the top of advanced settings form.
1125 *
1126 * @since 4.1
1127 */
1128 do_action( 'mainwp_advanced_settings_form_top' );
1129
1130 if ( self::show_openssl_lib_config() ) {
1131 $openssl_loc = MainWP_System_Utility::get_openssl_conf();
1132 ?>
1133 <h3 class="ui dividing header">
1134 <?php esc_html_e( 'OpenSSL Settings', 'mainwp' ); ?>
1135 <div class="sub header"><?php esc_html_e( 'Due to bug with PHP on some servers it is required to set the OpenSSL Library location so MainWP Dashboard can connect to your child sites.', 'mainwp' ); ?></div>
1136 </h3>
1137 <div class="ui grid field">
1138 <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL.cnf location', 'mainwp' ); ?></label>
1139 <div class="ten wide column ui field">
1140 <input type="text" name="mainwp_openssl_lib_location" value="<?php echo esc_html( $openssl_loc ); ?>">
1141 <em><?php esc_html_e( 'If your openssl.cnf file is saved to a different path from what is entered please enter your exact path.', 'mainwp' ); ?> <?php printf( esc_html__( 'If you are not sure how to find the openssl.cnf location, please %1$scheck this help document%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/how-to-find-the-openssl-cnf-file/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?></em>
1142 <em><?php esc_html_e( 'If you have confirmed the placement of your openssl.cnf and are still receiving an error banner, click the "Error Fixed" button to dismiss it.', 'mainwp' ); ?></em>
1143 </div>
1144 </div>
1145 <?php } ?>
1146
1147 <h3 class="ui dividing header"><?php esc_html_e( 'Cross IP Settings', 'mainwp' ); ?></h3>
1148
1149 <div class="ui grid field">
1150 <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous requests (Default: 4)', 'mainwp' ); ?></label>
1151 <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'If too many requests are sent out, they will begin to time out. This causes your sites to be shown as offline while they are up and running.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1152 <input type="text" name="mainwp_maximumRequests" id="mainwp_maximumRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumRequests' ) ) ? 4 : esc_attr( get_option( 'mainwp_maximumRequests' ) ) ); ?>"/>
1153 </div>
1154 </div>
1155
1156 <div class="ui grid field">
1157 <label class="six wide column middle aligned"><?php esc_html_e( 'Minimum delay between requests (Default: 200)', 'mainwp' ); ?></label>
1158 <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control minimum time delay between two requests.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1159 <input type="text" name="mainwp_minimumDelay" id="mainwp_minimumDelay" value="<?php echo ( ( false === get_option( 'mainwp_minimumDelay' ) ) ? 200 : esc_attr( get_option( 'mainwp_minimumDelay' ) ) ); ?>"/>
1160 </div>
1161 </div>
1162
1163 <h3 class="ui dividing header"><?php esc_html_e( 'Per IP Settings', 'mainwp' ); ?></h3>
1164
1165 <div class="ui grid field">
1166 <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous requests per IP (Default: 1)', 'mainwp' ); ?></label>
1167 <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'If too many requests are sent out, they will begin to time out. This causes your sites to be shown as offline while they are up and running.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1168 <input type="text" name="mainwp_maximumIPRequests" id="mainwp_maximumIPRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumIPRequests' ) ) ? 1 : esc_attr( get_option( 'mainwp_maximumIPRequests' ) ) ); ?>"/>
1169 </div>
1170 </div>
1171
1172 <div class="ui grid field">
1173 <label class="six wide column middle aligned"><?php esc_html_e( 'Minimum delay between requests to the same IP (Default: 1000)', 'mainwp' ); ?></label>
1174 <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control minimum time delay between two requests.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1175 <input type="text" name="mainwp_minimumIPDelay" id="mainwp_minimumIPDelay" value="<?php echo ( ( false === get_option( 'mainwp_minimumIPDelay' ) ) ? 1000 : esc_attr( get_option( 'mainwp_minimumIPDelay' ) ) ); ?>"/>
1176 </div>
1177 </div>
1178
1179 <h3 class="ui dividing header"><?php esc_html_e( 'Frontend Request Settings', 'mainwp' ); ?></h3>
1180
1181 <div class="ui grid field">
1182 <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous sync requests (Default: 8)', 'mainwp' ); ?></label>
1183 <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control how many sites your MainWP Dashboard should sync at once.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1184 <input type="text" name="mainwp_maximumSyncRequests" id="mainwp_maximumSyncRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumSyncRequests' ) ) ? 8 : esc_attr( get_option( 'mainwp_maximumSyncRequests' ) ) ); ?>"/>
1185 </div>
1186 </div>
1187
1188 <div class="ui grid field">
1189 <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous install and update requests (Default: 3)', 'mainwp' ); ?></label>
1190 <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control how many update and install requests your MainWP Dashboard should process at once.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1191 <input type="text" name="mainwp_maximumInstallUpdateRequests" id="mainwp_maximumInstallUpdateRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumInstallUpdateRequests' ) ) ? 3 : esc_attr( get_option( 'mainwp_maximumInstallUpdateRequests' ) ) ); ?>"/>
1192 </div>
1193 </div>
1194
1195 <h3 class="ui dividing header"><?php esc_html_e( 'Miscellaneous Settings', 'mainwp' ); ?></h3>
1196 <div class="ui grid field">
1197 <label class="six wide column middle aligned"><?php esc_html_e( 'Optimize data loading', 'mainwp' ); ?></label>
1198 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will cache updates for faster loading.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1199 <input type="checkbox" name="mainwp_optimize" id="mainwp_optimize" <?php echo ( ( 1 === (int) get_option( 'mainwp_optimize', 1 ) ) ? 'checked="true"' : '' ); ?> /><label><?php esc_html_e( 'Default: Off', 'mainwp' ); ?></label>
1200 </div>
1201 </div>
1202 <div class="ui grid field">
1203 <label class="six wide column middle aligned"><?php esc_html_e( 'Use WP Cron', 'mainwp' ); ?></label>
1204 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Disabling this option will disable the WP Cron so all scheduled events will stop working.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1205 <input type="checkbox" name="mainwp_options_wp_cron" id="mainwp_options_wp_cron" <?php echo ( ( 1 === (int) get_option( 'mainwp_wp_cron' ) ) || ( false === get_option( 'mainwp_wp_cron' ) ) ? 'checked="true"' : '' ); ?>/><label><?php esc_html_e( 'Default: On', 'mainwp' ); ?></label>
1206 </div>
1207 </div>
1208 <div class="ui grid field" >
1209 <label class="six wide column middle aligned"><?php esc_html_e( 'Verify SSL certificate', 'mainwp' ); ?></label>
1210 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will verify the SSL Certificate on your Child Site (if exists) while connecting the Child Site.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1211 <input type="checkbox" name="mainwp_sslVerifyCertificate" id="mainwp_sslVerifyCertificate" value="checked" <?php echo ( ( false === get_option( 'mainwp_sslVerifyCertificate' ) ) || ( 1 === (int) get_option( 'mainwp_sslVerifyCertificate' ) ) ) ? 'checked="checked"' : ''; ?>/><label><?php esc_html_e( 'Default: On', 'mainwp' ); ?></label>
1212 </div>
1213 </div>
1214 <?php
1215 $general_verify_con = (int) get_option( 'mainwp_verify_connection_method', 0 );
1216 ?>
1217 <div class="ui grid field">
1218 <label class="six wide column middle aligned"><?php esc_html_e( 'Verify connection method', 'mainwp' ); ?></label>
1219 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Select Verify connection method. If you are not sure, select "Default".', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1220 <select class="ui dropdown" id="mainwp_settings_verify_connection_method" name="mainwp_settings_verify_connection_method">
1221 <option <?php echo ( empty( $general_verify_con ) || 1 === $general_verify_con ) ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'OpenSSL (default)', 'mainwp' ); ?></option>
1222 <option <?php echo ( 2 === $general_verify_con ) ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'PHPSECLIB (fallback)', 'mainwp' ); ?></option>
1223 </select>
1224 </div>
1225 </div>
1226 <?php
1227 $sign_note = MainWP_Connect_Lib::get_connection_algo_settings_note();
1228 $sign_algs = MainWP_System_Utility::get_open_ssl_sign_algos();
1229 $general_sign_alg = get_option( 'mainwp_connect_signature_algo', false );
1230 if ( false === $general_sign_alg ) {
1231 $general_sign_alg = defined( 'OPENSSL_ALGO_SHA256' ) ? OPENSSL_ALGO_SHA256 : 1;
1232 MainWP_Utility::update_option( 'mainwp_connect_signature_algo', $general_sign_alg );
1233 } else {
1234 $general_sign_alg = intval( $general_sign_alg );
1235 }
1236 ?>
1237 <div class="ui grid field mainwp-hide-elemenent-sign-algo" <?php echo ( 2 === $general_verify_con ) ? 'style="display:none;"' : ''; ?> >
1238 <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL signature algorithm', 'mainwp' ); ?></label>
1239 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Select OpenSSL signature algorithm. If you are not sure, select "Default".', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1240 <select class="ui dropdown" id="mainwp_settings_openssl_alg" name="mainwp_settings_openssl_alg">
1241 <?php
1242 foreach ( $sign_algs as $val => $text ) {
1243 ?>
1244 <option <?php echo ( $val === $general_sign_alg ) ? 'selected' : ''; ?> value="<?php echo esc_attr( $val ); ?>"><?php echo esc_html( $text ); ?></option>
1245 <?php
1246 }
1247 ?>
1248 </select>
1249 <div class="ui yellow message mainwp-hide-elemenent-sign-algo-note" <?php echo ( 1 === $general_sign_alg ) ? '' : 'style="display:none;"'; ?>><?php echo esc_html( $sign_note ); ?></div>
1250 </div>
1251 </div>
1252 <div class="ui grid field">
1253 <label class="six wide column middle aligned"><?php esc_html_e( 'Force IPv4', 'mainwp' ); ?></label>
1254 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to force your MainWP Dashboard to use IPv4 while tryig to connect child sites.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1255 <input type="checkbox" name="mainwp_forceUseIPv4" id="mainwp_forceUseIPv4" value="checked" <?php echo ( 1 === (int) get_option( 'mainwp_forceUseIPv4' ) ) ? 'checked="checked"' : ''; ?>/><label><?php esc_html_e( 'Default: Off', 'mainwp' ); ?></label>
1256 </div>
1257 </div>
1258 <?php
1259
1260 /**
1261 * Action: mainwp_advanced_settings_form_bottom
1262 *
1263 * Fires at the bottom of advanced settings form.
1264 *
1265 * @since 4.1
1266 */
1267 do_action( 'mainwp_advanced_settings_form_bottom' );
1268
1269 ?>
1270 <div class="ui divider"></div>
1271 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1272 </form>
1273 </div>
1274 </div>
1275 <?php
1276 self::render_footer( 'Advanced' );
1277 }
1278
1279 /**
1280 * Render MainWP Tools SubPage.
1281 *
1282 * @uses \MainWP\Dashboard\MainWP_UI::render_screen_options()
1283 */
1284 public static function render_mainwp_tools() {
1285 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
1286 mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
1287
1288 return;
1289 }
1290 self::render_header( 'MainWPTools' );
1291 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1292 ?>
1293 <div id="mainwp-tools-settings" class="ui segment">
1294 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
1295 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-message' ) ) : ?>
1296 <div class="ui info message">
1297 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-message"></i>
1298 <?php printf( esc_html__( 'Use MainWP tools to adjust your MainWP Dashboard to your needs and perform specific actions when needed. For additional help, review this %1$shelp document%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?>
1299 </div>
1300 <?php endif; ?>
1301 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-custom-theme' ) ) : ?>
1302 <div class="ui info message">
1303 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-custom-theme"></i>
1304 <div><?php esc_html_e( 'Here you can select a theme for your MainWP Dashboard.', 'mainwp' ); ?></div>
1305 <div><?php esc_html_e( 'To create a custom theme, copy the `mainwp-dark-theme.css` file from the MainWP Custom Dashboard Extension located in the `css` directory, make your edits and upload the file to the `../wp-content/uploads/mainwp/custom-dashboard/` directory.', 'mainwp' ); ?></div>
1306 </div>
1307 <?php endif; ?>
1308 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) : ?>
1309 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
1310 <?php endif; ?>
1311 <?php if ( isset( $_POST['mainwp_restore_info_messages'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) : ?>
1312 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Info messages have been restored successfully!', 'mainwp' ); ?></div>
1313 <?php endif; ?>
1314 <div class="ui form">
1315 <form method="POST" action="">
1316 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1317 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'MainWPTools' ) ); ?>" />
1318 <h3 class="ui dividing header"><?php esc_html_e( 'MainWP Dashboard Tools', 'mainwp' ); ?></h3>
1319 <?php
1320 /**
1321 * Action: mainwp_tools_form_top
1322 *
1323 * Fires at the top of MainWP tools form.
1324 *
1325 * @since 4.1
1326 */
1327 do_action( 'mainwp_tools_form_top' );
1328
1329 $show_qsw = apply_filters( 'mainwp_show_qsw', true );
1330
1331 self::get_instance()->render_select_custom_themes();
1332
1333 ?>
1334 <div class="ui grid field">
1335 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable MainWP guided tours', 'mainwp' ); ?> <span class="ui blue mini label"><?php esc_html_e( 'BETA', 'mainwp' ); ?></span></label>
1336 <div class="ten wide column " data-tooltip="<?php esc_attr_e( 'Check this option to enable, or uncheck to disable MainWP guided tours.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1337 <div class="ui info message" style="display:block!important;">
1338 <?php printf( esc_html__( 'This feature is implemented using Javascript provided by Usetiful and is subject to the %1$sUsetiful Privacy Policy%2$s.', 'mainwp' ), '<a href="https://www.usetiful.com/privacy-policy" target="_blank">', '</a>' ); ?>
1339 </div>
1340 <div class="ui toggle checkbox">
1341 <input type="checkbox" name="mainwp-guided-tours-option" id="mainwp-guided-tours-option" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_guided_tours', 0 ) ) ? 'checked="true"' : '' ); ?> />
1342 </div>
1343 </div>
1344 </div>
1345 <div class="ui grid field">
1346 <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashboard to establish a new connection', 'mainwp' ); ?></label>
1347 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Force your MainWP Dashboard to reconnect with your child sites. Only needed if suggested by MainWP Support.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1348 <?php
1349 if ( $is_demo ) {
1350 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<input type="button" disabled="disabled" class="ui green basic button disabled" value="' . esc_attr__( 'Re-establish Connections', 'mainwp' ) . '" />' );
1351 } else {
1352 ?>
1353 <input type="button" name="" id="force-destroy-sessions-button" data-inverted="" data-position="top right" data-tooltip="<?php esc_attr_e( 'Forces your dashboard to reconnect with your child sites. This feature will log out any currently logged in users on the Child sites and require them to re-log in. Only needed if suggested by MainWP Support.', 'mainwp' ); ?>" class="ui green basic button" value="<?php esc_attr_e( 'Re-establish Connections', 'mainwp' ); ?>" />
1354 <?php } ?>
1355 </div>
1356 </div>
1357 <div class="ui grid field">
1358 <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashbaord to set new pair of OpenSSL Keys', 'mainwp' ); ?></label>
1359 <div class="ten wide column" id="mainwp-renew-connections-tool" data-content="<?php esc_attr_e( 'This will function renew connection and reconnect site right away.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
1360 <?php
1361 if ( $is_demo ) {
1362 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="javascript:void(0)" disabled="disabled" class="ui button green basic disabled">' . esc_html__( 'Reset OpenSSL Key Pair', 'mainwp' ) . '</a>' );
1363 } else {
1364 ?>
1365 <a href="javascript:void(0)" onclick="mainwp_tool_renew_connections_show(); return false;" class="ui button green basic"><?php esc_html_e( 'Reset OpenSSL Key Pair', 'mainwp' ); ?></a>
1366 <?php } ?>
1367 </div>
1368 </div>
1369 <?php if ( $show_qsw ) { ?>
1370 <div class="ui grid field">
1371 <label class="six wide column middle aligned"><?php esc_html_e( 'Start the MainWP Quick Setup Wizard', 'mainwp' ); ?></label>
1372 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to start the Quick Setup Wizard', 'mainwp' ); ?>" data-inverted="" data-position="top left"><a href="admin.php?page=mainwp-setup" class="ui green button basic" ><?php esc_html_e( 'Start Quick Setup Wizard', 'mainwp' ); ?></a></div>
1373 </div>
1374 <?php } ?>
1375 <div class="ui grid field">
1376 <label class="six wide column middle aligned"><?php esc_html_e( 'Export child sites to CSV file', 'mainwp' ); ?></label>
1377 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to export all connected sites to a CSV file.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><a href="admin.php?page=MainWPTools&doExportSites=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'export_sites' ) ); ?>" class="ui button green basic"><?php esc_html_e( 'Export Child Sites', 'mainwp' ); ?></a></div>
1378 </div>
1379 <div class="ui grid field">
1380 <label class="six wide column middle aligned"><?php esc_html_e( 'Import child sites', 'mainwp' ); ?></label>
1381 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to import websites to your MainWP Dashboard.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><a href="admin.php?page=managesites&do=bulknew" class="ui button green basic"><?php esc_html_e( 'Import Child Sites', 'mainwp' ); ?></a></div>
1382 </div>
1383 <div class="ui grid field">
1384 <label class="six wide column middle aligned"><?php esc_html_e( 'Disconnect all child sites', 'mainwp' ); ?></label>
1385 <div class="ten wide column" id="mainwp-disconnect-sites-tool" data-content="<?php esc_attr_e( 'This will function will break the connection and leave the MainWP Child plugin active and which makes your sites vulnerable. Use only if you attend to reconnect site to the same or a different dashboard right away.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
1386 <?php
1387 if ( $is_demo ) {
1388 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="#" class="ui button green basic disabled" disabled="disabled">' . esc_html__( 'Disconnect Sites', 'mainwp' ) . '</a>' );
1389 } else {
1390 ?>
1391 <a href="admin.php?page=MainWPTools&disconnectSites=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'disconnect_sites' ) ); ?>" onclick="mainwp_tool_disconnect_sites(); return false;" class="ui button green basic"><?php esc_html_e( 'Disconnect Sites', 'mainwp' ); ?></a>
1392 <?php } ?>
1393 </div>
1394 </div>
1395 <div class="ui grid field">
1396 <label class="six wide column middle aligned"><?php esc_html_e( 'Delete extensions API Activation data', 'mainwp' ); ?></label>
1397 <div class="ten wide column" id="mainwp-clear-activation-data" data-content="<?php esc_attr_e( 'Delete extensions API activation data. This will not affect extensions settings, it just removes API activation data.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
1398 <a href="admin.php?page=MainWPTools&clearActivationData=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'clear_activation_data' ) ); ?>" onclick="mainwp_tool_clear_activation_data(this); return false;" class="ui button green basic"><?php esc_html_e( 'Delete Extensions API Activation Data', 'mainwp' ); ?></a>
1399 </div>
1400 </div>
1401 <div class="ui grid field">
1402 <label class="six wide column middle aligned"><?php esc_html_e( 'Restore all info messages', 'mainwp' ); ?></label>
1403 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to restore all info messages in your MainWP Dashboard and Extensions.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1404 <input type="submit" name="mainwp_restore_info_messages" id="mainwp_restore_info_messages" class="ui button" value="<?php esc_attr_e( 'Restore Info Messages', 'mainwp' ); ?>"/>
1405 </div>
1406 </div>
1407 <?php
1408 $enabled_demo = MainWP_Demo_Handle::is_demo_mode();
1409 $is_new = MainWP_Demo_Handle::get_instance()->is_new_instance();
1410 if ( ! MainWP_Demo_Handle::is_instawp_site() ) {
1411 ?>
1412 <div class="ui grid field">
1413 <label class="six wide column middle aligned"><?php echo esc_html__( 'Demo mode', 'mainwp' ); ?></label>
1414 <div class="ten wide column">
1415 <?php if ( ! $enabled_demo ) { ?>
1416 <span data-tooltip="<?php esc_attr_e( 'Demo Mode can not be enabled on MainWP Dashboards that already have sites connected, clients created or extensions installed.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><button page-import="settings" class="ui green button mainwp-import-demo-data-button" <?php echo ( ! $is_new ? 'disabled="disabled"' : '' ); ?>><?php esc_html_e( 'Import Demo Content', 'mainwp' ); ?></button></span>
1417 <?php } else { ?>
1418 <span data-tooltip="<?php esc_attr_e( 'Click this button to delete the Demo content from your MainWP Dashboard and disable the Demo mode.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><button class="ui green button mainwp-remove-demo-data-button"><?php esc_html_e( 'Delete Demo Content', 'mainwp' ); ?></button></span>
1419 <?php } ?>
1420 </div>
1421 </div>
1422 <?php
1423 }
1424 /**
1425 * Action: mainwp_tools_form_bottom
1426 *
1427 * Fires at the bottom of mainwp tools form.
1428 *
1429 * @since 4.1
1430 */
1431 do_action( 'mainwp_tools_form_bottom' );
1432 ?>
1433 <div class="ui divider"></div>
1434 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1435 </form>
1436 </div>
1437 </div>
1438 <script type="text/javascript">
1439 jQuery( '#mainwp-disconnect-sites-tool' ).popup();
1440 jQuery( '#mainwp-clear-activation-data' ).popup();
1441 </script>
1442 <?php
1443 self::render_footer( 'MainWPTools' );
1444 MainWP_Connect_Helper::render_renew_connections_modal();
1445 }
1446
1447 /**
1448 * Render MainWP themes selection.
1449 */
1450 public function render_select_custom_themes() {
1451 $custom_theme = $this->get_current_user_theme();
1452 if ( false === $custom_theme ) {
1453 // to compatible with Custom Dashboard extension settings.
1454 $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
1455 if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
1456 $compat_theme = $compat_settings['theme'];
1457 }
1458 if ( null !== $compat_theme ) {
1459 $custom_theme = $compat_theme;
1460 }
1461 }
1462 $themes_files = self::get_instance()->get_custom_themes_files();
1463 if ( empty( $themes_files ) ) {
1464 $themes_files = array();
1465 }
1466 ?>
1467 <div class="ui grid field">
1468 <label class="six wide column middle aligned"><?php esc_html_e( 'Select MainWP Theme', 'mainwp' ); ?></label>
1469 <div class="ten wide column" tabindex="0" data-tooltip="<?php esc_attr_e( 'Select your MainWP Dashboard theme.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1470 <select name="mainwp_settings_custom_theme" id="mainwp_settings_custom_theme" class="ui dropdown selection">
1471 <option value="default" <?php echo ( 'default' === $custom_theme || empty( $custom_theme ) ) ? 'selected' : ''; ?>><?php esc_html_e( 'Default', 'mainwp' ); ?></option>
1472 <option value="classic" <?php echo ( 'classic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Classic', 'mainwp' ); ?></option>
1473 <option value="dark" <?php echo ( 'dark' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Dark', 'mainwp' ); ?></option>
1474 <option value="wpadmin" <?php echo ( 'wpadmin' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'WP Admin', 'mainwp' ); ?></option>
1475 <option value="minimalistic" <?php echo ( 'minimalistic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Minimalistic', 'mainwp' ); ?></option>
1476 <?php
1477 foreach ( $themes_files as $file_name => $theme ) {
1478 $theme = ucfirst( $theme );
1479 $_select = '';
1480 if ( $custom_theme === $file_name ) {
1481 $_select = 'selected';
1482 }
1483 echo '<option value="' . esc_attr( $file_name ) . '" ' . esc_attr( $_select ) . '>' . esc_html( $theme ) . '</option>';
1484 }
1485 ?>
1486 </select>
1487 </div>
1488 </div>
1489 <?php
1490 }
1491
1492 /**
1493 * Get custom themes files.
1494 */
1495 public function get_custom_themes_files() {
1496 // get themes files.
1497 $dirs = $this->get_custom_theme_folder();
1498 $scan_dir = $dirs[0];
1499 $handle = opendir( $scan_dir );
1500 $themes = array();
1501 $scan_files = array();
1502 if ( $handle ) {
1503 $filename = readdir( $handle );
1504 while ( false !== $filename ) {
1505 $correct_file = true;
1506 if ( '.' === substr( $filename, 0, 1 ) || 'index.php' === $filename ) {
1507 $correct_file = false;
1508 } elseif ( '.css' !== substr( $filename, - 4 ) ) {
1509 $correct_file = false;
1510 }
1511 if ( $correct_file ) {
1512 $theme = basename( $filename, '.css' );
1513 $theme = str_replace( '-theme', '', $theme );
1514 $themes[ $filename ] = trim( $theme );
1515 }
1516 $filename = readdir( $handle ); // to while loop.
1517 }
1518 closedir( $handle );
1519 }
1520 return $themes;
1521 }
1522
1523 /**
1524 * Get selected MainWP theme name.
1525 */
1526 public function get_selected_theme() {
1527 $selected_theme = false;
1528
1529 $custom_theme = $this->get_current_user_theme();
1530
1531 if ( false === $custom_theme ) {
1532 // to compatible with Custom Dashboard extension settings.
1533 $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
1534 if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
1535 $compat_theme = $compat_settings['theme'];
1536 }
1537
1538 if ( null !== $compat_theme ) {
1539 $custom_theme = $compat_theme;
1540 }
1541 }
1542
1543 if ( ! empty( $custom_theme ) ) {
1544 if ( 'default' === $custom_theme || 'dark' === $custom_theme || 'wpadmin' === $custom_theme || 'minimalistic' === $custom_theme ) {
1545 return $custom_theme;
1546 }
1547 $dirs = $this->get_custom_theme_folder();
1548 $theme_dir = $dirs[0];
1549 $file = $theme_dir . $custom_theme;
1550 if ( file_exists( $file ) && '.css' === substr( $file, - 4 ) ) {
1551 $selected_theme = $custom_theme;
1552 }
1553 }
1554 return $selected_theme;
1555 }
1556
1557
1558 /**
1559 * Get custom MainWP theme folder.
1560 */
1561 public function get_custom_theme_folder() {
1562 $dirs = MainWP_System_Utility::get_mainwp_dir();
1563 global $wp_filesystem;
1564 if ( is_array( $dirs ) && ! $wp_filesystem->exists( $dirs[0] . 'themes' ) && $wp_filesystem->exists( $dirs[0] . 'custom-dashboard' ) ) {
1565 // re-name the custom-dashboard folder to compatible.
1566 $wp_filesystem->move( $dirs[0] . 'custom-dashboard', $dirs[0] . 'themes' );
1567 }
1568 $dirs = MainWP_System_Utility::get_mainwp_dir_allow_access( 'themes' );
1569 return $dirs;
1570 }
1571
1572
1573 /**
1574 * Get current user's selected theme.
1575 */
1576 public function get_current_user_theme() {
1577 $custom_theme = get_user_option( 'mainwp_selected_theme' );
1578 if ( empty( $custom_theme ) ) {
1579 $custom_theme = get_option( 'mainwp_selected_theme', 'default' );
1580 }
1581 return $custom_theme;
1582 }
1583
1584 /**
1585 * Export Child Sites and save as .csv file.
1586 *
1587 * @uses \MainWP\Dashboard\MainWP_DB::query()
1588 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
1589 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
1590 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
1591 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
1592 */
1593 public static function export_sites() {
1594 if ( isset( $_GET['doExportSites'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'export_sites' ) ) {
1595
1596 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( true );
1597 $websites = MainWP_DB::instance()->query( $sql );
1598
1599 if ( ! $websites ) {
1600 die( 'Not found sites' );
1601 }
1602
1603 $keys = array( 'name', 'url', 'adminname', 'wpgroups', 'uniqueId', 'http_user', 'http_pass', 'verify_certificate', 'ssl_version' );
1604 $allowedHeaders = array( 'site name', 'url', 'admin name', 'group', 'security id', 'http username', 'http password', 'verify certificate', 'ssl version' );
1605
1606 $csv = implode( ',', $allowedHeaders ) . "\r";
1607 MainWP_DB::data_seek( $websites, 0 );
1608 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1609 if ( empty( $website ) ) {
1610 continue;
1611 }
1612 $row = MainWP_Utility::map_site( $website, $keys, false );
1613 $csv .= '"' . implode( '","', $row ) . '"' . "\r";
1614 }
1615
1616 header( 'Content-Type: text/csv; charset=utf-8' );
1617 header( 'Content-Disposition: attachment; filename=export-sites.csv' );
1618 echo $csv; // phpcs:ignore WordPress.Security.EscapeOutput
1619 exit();
1620 }
1621 }
1622
1623 /**
1624 * Render MainWP Email Settings SubPage.
1625 *
1626 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_notification_types()
1627 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_edit_settings()
1628 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::emails_general_settings_handle()
1629 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_all_settings()
1630 * @uses \MainWP\Dashboard\MainWP_Notification_Template::handle_template_file_action()
1631 */
1632 public static function render_email_settings() {
1633 $notification_emails = MainWP_Notification_Settings::get_notification_types();
1634 self::render_header( 'Emails' );
1635 $edit_email = isset( $_GET['edit-email'] ) ? sanitize_text_field( wp_unslash( $_GET['edit-email'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1636 if ( ! empty( $edit_email ) && isset( $notification_emails[ $edit_email ] ) ) {
1637 $updated_templ = MainWP_Notification_Template::instance()->handle_template_file_action();
1638 MainWP_Notification_Settings::instance()->render_edit_settings( $edit_email, $updated_templ );
1639 } else {
1640 $updated = MainWP_Notification_Settings::emails_general_settings_handle();
1641 MainWP_Notification_Settings::instance()->render_all_settings( $updated );
1642 }
1643 self::render_footer( 'Emails' );
1644 }
1645
1646 /**
1647 * Hook the section help content to the Help Sidebar element
1648 */
1649 public static function mainwp_help_content() {
1650 if ( isset( $_GET['page'] ) && ( 'Settings' === $_GET['page'] || 'SettingsAdvanced' === $_GET['page'] || 'MainWPTools' === $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1651 ?>
1652 <p><?php esc_html_e( 'If you need help with your MainWP Dashboard settings, please review following help documents', 'mainwp' ); ?></p>
1653 <div class="ui relaxed bulleted list">
1654 <div class="item"><a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/" target="_blank">MainWP Dashboard Settings</a> <i class="external alternate icon"></i></div>
1655 </div>
1656 <?php
1657 }
1658 }
1659 }
1660