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

2,138 lines 137.4 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 { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
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( static::$instance ) ) {
52 static::$instance = new self();
53 }
54 return static::$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( static::get_class_name(), 'render_header' ) ); // deprecated, use mainwp_pageheader_settings.
67
68 add_action( 'mainwp_pageheader_settings', array( static::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( static::get_class_name(), 'render_footer' ) ); // deprecated, use mainwp_pagefooter_settings.
78
79 add_action( 'mainwp_pagefooter_settings', array( static::get_class_name(), 'render_footer' ) );
80
81 add_action( 'admin_init', array( static::get_class_name(), 'admin_init' ) );
82
83 add_action( 'mainwp_help_sidebar_content', array( static::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() { // phpcs:ignore -- NOSONAR - complex.
88 static::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 static::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 static::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 static::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 static::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. NOSONAR - not IP.
203 static::$subPages = apply_filters( 'mainwp_getsubpages_settings', $sub_pages );
204
205 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
206 foreach ( static::$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( static::$subPages ) && is_array( static::$subPages ) && ! empty( static::$subPages ) ) {
238 foreach ( static::$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 isset( $subPage['before_title'] ) ? $subPage['before_title'] : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?> <?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 = '' ) { // phpcs:ignore -- NOSONAR - complex.
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( static::$subPages ) && is_array( static::$subPages ) ) {
368 foreach ( static::$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 if ( ! empty( $subPage['before_title'] ) ) {
377 $item['before_title'] = $subPage['before_title'];
378 }
379
380 if ( isset( $subPage['class'] ) ) {
381 $item['class'] = $subPage['class'];
382 }
383 $renderItems[] = $item;
384 }
385 }
386
387 MainWP_UI::render_page_navigation( $renderItems );
388 }
389
390 /**
391 * Close the HTML container.
392 */
393 public static function render_footer() {
394 echo '</div>';
395 }
396
397 /**
398 * Method handle_settings_post().
399 *
400 * This class handles the $_POST of Settings Options.
401 *
402 * @uses MainWP_DB::instance()
403 * @uses MainWP_Utility::update_option()
404 *
405 * @return boolean True|False Posts On True.
406 *
407 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
408 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
409 * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
410 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
411 */
412 public static function handle_settings_post() { // phpcs:ignore -- NOSONAR - complex.
413 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) {
414 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
415 $userExtension->pluginDir = '';
416
417 MainWP_DB_Common::instance()->update_user_extension( $userExtension );
418 if ( MainWP_System_Utility::is_admin() ) {
419
420 /**
421 * Action: mainwp_before_save_general_settings
422 *
423 * Fires before general settings save.
424 *
425 * @since 4.1
426 */
427 do_action( 'mainwp_before_save_general_settings', $_POST );
428
429 $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) );
430 MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val );
431 $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) );
432 MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val );
433 $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) );
434 MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val );
435 $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 );
436 MainWP_Utility::update_option( 'mainwp_show_language_updates', $val );
437 $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) );
438 MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val );
439 $val = ( ! isset( $_POST['mainwp_backup_before_upgrade'] ) ? 0 : 1 );
440 MainWP_Utility::update_option( 'mainwp_backup_before_upgrade', $val );
441 $val = ( ! isset( $_POST['mainwp_backup_before_upgrade_days'] ) ? 7 : intval( $_POST['mainwp_backup_before_upgrade_days'] ) );
442 MainWP_Utility::update_option( 'mainwp_backup_before_upgrade_days', $val );
443
444 if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) {
445 MainWP_Utility::update_option( 'mainwp_maximumComments', isset( $_POST['mainwp_maximumComments'] ) ? intval( $_POST['mainwp_maximumComments'] ) : 50 );
446 }
447
448 $current_timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
449 $new_timeDailyUpdate = isset( $_POST['mainwp_timeDailyUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_timeDailyUpdate'] ) ) : '';
450
451 if ( $current_timeDailyUpdate !== $new_timeDailyUpdate ) {
452 MainWP_Utility::update_option( 'mainwp_timeDailyUpdate', $new_timeDailyUpdate );
453 }
454
455 $old_freq = (int) get_option( 'mainwp_frequencyDailyUpdate', 2 );
456 $new_freq = ( isset( $_POST['mainwp_frequencyDailyUpdate'] ) ? intval( $_POST['mainwp_frequencyDailyUpdate'] ) : 2 );
457 if ( $old_freq !== $new_freq ) {
458 MainWP_Utility::update_option( 'mainwp_frequencyDailyUpdate', $new_freq );
459 MainWP_Logger::instance()->log_update_check( 'New frequency daily :: ' . $new_freq );
460 }
461
462 $curr_frequency_updates = get_option( 'mainwp_frequency_AutoUpdate', 'daily' );
463 $new_frequency_updates = isset( $_POST['mainwp_frequency_AutoUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_frequency_AutoUpdate'] ) ) : 'daily';
464 if ( $new_frequency_updates !== $curr_frequency_updates ) {
465 MainWP_Utility::update_option( 'mainwp_frequency_AutoUpdate', $new_frequency_updates );
466 }
467
468 $curr_day_updates = (int) get_option( 'mainwp_dayinweek_AutoUpdate', 0 );
469 $new_day_updates = isset( $_POST['mainwp_dayinweek_AutoUpdate'] ) ? intval( wp_unslash( $_POST['mainwp_dayinweek_AutoUpdate'] ) ) : 0;
470 if ( $new_day_updates !== $curr_day_updates ) {
471 MainWP_Utility::update_option( 'mainwp_dayinweek_AutoUpdate', $new_day_updates );
472 }
473
474 $curr_dayinmonth_updates = (int) get_option( 'mainwp_dayinmonth_AutoUpdate', 1 );
475 $new_dayinmonth_updates = isset( $_POST['mainwp_dayinmonth_AutoUpdate'] ) ? intval( wp_unslash( $_POST['mainwp_dayinmonth_AutoUpdate'] ) ) : 1;
476 if ( $new_dayinmonth_updates !== $curr_dayinmonth_updates ) {
477 MainWP_Utility::update_option( 'mainwp_dayinmonth_AutoUpdate', $new_dayinmonth_updates );
478 }
479
480 $curr_time_updates = get_option( 'mainwp_time_AutoUpdate', '00:00' );
481 $new_time_updates = isset( $_POST['mainwp_time_AutoUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_time_AutoUpdate'] ) ) : '00:00';
482 if ( $new_time_updates !== $curr_time_updates ) {
483 MainWP_Utility::update_option( 'mainwp_time_AutoUpdate', $new_time_updates );
484 }
485
486 MainWP_Cron_Jobs_Auto_Updates::set_next_auto_updates_time();
487
488 $new_delay = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 );
489 MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $new_delay );
490
491 $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 );
492 $user = wp_get_current_user();
493 if ( $user ) {
494 update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
495 }
496
497 MainWP_Utility::update_option( 'mainwp_numberdays_Outdate_Plugin_Theme', ! empty( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) ? intval( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) : 365 );
498
499 $check_http_response = ( isset( $_POST['mainwp_check_http_response'] ) ? 1 : 0 );
500 MainWP_Utility::update_option( 'mainwp_check_http_response', $check_http_response );
501
502 $actions_notification_enable = ( isset( $_POST['mainwp_site_actions_notification_enable'] ) ? 1 : 0 );
503 MainWP_Utility::update_option( 'mainwp_site_actions_notification_enable', $actions_notification_enable );
504
505 //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
506 // Handle custom date/time formats.
507 if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] )
508 && '\c\u\s\t\o\m' === wp_unslash( $_POST['date_format'] )
509 ) {
510 $_POST['date_format'] = wp_unslash( $_POST['date_format_custom'] );
511 }
512
513 if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] )
514 && '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] )
515 ) {
516 $_POST['time_format'] = wp_unslash( $_POST['time_format_custom'] );
517 }
518
519 if ( isset( $_POST['timezone_string'] ) ) {
520 // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
521 if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', wp_unslash( $_POST['timezone_string'] ) ) ) {
522 $_POST['gmt_offset'] = wp_unslash( $_POST['timezone_string'] );
523 $_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', wp_unslash( $_POST['gmt_offset'] ) ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
524 $_POST['timezone_string'] = '';
525 }
526
527 $options = array(
528 'gmt_offset',
529 'date_format',
530 'time_format',
531 'timezone_string',
532 );
533
534 foreach ( $options as $option ) {
535 $value = null;
536 if ( isset( $_POST[ $option ] ) ) {
537 $value = wp_unslash( $_POST[ $option ] );
538 if ( ! is_array( $value ) ) {
539 $value = trim( $value );
540 }
541 }
542 update_option( $option, $value );
543 }
544 }
545 //phpcs:enable
546
547 MainWP_Utility::update_option( 'mainwp_use_favicon', 1 );
548
549 /**
550 * Action: mainwp_after_save_general_settings
551 *
552 * Fires after save general settings.
553 *
554 * @since 4.1
555 */
556 do_action( 'mainwp_after_save_general_settings', $_POST );
557 }
558
559 return true;
560 }
561
562 return false;
563 }
564
565 /**
566 * Render the MainWP Settings Page.
567 *
568 * @uses \MainWP\Dashboard\MainWP_Monitoring_View
569 * @uses \MainWP\Dashboard\MainWP_Manage_Backups::render_settings()
570 * @uses \MainWP\Dashboard\MainWP_Utility::get_http_codes()
571 */
572 public static function render() { //phpcs:ignore -- NOSONAR - complex method.
573 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
574 \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
575 return;
576 }
577
578 static::render_header( '' );
579 ?>
580 <div id="mainwp-general-settings" class="ui segment">
581 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-general-settings-info-message' ) ) : ?>
582 <div class="ui info message">
583 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-general-settings-info-message"></i>
584 <?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>' ); ?>
585 </div>
586 <?php endif; ?>
587 <?php if ( isset( $_GET['message'] ) && 'saved' === $_GET['message'] ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
588 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
589 <?php endif; ?>
590 <div class="ui form">
591 <form method="POST" action="admin.php?page=Settings" id="mainwp-settings-page-form">
592 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
593 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'Settings' ) ); ?>" />
594 <?php
595 /**
596 * Action: mainwp_settings_form_top
597 *
598 * Fires at the top of settings form.
599 *
600 * @since 4.1
601 */
602 do_action( 'mainwp_settings_form_top' );
603 ?>
604 <h3 class="ui dividing header">
605 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-general' ); ?>
606 <?php esc_html_e( 'General Settings', 'mainwp' ); ?></h3>
607 <?php
608 $timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
609 $frequencyDailyUpdate = (int) get_option( 'mainwp_frequencyDailyUpdate', 2 );
610 $run_timestamp = MainWP_System_Cron_Jobs::get_timestamp_from_hh_mm( $timeDailyUpdate );
611 $delay_autoupdate = (int) get_option( 'mainwp_delay_autoupdate', 1 );
612
613 ?>
614 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general">
615 <label class="six wide column middle aligned">
616 <?php
617 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_timeDailyUpdate', $timeDailyUpdate );
618 esc_html_e( 'Daily sync time', 'mainwp' );
619 ?>
620 </label>
621 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose a specific time to initiate the first daily synchronization process.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
622 <div class="time-selector">
623 <div class="ui input left icon">
624 <i class="clock icon"></i>
625 <input type="text" class="settings-field-value-change-handler" current-utc-datetime="<?php echo esc_attr( gmdate( 'Y-m-d H:i:s' ) ); ?>" sync-time-local-datetime="<?php echo esc_attr( gmdate( 'Y-m-d H:i:s', $run_timestamp ) ); ?>" local-datetime="<?php echo esc_attr( gmdate( '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 ); ?>" />
626 </div>
627 </div>
628 </div>
629 </div>
630 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="2">
631 <label class="six wide column middle aligned">
632 <?php
633 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_frequencyDailyUpdate', $frequencyDailyUpdate );
634 esc_html_e( 'Frequency of auto sync', 'mainwp' );
635 ?>
636 </label>
637 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set the frequency for automatic synchronization throughout the day.', 'mainwp' ); ?>" data-inverted="" data-position="top left" >
638 <select name="mainwp_frequencyDailyUpdate" id="mainwp_frequencyDailyUpdate" class="ui dropdown settings-field-value-change-handler">
639 <option value="1" <?php echo 1 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Once per day', 'mainwp' ); ?></option>
640 <option value="2" <?php echo 2 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Twice per day', 'mainwp' ); ?></option>
641 <option value="3" <?php echo 3 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Three times per day', 'mainwp' ); ?></option>
642 <option value="4" <?php echo 4 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Four times per day', 'mainwp' ); ?></option>
643 <option value="5" <?php echo 5 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Five times per day', 'mainwp' ); ?></option>
644 <option value="6" <?php echo 6 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Six times per day', 'mainwp' ); ?></option>
645 <option value="7" <?php echo 7 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Seven times per day', 'mainwp' ); ?></option>
646 <option value="8" <?php echo 8 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Eight times per day', 'mainwp' ); ?></option>
647 <option value="9" <?php echo 9 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Nine times per day', 'mainwp' ); ?></option>
648 <option value="10" <?php echo 10 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Ten times per day', 'mainwp' ); ?></option>
649 <option value="11" <?php echo 11 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Eleven times per day', 'mainwp' ); ?></option>
650 <option value="12" <?php echo 12 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Twelve times per day', 'mainwp' ); ?></option>
651 </select>
652 </div>
653 </div>
654 <script type="text/javascript">
655 jQuery( document ).ready( function() {
656 jQuery( '.time-selector' ).calendar( {
657 type: 'time',
658 ampm: false,
659 formatter: {
660 time: 'H:mm',
661 cellTime: 'H:mm'
662 }
663 } );
664 } );
665 </script>
666
667 <?php
668
669 static::render_timezone_settings();
670 static::render_datetime_settings();
671
672 $sidebarPosition = get_user_option( 'mainwp_sidebarPosition' );
673 if ( false === $sidebarPosition ) {
674 $sidebarPosition = 1;
675 }
676
677 ?>
678 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="1">
679 <label class="six wide column middle aligned">
680 <?php
681 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_sidebarPosition', (int) $sidebarPosition );
682 esc_html_e( 'Sidebar position', 'mainwp' );
683 ?>
684 </label>
685 <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">
686 <select name="mainwp_sidebarPosition" id="mainwp_sidebarPosition" class="ui dropdown settings-field-value-change-handler">
687 <option value="1" <?php echo 1 === (int) $sidebarPosition ? 'selected' : ''; ?>><?php esc_html_e( 'Right (default)', 'mainwp' ); ?></option>
688 <option value="0" <?php echo 0 === (int) $sidebarPosition ? 'selected' : ''; ?>><?php esc_html_e( 'Left', 'mainwp' ); ?></option>
689 </select>
690 </div>
691 </div>
692 <?php MainWP_UI::render_screen_options(); ?>
693
694 <h3 class="ui dividing header">
695 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-updates' ); ?>
696 <?php esc_html_e( 'Updates Settings', 'mainwp' ); ?></h3>
697 <?php
698 $snAutomaticDailyUpdate = (int) get_option( 'mainwp_automaticDailyUpdate', 0 );
699 $snPluginAutomaticDailyUpdate = (int) get_option( 'mainwp_pluginAutomaticDailyUpdate', 0 );
700 $snThemeAutomaticDailyUpdate = (int) get_option( 'mainwp_themeAutomaticDailyUpdate', 0 );
701 $backup_before_upgrade = get_option( 'mainwp_backup_before_upgrade' );
702 $mainwp_backup_before_upgrade_days = get_option( 'mainwp_backup_before_upgrade_days' );
703 if ( empty( $mainwp_backup_before_upgrade_days ) || ! ctype_digit( $mainwp_backup_before_upgrade_days ) ) {
704 $mainwp_backup_before_upgrade_days = 7;
705 }
706 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
707 $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
708 $primaryBackup = get_option( 'mainwp_primaryBackup' );
709 $disableUpdateConfirmations = (int) get_option( 'mainwp_disable_update_confirmations', 0 );
710 ?>
711 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
712 <label class="six wide column middle aligned">
713 <?php
714 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_pluginAutomaticDailyUpdate', $snPluginAutomaticDailyUpdate );
715 esc_html_e( 'Plugin advanced automatic updates', 'mainwp' );
716 ?>
717 </label>
718 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic plugin updates. If enabled, MainWP will update only plugins that you have marked as Trusted.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
719 <select name="mainwp_pluginAutomaticDailyUpdate" id="mainwp_pluginAutomaticDailyUpdate" class="ui dropdown settings-field-value-change-handler">
720 <option value="1" <?php echo 1 === $snPluginAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
721 <option value="0" <?php echo 0 === $snPluginAutomaticDailyUpdate || 2 === $snPluginAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
722 </select>
723 </div>
724 </div>
725 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
726 <label class="six wide column middle aligned">
727 <?php
728 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_themeAutomaticDailyUpdate', $snThemeAutomaticDailyUpdate );
729 esc_html_e( 'Theme advanced automatic updates', 'mainwp' );
730 ?>
731 </label>
732 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic theme updates. If enabled, MainWP will update only themes that you have marked as Trusted.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
733 <select name="mainwp_themeAutomaticDailyUpdate" id="mainwp_themeAutomaticDailyUpdate" class="ui dropdown settings-field-value-change-handler">
734 <option value="1" <?php echo 1 === $snThemeAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
735 <option value="0" <?php echo 0 === $snThemeAutomaticDailyUpdate || 2 === $snThemeAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
736 </select>
737 </div>
738 </div>
739 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
740 <label class="six wide column middle aligned">
741 <?php
742 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_automaticDailyUpdate', $snAutomaticDailyUpdate );
743 esc_html_e( 'WP Core advanced automatic updates', 'mainwp' );
744 ?>
745 </label>
746 <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">
747 <select name="mainwp_automaticDailyUpdate" id="mainwp_automaticDailyUpdate" class="ui dropdown settings-field-value-change-handler">
748 <option value="1" <?php echo 1 === $snAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
749 <option value="0" <?php echo 0 === $snAutomaticDailyUpdate || 2 === (int) $snAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
750 </select>
751 </div>
752 </div>
753 <?php static::render_auto_updates_settings(); ?>
754 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates" default-indi-value="1">
755 <label class="six wide column middle aligned">
756 <?php
757 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_delay_autoupdate', $delay_autoupdate );
758 esc_html_e( 'Advanced automatic updates delay', 'mainwp' );
759 ?>
760 </label>
761 <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">
762 <select name="mainwp_delay_autoupdate" id="mainwp_delay_autoupdate" class="ui dropdown settings-field-value-change-handler">
763 <option value="0" <?php echo 0 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( 'Delay off', 'mainwp' ); ?></option>
764 <option value="1" <?php echo 1 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '1 day', 'mainwp' ); ?></option>
765 <option value="2" <?php echo 2 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '2 days', 'mainwp' ); ?></option>
766 <option value="3" <?php echo 3 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '3 days', 'mainwp' ); ?></option>
767 <option value="4" <?php echo 4 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '4 days', 'mainwp' ); ?></option>
768 <option value="5" <?php echo 5 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '5 days', 'mainwp' ); ?></option>
769 <option value="6" <?php echo 6 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '6 days', 'mainwp' ); ?></option>
770 <option value="7" <?php echo 7 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '7 days', 'mainwp' ); ?></option>
771 <option value="14" <?php echo 14 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '14 days', 'mainwp' ); ?></option>
772 <option value="30" <?php echo 30 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '30 days', 'mainwp' ); ?></option>
773 </select>
774 </div>
775 </div>
776 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates" default-indi-value="1">
777 <label class="six wide column middle aligned">
778 <?php
779 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_show_language_updates', $mainwp_show_language_updates );
780 esc_html_e( 'Show WordPress language updates', 'mainwp' );
781 ?>
782 </label>
783 <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">
784 <input type="checkbox" name="mainwp_show_language_updates" class="settings-field-value-change-handler" id="mainwp_show_language_updates" <?php echo 1 === (int) $mainwp_show_language_updates ? 'checked="true"' : ''; ?>/>
785 </div>
786 </div>
787 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
788 <label class="six wide column middle aligned">
789 <?php
790 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_disable_update_confirmations', $disableUpdateConfirmations );
791 esc_html_e( 'Update confirmations', 'mainwp' );
792 ?>
793 </label>
794 <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">
795 <select name="mainwp_disable_update_confirmations" id="mainwp_disable_update_confirmations" class="ui dropdown settings-field-value-change-handler">
796 <option value="0" <?php echo 0 === $disableUpdateConfirmations ? 'selected' : ''; ?>><?php esc_html_e( 'Enable', 'mainwp' ); ?></option>
797 <option value="2" <?php echo 2 === $disableUpdateConfirmations ? 'selected' : ''; ?>><?php esc_html_e( 'Disable', 'mainwp' ); ?></option>
798 <option value="1" <?php echo 1 === $disableUpdateConfirmations ? 'selected' : ''; ?>><?php esc_html_e( 'Disable for single updates', 'mainwp' ); ?></option>
799 </select>
800 </div>
801 </div>
802 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
803 <label class="six wide column middle aligned">
804 <?php
805 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_check_http_response', get_option( 'mainwp_check_http_response', '' ) );
806 esc_html_e( 'Check site HTTP response after update', 'mainwp' );
807 ?>
808 </label>
809 <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">
810 <input type="checkbox" class="settings-field-value-change-handler" inverted-value="1" name="mainwp_check_http_response" id="mainwp_check_http_response" <?php echo 1 === (int) get_option( 'mainwp_check_http_response', 0 ) ? 'checked="true"' : ''; ?>/>
811 </div>
812 </div>
813
814 <?php if ( ( $enableLegacyBackupFeature && empty( $primaryBackup ) ) || ( empty( $enableLegacyBackupFeature ) && ! empty( $primaryBackup ) ) ) { ?>
815 <div class="ui grid field mainwp-parent-toggle settings-field-indicator-wrapper settings-field-indicator-updates">
816 <label class="six wide column middle aligned">
817 <?php
818 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_backup_before_upgrade', (int) $backup_before_upgrade );
819 esc_html_e( 'Require a backup before an update', 'mainwp' );
820 ?>
821 </label>
822 <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">
823 <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_backup_before_upgrade" id="mainwp_backup_before_upgrade" <?php echo 1 === (int) $backup_before_upgrade ? 'checked="true"' : ''; ?>/>
824 </div>
825 </div>
826 <div class="ui grid field mainwp-child-field settings-field-indicator-wrapper settings-field-indicator-updates" default-indi-value="7" <?php echo 1 === (int) $backup_before_upgrade ? '' : 'style="display:none"'; ?> >
827 <label class="six wide column middle aligned">
828 <?php
829 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_backup_before_upgrade_days', (int) $mainwp_backup_before_upgrade_days );
830 esc_html_e( 'Days without of a full backup tolerance', 'mainwp' );
831 ?>
832 </label>
833 <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">
834 <input type="text" class="settings-field-value-change-handler" name="mainwp_backup_before_upgrade_days" id="mainwp_backup_before_upgrade_days" value="<?php echo esc_attr( $mainwp_backup_before_upgrade_days ); ?>" />
835 </div>
836 </div>
837 <?php } ?>
838
839 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates" default-indi-value="365">
840 <label class="six wide column middle aligned">
841 <?php
842 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_numberdays_Outdate_Plugin_Theme', (int) get_option( 'mainwp_numberdays_Outdate_Plugin_Theme', 365 ) );
843
844 esc_html_e( 'Abandoned plugins/themes tolerance', 'mainwp' );
845 ?>
846 </label>
847 <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">
848 <input type="text" class="settings-field-value-change-handler" 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' ) ); ?>"/>
849 </div>
850 </div>
851 <?php MainWP_Monitoring_View::render_settings(); ?>
852 <?php MainWP_Manage_Backups::render_settings(); ?>
853 <?php
854 /**
855 * Action: mainwp_settings_form_bottom
856 *
857 * Fires at the bottom of settings form.
858 *
859 * @since 4.1
860 */
861 do_action( 'mainwp_settings_form_bottom' );
862 ?>
863 <div class="ui divider"></div>
864 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
865 <div style="clear:both"></div>
866 </form>
867 </div>
868 </div>
869 <?php
870 static::render_footer( '' );
871 }
872
873 /**
874 * Method render_auto_updates_settings().
875 */
876 public static function render_auto_updates_settings() { // phpcs:ignore -- NOSONAR - complex.
877
878 $time_AutoUpdate = get_option( 'mainwp_time_AutoUpdate' );
879 $dayinweek_AutoUpdate = (int) get_option( 'mainwp_dayinweek_AutoUpdate', 0 );
880 $dayinmonth_AutoUpdate = (int) get_option( 'mainwp_dayinmonth_AutoUpdate', 1 );
881 $frequency_AutoUpdate = get_option( 'mainwp_frequency_AutoUpdate', 'daily' );
882
883 if ( empty( $time_AutoUpdate ) ) {
884 $time_AutoUpdate = '00:00';
885 }
886
887 if ( ! in_array( $frequency_AutoUpdate, array( 'daily', 'weekly', 'monthly' ) ) ) {
888 $frequency_AutoUpdate = 'daily';
889 }
890
891 ?>
892 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="daily">
893 <label class="six wide column middle aligned">
894 <?php
895 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_frequency_AutoUpdate', $frequency_AutoUpdate );
896 esc_html_e( 'Frequency of automatic updates', 'mainwp' );
897 ?>
898 </label>
899 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set the frequency for automatic updates process.', 'mainwp' ); ?>" data-inverted="" data-position="top left" >
900 <select name="mainwp_frequency_AutoUpdate" id="mainwp_frequency_AutoUpdate" class="ui dropdown settings-field-value-change-handler">
901 <option value="daily" <?php echo 'daily' === $frequency_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Daily', 'mainwp' ); ?></option>
902 <option value="weekly" <?php echo 'weekly' === $frequency_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Weekly', 'mainwp' ); ?></option>
903 <option value="monthly" <?php echo 'monthly' === $frequency_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Monthly', 'mainwp' ); ?></option>
904 </select>
905 </div>
906 </div>
907
908 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" id="mainwp-dayinmonth-autoupdate-wrapper" <?php echo in_array( $frequency_AutoUpdate, array( 'monthly' ) ) ? '' : 'style="display:none;"'; ?>>
909 <label class="six wide column middle aligned">
910 <?php
911 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_dayinmonth_AutoUpdate', $dayinmonth_AutoUpdate );
912 esc_html_e( 'Select day', 'mainwp' );
913 ?>
914 </label>
915 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose a specific day in month to initiate automatic updates process.', 'mainwp' ); ?>" data-inverted="" data-position="top left" >
916 <select name="mainwp_dayinmonth_AutoUpdate" id="mainwp_dayinmonth_AutoUpdate" class="ui dropdown settings-field-value-change-handler">
917 <?php
918 $day_suffix = array(
919 1 => 'st',
920 2 => 'nd',
921 3 => 'rd',
922 );
923 for ( $x = 1; $x <= 31; $x++ ) {
924 $_select = '';
925 if ( $dayinmonth_AutoUpdate === $x ) {
926 $_select = 'selected';
927 }
928 $remain = $x % 10;
929 $day_sf = isset( $day_suffix[ $remain ] ) ? $day_suffix[ $remain ] : 'th';
930 echo '<option value="' . intval( $x ) . '" ' . esc_html( $_select ) . '>' . esc_html( $x . $day_sf ) . ' of the month</option>';
931 }
932 ?>
933 </select>
934 </div>
935 </div>
936
937 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" id="mainwp-dayinweek-autoupdate-wrapper" <?php echo in_array( $frequency_AutoUpdate, array( 'weekly' ) ) ? '' : 'style="display:none;"'; ?>>
938 <label class="six wide column middle aligned">
939 <?php
940 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_dayinweek_AutoUpdate', $dayinweek_AutoUpdate );
941 esc_html_e( 'Select day', 'mainwp' );
942 ?>
943 </label>
944 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose a specific day in week to initiate automatic updates process.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
945 <select name="mainwp_dayinweek_AutoUpdate" id="mainwp_dayinweek_AutoUpdate" class="ui dropdown settings-field-value-change-handler">
946 <option value="0" <?php echo 0 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Mon', 'mainwp' ); ?></option>
947 <option value="1" <?php echo 1 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Tue', 'mainwp' ); ?></option>
948 <option value="2" <?php echo 2 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Wed', 'mainwp' ); ?></option>
949 <option value="3" <?php echo 3 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Thus', 'mainwp' ); ?></option>
950 <option value="4" <?php echo 4 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Fri', 'mainwp' ); ?></option>
951 <option value="5" <?php echo 5 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Sat', 'mainwp' ); ?></option>
952 <option value="6" <?php echo 6 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Sun', 'mainwp' ); ?></option>
953 </select>
954 </div>
955 </div>
956 <div id="mainwp-time-autoupdate-wrapper" class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="00:00">
957 <label class="six wide column middle aligned">
958 <?php
959 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_time_AutoUpdate', $time_AutoUpdate );
960 esc_html_e( 'Select time', 'mainwp' );
961 $_last_start_auto_updates = get_option( 'mainwp_automatic_updates_start_lasttime', 0 );
962 $_next_auto_updates = get_option( 'mainwp_automatic_update_next_run_timestamp', 0 );
963 ?>
964 </label>
965 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose a specific time to initiate automatic updates process.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
966 <div class="time-selector">
967 <div class="ui input left icon">
968 <i class="clock icon"></i>
969 <input type="text" class="settings-field-value-change-handler" current-utc-datetime="<?php echo date( 'Y-m-d H:i:s' ); ?>" auto-updates-last-start-time="<?php echo date( 'Y-m-d H:i:s', $_last_start_auto_updates ); ?>" auto-updates-next-time="<?php echo date( 'Y-m-d H:i:s', $_next_auto_updates ); ?>" local-datetime="<?php echo date( 'Y-m-d H:i:s', MainWP_Utility::get_timestamp() ); // phpcs:ignore -- to get local time. ?>" name="mainwp_time_AutoUpdate" id="mainwp_time_AutoUpdate" value="<?php echo esc_attr( $time_AutoUpdate ); ?>" />
970 </div>
971 </div>
972 </div>
973 </div>
974 <script type="text/javascript">
975 jQuery(document).on('change', '#mainwp_frequency_AutoUpdate', function () {
976 if( jQuery(this).val() == 'monthly' ){
977 jQuery('#mainwp-dayinweek-autoupdate-wrapper').hide();
978 jQuery('#mainwp-dayinmonth-autoupdate-wrapper').show();
979 } else if( jQuery(this).val() == 'weekly'){
980 jQuery('#mainwp-dayinweek-autoupdate-wrapper').show();
981 jQuery('#mainwp-dayinmonth-autoupdate-wrapper').hide();
982 } else {
983 jQuery('#mainwp-dayinweek-autoupdate-wrapper').hide();
984 jQuery('#mainwp-dayinmonth-autoupdate-wrapper').hide();
985 }
986 });
987 </script>
988 <?php
989 }
990
991 /**
992 * Render Timezone settings.
993 */
994 public static function render_timezone_settings() { // phpcs:ignore -- NOSONAR - complex.
995
996 $current_offset = get_option( 'gmt_offset' );
997 $tzstring = get_option( 'timezone_string' );
998 $check_zone_info = true;
999
1000 // Remove old Etc mappings. Fallback to gmt_offset.
1001 if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
1002 $tzstring = '';
1003 }
1004
1005 if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists.
1006 $check_zone_info = false;
1007 if ( empty( $current_offset ) ) {
1008 $tzstring = 'UTC+0';
1009 } elseif ( $current_offset < 0 ) {
1010 $tzstring = 'UTC' . $current_offset;
1011 } else {
1012 $tzstring = 'UTC+' . $current_offset;
1013 }
1014 }
1015
1016 $timezone_format = _x( 'Y-m-d H:i:s', 'timezone date format' );
1017
1018 ?>
1019 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general">
1020 <label class="six wide column middle aligned"><?php esc_html_e( 'Timezone', 'mainwp' ); ?></label>
1021 <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">
1022 <select id="timezone_string" class="ui dropdown" name="timezone_string" aria-describedby="timezone-description">
1023 <?php echo wp_timezone_choice( $tzstring, get_user_locale() ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
1024 </select>
1025 <div class="ui hidden fitted divider"></div>
1026 <div class="ui secondary segment">
1027 <?php printf( esc_html__( 'Universal time is %s.' ), '<code>' . esc_html( date_i18n( $timezone_format, false, true ) ) . '</code>' ); ?>
1028 <div class="ui hidden fitted divider"></div>
1029 <?php if ( get_option( 'timezone_string' ) || ! empty( $current_offset ) ) : ?>
1030 <?php printf( esc_html__( 'Local time is %s.' ), '<code>' . esc_html( date_i18n( $timezone_format ) ) . '</code>' ); ?>
1031 <div class="ui hidden fitted divider"></div>
1032 <?php endif; ?>
1033 <?php if ( $check_zone_info && $tzstring ) : ?>
1034 <?php
1035 $now = new \DateTime( 'now', new \DateTimeZone( $tzstring ) );
1036 $dst = (bool) $now->format( 'I' );
1037
1038 if ( $dst ) {
1039 esc_html_e( 'This timezone is currently in daylight saving time.', 'mainwp' );
1040 } else {
1041 esc_html_e( 'This timezone is currently in standard time.', 'mainwp' );
1042 }
1043 ?>
1044 <div class="ui hidden fitted divider"></div>
1045 <?php
1046 if ( in_array( $tzstring, timezone_identifiers_list(), true ) ) {
1047 $transitions = timezone_transitions_get( timezone_open( $tzstring ), time() );
1048
1049 if ( ! empty( $transitions[1] ) ) {
1050 echo ' ';
1051 $message = $transitions[1]['isdst'] ? esc_html__( 'Daylight saving time begins on: %s.', 'mainwp' ) : esc_html__( 'Standard time begins on: %s.', 'mainwp' );
1052 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
1053 } else {
1054 esc_html_e( 'This timezone does not observe daylight saving time.', 'mainwp' );
1055 }
1056 }
1057 ?>
1058 <?php endif; ?>
1059 </div>
1060 </div>
1061 </div>
1062 <?php
1063 }
1064
1065 /**
1066 * Render Date/Time settings.
1067 */
1068 public static function render_datetime_settings() {
1069 ?>
1070 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="F j, Y">
1071 <label class="six wide column middle aligned">
1072 <?php
1073 MainWP_Settings_Indicator::render_not_default_indicator( 'date_format', get_option( 'date_format' ) );
1074 esc_html_e( 'Date format', 'mainwp' );
1075 ?>
1076 </label>
1077 <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">
1078 <?php
1079 /**
1080 * Filters the default date formats.
1081 *
1082 * @since 2.7.0
1083 * @since 4.0.0 Added ISO date standard YYYY-MM-DD format.
1084 *
1085 * @param string[] $default_date_formats Array of default date formats.
1086 */
1087 $date_formats = array_unique( apply_filters( 'date_formats', array( esc_html__( 'F j, Y' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) );
1088
1089 $custom = true;
1090
1091 foreach ( $date_formats as $format ) {
1092 echo "\t<label><input type='radio' name='date_format' value='" . esc_attr( $format ) . "'";
1093 if ( get_option( 'date_format' ) === $format ) { // checked() uses "==" rather than "===".
1094 echo " checked='checked'";
1095 $custom = false;
1096 }
1097 echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
1098 }
1099 echo '<label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
1100 checked( $custom );
1101 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>' .
1102 '<label for="date_format_custom" class="screen-reader-text">' . esc_html__( 'Custom date format:' ) . '</label>' .
1103 '<input type="text" name="date_format_custom" id="date_format_custom" value="' . esc_attr( get_option( 'date_format' ) ) . '" class="small-text settings-field-value-change-handler" />' .
1104 '<br />' .
1105 '<em><strong>' . esc_html__( 'Preview:' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'date_format' ) ) ) . '</span>' .
1106 "<span class='spinner'></span>\n" . '</em>';
1107 ?>
1108 </div>
1109 </div>
1110
1111 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="g:i a">
1112 <label class="six wide column middle aligned">
1113 <?php
1114 MainWP_Settings_Indicator::render_not_default_indicator( 'time_format', get_option( 'time_format' ) );
1115 esc_html_e( 'Time format', 'mainwp' );
1116 ?>
1117 </label>
1118 <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">
1119 <?php
1120 /**
1121 * Filters the default time formats.
1122 *
1123 * @since 2.7.0
1124 *
1125 * @param string[] $default_time_formats Array of default time formats.
1126 */
1127 $time_formats = array_unique( apply_filters( 'time_formats', array( esc_html__( 'g:i a' ), 'g:i A', 'H:i' ) ) );
1128
1129 $custom = true;
1130
1131 foreach ( $time_formats as $format ) {
1132 echo "\t<label><input type='radio' name='time_format' value='" . esc_attr( $format ) . "'";
1133 if ( get_option( 'time_format' ) === $format ) { // checked() uses "==" rather than "===".
1134 echo " checked='checked'";
1135 $custom = false;
1136 }
1137 echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
1138 }
1139 echo '<label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
1140 checked( $custom );
1141 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>' .
1142 '<label for="time_format_custom" class="screen-reader-text">' . esc_html__( 'Custom time format:' ) . '</label>' .
1143 '<input type="text" class="small-text settings-field-value-change-handler" name="time_format_custom" id="time_format_custom" value="' . esc_attr( get_option( 'time_format' ) ) . '" />' .
1144 '<br />' .
1145 '<em><strong>' . esc_html__( 'Preview:' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'time_format' ) ) ) . '</span>' .
1146 "<span class='spinner'></span>\n" . '</em>';
1147 ?>
1148 </div>
1149 </div>
1150 <script type="text/javascript">
1151 jQuery(function($) {
1152 $( 'input[name="date_format"]' ).on( 'click', function() {
1153 if ( 'date_format_custom_radio' !== $( this ).attr( 'id' ) ){
1154 $( 'input[name="date_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
1155 $( 'input[name="date_format_custom"]' ).trigger("change"); // support indicator.
1156 }
1157 } );
1158
1159 $( 'input[name="date_format_custom"]' ).on( 'click input', function() {
1160 $( '#date_format_custom_radio' ).prop( 'checked', true );
1161 } );
1162
1163 $( 'input[name="time_format"]' ).on( 'click', function() {
1164 if ( 'time_format_custom_radio' !== $(this).attr( 'id' ) ){
1165 $( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
1166 $( 'input[name="time_format_custom"]' ).trigger("change"); // support indicator.
1167 }
1168 } );
1169
1170 $( 'input[name="time_format_custom"]' ).on( 'click input', function() {
1171 $( '#time_format_custom_radio' ).prop( 'checked', true );
1172 } );
1173
1174 $( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() {
1175 let format = $( this ),
1176 fieldset = format.closest( '.fieldset-wrapper' ),
1177 example = fieldset.find( '.example' ),
1178 spinner = fieldset.find( '.spinner' );
1179
1180 // Debounce the event callback while users are typing.
1181 clearTimeout( $.data( this, 'timer' ) );
1182 $( this ).data( 'timer', setTimeout( function() {
1183 // If custom date is not empty.
1184 if ( format.val() ) {
1185 spinner.addClass( 'is-active' );
1186
1187 $.post( ajaxurl, {
1188 action: 'date_format_custom' === format.attr( 'name' ) ? 'date_format' : 'time_format',
1189 date : format.val()
1190 }, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
1191 }
1192 }, 500 ) );
1193 } );
1194 });
1195 </script>
1196 <?php
1197 }
1198
1199 /**
1200 * Method get_websites_automatic_update_time()
1201 *
1202 * Get websites automatic update time.
1203 *
1204 * @return mixed array
1205 *
1206 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
1207 */
1208 public static function get_websites_automatic_update_time() {
1209 $lastAutomaticUpdate = MainWP_Auto_Updates_DB::instance()->get_websites_last_automatic_sync();
1210 $lasttimeAutomatic = get_option( 'mainwp_updatescheck_last_timestamp' );
1211 $lasttimeStartAutomatic = get_option( 'mainwp_updatescheck_start_last_timestamp' );
1212 $local_timestamp = MainWP_Utility::get_timestamp();
1213 $running = get_option( 'mainwp_cron_checksites_running' );
1214
1215 if ( empty( $lasttimeStartAutomatic ) && ! empty( $lasttimeAutomatic ) ) {
1216 $lasttimeStartAutomatic = $lasttimeAutomatic;
1217 }
1218
1219 if ( empty( $lastAutomaticUpdate ) ) {
1220 $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1221 } elseif ( 'yes' === $running && ( 0 < MainWP_Auto_Updates_DB::instance()->get_websites_count_where_dts_automatic_sync_smaller_then_start( $lasttimeStartAutomatic ) || 0 < MainWP_Auto_Updates_DB::instance()->get_websites_check_updates_count( $lasttimeStartAutomatic ) ) ) {
1222 $nextAutomaticUpdate = esc_html__( 'Processing your websites.', 'mainwp' );
1223 } else {
1224 $next_time = MainWP_System_Cron_Jobs::get_next_time_automatic_update_to_show();
1225 if ( $next_time < $local_timestamp + 5 * MINUTE_IN_SECONDS ) {
1226 $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1227 } else {
1228 $nextAutomaticUpdate = MainWP_Utility::format_timestamp( $next_time );
1229 }
1230 }
1231
1232 if ( empty( $lastAutomaticUpdate ) ) {
1233 $lastAutomaticUpdate = esc_html__( 'Never', 'mainwp' );
1234 } else {
1235 $lastAutomaticUpdate = MainWP_Utility::format_timestamp( $lastAutomaticUpdate );
1236 }
1237
1238 return array(
1239 'last' => $lastAutomaticUpdate,
1240 'next' => $nextAutomaticUpdate,
1241 );
1242 }
1243
1244 /**
1245 * Returns false or the location of the OpenSSL Lib File.
1246 *
1247 * @return mixed false|opensslLibLocation
1248 *
1249 * @uses \MainWP\Dashboard\MainWP_Server_Information_Handler::is_openssl_config_warning()
1250 */
1251 public static function show_openssl_lib_config() {
1252 return MainWP_Server_Information_Handler::is_openssl_config_warning() ? true : false;
1253 }
1254
1255 /**
1256 * Render Advanced Options Subpage.
1257 *
1258 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
1259 */
1260 public static function render_advanced() { //phpcs:ignore -- NOSONAR - complex method.
1261 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
1262 \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
1263 return;
1264 }
1265
1266 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) {
1267
1268 /**
1269 * Action: mainwp_before_save_advanced_settings
1270 *
1271 * Fires before save advanced settings.
1272 *
1273 * @since 4.1
1274 */
1275 do_action( 'mainwp_before_save_advanced_settings', $_POST );
1276
1277 MainWP_Utility::update_option( 'mainwp_maximumRequests', ! empty( $_POST['mainwp_maximumRequests'] ) ? intval( $_POST['mainwp_maximumRequests'] ) : 4 );
1278 MainWP_Utility::update_option( 'mainwp_minimumDelay', ! empty( $_POST['mainwp_minimumDelay'] ) ? intval( $_POST['mainwp_minimumDelay'] ) : 200 );
1279 MainWP_Utility::update_option( 'mainwp_maximumIPRequests', ! empty( $_POST['mainwp_maximumIPRequests'] ) ? intval( $_POST['mainwp_maximumIPRequests'] ) : 1 );
1280 MainWP_Utility::update_option( 'mainwp_minimumIPDelay', ! empty( $_POST['mainwp_minimumIPDelay'] ) ? intval( $_POST['mainwp_minimumIPDelay'] ) : 1000 );
1281 MainWP_Utility::update_option( 'mainwp_maximumSyncRequests', ! empty( $_POST['mainwp_maximumSyncRequests'] ) ? intval( $_POST['mainwp_maximumSyncRequests'] ) : 8 );
1282 MainWP_Utility::update_option( 'mainwp_maximumInstallUpdateRequests', ! empty( $_POST['mainwp_maximumInstallUpdateRequests'] ) ? intval( $_POST['mainwp_maximumInstallUpdateRequests'] ) : 3 );
1283 MainWP_Utility::update_option( 'mainwp_sslVerifyCertificate', isset( $_POST['mainwp_sslVerifyCertificate'] ) ? 1 : 0 );
1284 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 );
1285 MainWP_Utility::update_option( 'mainwp_verify_connection_method', isset( $_POST['mainwp_settings_verify_connection_method'] ) ? intval( $_POST['mainwp_settings_verify_connection_method'] ) : 0 );
1286 MainWP_Utility::update_option( 'mainwp_forceUseIPv4', isset( $_POST['mainwp_forceUseIPv4'] ) ? 1 : 0 );
1287 $use_wpcron = ! isset( $_POST['mainwp_options_wp_cron'] ) ? 0 : 1;
1288 MainWP_Utility::update_option( 'mainwp_wp_cron', $use_wpcron );
1289 MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) );
1290 MainWP_Utility::update_option( 'mainwp_maximum_uptime_monitoring_requests', ! empty( $_POST['mainwp_maximumUptimeMonitoringRequests'] ) ? intval( $_POST['mainwp_maximumUptimeMonitoringRequests'] ) : 10 );
1291
1292 // required check.
1293 MainWP_Uptime_Monitoring_Schedule::instance()->check_to_disable_schedule_individual_uptime_monitoring(); // required a check to sync the settings.
1294
1295 if ( isset( $_POST['mainwp_openssl_lib_location'] ) ) {
1296 $openssl_loc = ! empty( $_POST['mainwp_openssl_lib_location'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_openssl_lib_location'] ) ) : '';
1297 MainWP_Utility::update_option( 'mainwp_opensslLibLocation', $openssl_loc );
1298 }
1299
1300 /**
1301 * Action: mainwp_after_save_advanced_settings
1302 *
1303 * Fires after advanced settings save.
1304 *
1305 * @since 4.1
1306 */
1307 do_action( 'mainwp_after_save_advanced_settings', $_POST );
1308 }
1309 static::render_header( 'Advanced' );
1310 ?>
1311
1312 <div id="mainwp-advanced-settings" class="ui segment">
1313 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-advanced-settings-info-notice' ) ) : ?>
1314 <div class="ui info message">
1315 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-advanced-settings-info-notice"></i>
1316 <?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' ); ?>
1317 </div>
1318 <?php endif; ?>
1319 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) : ?>
1320 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
1321 <?php endif; ?>
1322 <div class="ui form">
1323 <form method="POST" action="">
1324 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1325 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'SettingsAdvanced' ) ); ?>" />
1326 <?php
1327
1328 /**
1329 * Action: mainwp_advanced_settings_form_top
1330 *
1331 * Fires at the top of advanced settings form.
1332 *
1333 * @since 4.1
1334 */
1335 do_action( 'mainwp_advanced_settings_form_top' );
1336
1337 if ( static::show_openssl_lib_config() ) {
1338 $openssl_loc = MainWP_System_Utility::get_openssl_conf();
1339 ?>
1340 <h3 class="ui dividing header">
1341 <?php esc_html_e( 'OpenSSL Settings', 'mainwp' ); ?>
1342 <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>
1343 </h3>
1344 <div class="ui grid field">
1345 <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL.cnf location', 'mainwp' ); ?></label>
1346 <div class="ten wide column ui field">
1347 <input type="text" name="mainwp_openssl_lib_location" value="<?php echo esc_html( $openssl_loc ); ?>">
1348 <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>
1349 <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>
1350 </div>
1351 </div>
1352 <?php } ?>
1353
1354 <h3 class="ui dividing header">
1355 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-cross-ip' ); ?>
1356 <?php esc_html_e( 'Cross IP Settings', 'mainwp' ); ?></h3>
1357
1358 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cross-ip" default-indi-value="4">
1359 <label class="six wide column middle aligned">
1360 <?php
1361 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumRequests', (int) get_option( 'mainwp_maximumRequests', 4 ) );
1362 esc_html_e( 'Maximum simultaneous requests (Default: 4)', 'mainwp' );
1363 ?>
1364 </label>
1365 <div class="ten wide column" 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">
1366 <div class="ui bottom aligned labeled slider" id="mainwp_maximumRequests_slider"></div>
1367 <div class="ui input">
1368 <input type="hidden" class="settings-field-value-change-handler" name="mainwp_maximumRequests" id="mainwp_maximumRequests" value="<?php echo false === get_option( 'mainwp_maximumRequests' ) ? 4 : esc_attr( get_option( 'mainwp_maximumRequests' ) ); ?>"/>
1369 </div>
1370 </div>
1371 </div>
1372
1373 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cross-ip" default-indi-value="200">
1374 <label class="six wide column middle aligned">
1375 <?php
1376 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_minimumDelay', (int) get_option( 'mainwp_minimumDelay', 200 ) );
1377 esc_html_e( 'Minimum delay between requests in milliseconds (Default: 200ms)', 'mainwp' );
1378 ?>
1379 </label>
1380 <div class="ten wide column" 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">
1381 <div class="ui bottom aligned labeled slider" id="mainwp_minimumDelay_slider"></div>
1382 <div class="ui input">
1383 <input type="hidden" class="settings-field-value-change-handler" name="mainwp_minimumDelay" id="mainwp_minimumDelay" value="<?php echo false === get_option( 'mainwp_minimumDelay' ) ? 200 : esc_attr( get_option( 'mainwp_minimumDelay' ) ); ?>"/>
1384 </div>
1385 </div>
1386 </div>
1387
1388 <h3 class="ui dividing header">
1389 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-per-ip' ); ?>
1390 <?php esc_html_e( 'Per IP Settings', 'mainwp' ); ?></h3>
1391
1392 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-per-ip" default-indi-value="1">
1393 <label class="six wide column middle aligned">
1394 <?php
1395 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumIPRequests', (int) get_option( 'mainwp_maximumIPRequests', 1 ) );
1396 esc_html_e( 'Maximum simultaneous requests per IP (Default: 1)', 'mainwp' );
1397 ?>
1398 </label>
1399 <div class="ten wide column" 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">
1400 <div class="ui bottom aligned labeled slider" id="mainwp_maximumIPRequests_slider"></div>
1401 <div class="ui input">
1402 <input type="hidden" class="settings-field-value-change-handler" name="mainwp_maximumIPRequests" id="mainwp_maximumIPRequests" value="<?php echo false === get_option( 'mainwp_maximumIPRequests' ) ? 1 : esc_attr( get_option( 'mainwp_maximumIPRequests' ) ); ?>"/>
1403 </div>
1404 </div>
1405 </div>
1406
1407 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-per-ip" default-indi-value="1000">
1408 <label class="six wide column middle aligned">
1409 <?php
1410 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_minimumIPDelay', (int) get_option( 'mainwp_minimumIPDelay', 1000 ) );
1411 esc_html_e( 'Minimum delay between requests to the same IP in milliseconds (Default: 1000ms)', 'mainwp' );
1412 ?>
1413 </label>
1414 <div class="ten wide column" 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">
1415 <div class="ui bottom aligned labeled slider" id="mainwp_minimumIPDelay_slider"></div>
1416 <div class="ui input">
1417 <input type="hidden" class="settings-field-value-change-handler" name="mainwp_minimumIPDelay" id="mainwp_minimumIPDelay" value="<?php echo false === get_option( 'mainwp_minimumIPDelay' ) ? 1000 : esc_attr( get_option( 'mainwp_minimumIPDelay' ) ); ?>"/>
1418 </div>
1419 </div>
1420 </div>
1421
1422 <h3 class="ui dividing header">
1423 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-frontend-request' ); ?>
1424 <?php esc_html_e( 'Frontend Request Settings', 'mainwp' ); ?></h3>
1425
1426 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-frontend-request" default-indi-value="8">
1427 <label class="six wide column middle aligned">
1428 <?php
1429 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumSyncRequests', (int) get_option( 'mainwp_maximumSyncRequests', 8 ) );
1430 esc_html_e( 'Maximum simultaneous sync requests (Default: 8)', 'mainwp' );
1431 ?>
1432 </label>
1433 <div class="ten wide column" 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">
1434 <div class="ui bottom aligned labeled slider" id="mainwp_maximumSyncRequests_slider"></div>
1435 <div class="ui input">
1436 <input type="hidden" class="settings-field-value-change-handler" name="mainwp_maximumSyncRequests" id="mainwp_maximumSyncRequests" value="<?php echo false === get_option( 'mainwp_maximumSyncRequests' ) ? 8 : esc_attr( get_option( 'mainwp_maximumSyncRequests' ) ); ?>"/>
1437 </div>
1438 </div>
1439 </div>
1440
1441 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-frontend-request" default-indi-value="3">
1442 <label class="six wide column middle aligned">
1443 <?php
1444 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumInstallUpdateRequests', (int) get_option( 'mainwp_maximumInstallUpdateRequests', 3 ) );
1445 esc_html_e( 'Maximum simultaneous install and update requests (Default: 3)', 'mainwp' );
1446 ?>
1447 </label>
1448 <div class="ten wide column" 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">
1449 <div class="ui bottom aligned labeled slider" id="mainwp_maximumInstallUpdateRequests_slider"></div>
1450 <div class="ui input">
1451 <input type="hidden" class="settings-field-value-change-handler" name="mainwp_maximumInstallUpdateRequests" id="mainwp_maximumInstallUpdateRequests" value="<?php echo false === get_option( 'mainwp_maximumInstallUpdateRequests' ) ? 3 : esc_attr( get_option( 'mainwp_maximumInstallUpdateRequests' ) ); ?>"/>
1452 </div>
1453 </div>
1454 </div>
1455
1456 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-frontend-request" default-indi-value="10">
1457 <label class="six wide column middle aligned">
1458 <?php
1459 $maximum_monitoring_requests = (int) get_option( 'mainwp_maximum_uptime_monitoring_requests', 10 );
1460 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximum_uptime_monitoring_requests', $maximum_monitoring_requests );
1461 esc_html_e( 'Maximum simultaneous uptime monitoring requests (Default: 10)', 'mainwp' );
1462 ?>
1463 </label>
1464 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'This option allows you to control how many uptime monitoring requests your MainWP Dashboard should process at once.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1465 <div class="ui bottom aligned labeled slider settings-field-value-change-handler" id="mainwp_maximumUptimeMonitoringRequests_slider"></div>
1466 <div class="ui input">
1467 <input type="hidden" class="settings-field-value-change-handler" name="mainwp_maximumUptimeMonitoringRequests" id="mainwp_maximumUptimeMonitoringRequests" value="<?php echo false === get_option( 'mainwp_maximum_uptime_monitoring_requests' ) ? 10 : esc_attr( get_option( 'mainwp_maximum_uptime_monitoring_requests' ) ); ?>"/>
1468 </div>
1469 </div>
1470 </div>
1471
1472 <h3 class="ui dividing header">
1473 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-miscellaneous' ); ?>
1474 <?php esc_html_e( 'Miscellaneous Settings', 'mainwp' ); ?></h3>
1475 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1">
1476 <label class="six wide column middle aligned">
1477 <?php
1478 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_optimize', (int) get_option( 'mainwp_optimize', 1 ) );
1479 esc_html_e( 'Optimize data loading', 'mainwp' );
1480 ?>
1481 </label>
1482 <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">
1483 <input type="checkbox" class="settings-field-value-change-handler" 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>
1484 </div>
1485 </div>
1486 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1">
1487 <label class="six wide column middle aligned">
1488 <?php
1489 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_wp_cron', (int) get_option( 'mainwp_wp_cron', 1 ) );
1490 esc_html_e( 'Use WP Cron', 'mainwp' );
1491 ?>
1492 </label>
1493 <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">
1494 <input type="checkbox" class="settings-field-value-change-handler" 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>
1495 </div>
1496 </div>
1497 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1" >
1498 <label class="six wide column middle aligned">
1499 <?php
1500 $indi_val = (int) get_option( 'mainwp_sslVerifyCertificate', 1 );
1501 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_sslVerifyCertificate', $indi_val );
1502 esc_html_e( 'Verify SSL certificate', 'mainwp' );
1503 ?>
1504 </label>
1505 <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">
1506 <input type="checkbox" class="settings-field-value-change-handler" 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>
1507 </div>
1508 </div>
1509 <?php
1510 $general_verify_con = (int) get_option( 'mainwp_verify_connection_method', 1 );
1511 ?>
1512 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1">
1513 <label class="six wide column middle aligned">
1514 <?php
1515 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_verify_connection_method', (int) $general_verify_con );
1516 esc_html_e( 'Verify connection method', 'mainwp' );
1517 ?>
1518 </label>
1519 <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">
1520 <select class="ui dropdown settings-field-value-change-handler" id="mainwp_settings_verify_connection_method" name="mainwp_settings_verify_connection_method">
1521 <option <?php echo ( empty( $general_verify_con ) || 1 === $general_verify_con ) ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'OpenSSL (default)', 'mainwp' ); ?></option>
1522 <option <?php echo ( 2 === $general_verify_con ) ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'PHPSECLIB (fallback)', 'mainwp' ); ?></option>
1523 </select>
1524 </div>
1525 </div>
1526 <?php
1527 $sign_note = MainWP_Connect_Lib::get_connection_algo_settings_note();
1528 $sign_algs = MainWP_System_Utility::get_open_ssl_sign_algos();
1529 $general_sign_alg = get_option( 'mainwp_connect_signature_algo', false );
1530 if ( false === $general_sign_alg ) {
1531 $general_sign_alg = defined( 'OPENSSL_ALGO_SHA256' ) ? OPENSSL_ALGO_SHA256 : 1;
1532 MainWP_Utility::update_option( 'mainwp_connect_signature_algo', $general_sign_alg );
1533 } else {
1534 $general_sign_alg = intval( $general_sign_alg );
1535 }
1536 $algo_def = defined( 'OPENSSL_ALGO_SHA256' ) ? (int) OPENSSL_ALGO_SHA256 : 1;
1537 ?>
1538 <div default-indi-value="<?php echo esc_attr( $algo_def ); ?>" class="ui grid field mainwp-hide-elemenent-sign-algo settings-field-indicator-wrapper settings-field-indicator-miscellaneous" <?php echo ( 2 === $general_verify_con ) ? 'style="display:none;"' : ''; ?> >
1539 <label class="six wide column middle aligned">
1540 <?php
1541 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_connect_signature_algo', (int) $general_sign_alg );
1542 esc_html_e( 'OpenSSL signature algorithm', 'mainwp' );
1543 ?>
1544 </label>
1545 <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">
1546 <select class="ui dropdown settings-field-value-change-handler" id="mainwp_settings_openssl_alg" name="mainwp_settings_openssl_alg">
1547 <?php
1548 foreach ( $sign_algs as $val => $text ) {
1549 ?>
1550 <option <?php echo ( $val === $general_sign_alg ) ? 'selected' : ''; ?> value="<?php echo esc_attr( $val ); ?>"><?php echo esc_html( $text ); ?></option>
1551 <?php
1552 }
1553 ?>
1554 </select>
1555 <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>
1556 </div>
1557 </div>
1558 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous">
1559 <label class="six wide column middle aligned">
1560 <?php
1561 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_forceUseIPv4', (int) get_option( 'mainwp_forceUseIPv4' ) );
1562 esc_html_e( 'Force IPv4', 'mainwp' );
1563 ?>
1564 </label>
1565 <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">
1566 <input type="checkbox" class="settings-field-value-change-handler" 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>
1567 </div>
1568 </div>
1569 <?php
1570
1571 /**
1572 * Action: mainwp_advanced_settings_form_bottom
1573 *
1574 * Fires at the bottom of advanced settings form.
1575 *
1576 * @since 4.1
1577 */
1578 do_action( 'mainwp_advanced_settings_form_bottom' );
1579
1580 ?>
1581 <div class="ui divider"></div>
1582 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1583 </form>
1584 </div>
1585 </div>
1586 <script>
1587 const maximumRequests = <?php echo ! empty( get_option( 'mainwp_maximumRequests' ) ) ? esc_js( get_option( 'mainwp_maximumRequests' ) ) : 4; ?>;
1588 jQuery('#mainwp_maximumRequests_slider').slider({
1589 min: 1,
1590 max: 20,
1591 start: maximumRequests,
1592 step: 1,
1593 restrictedLabels: [1,20],
1594 showThumbTooltip: true,
1595 tooltipConfig: {
1596 position: 'top center',
1597 variation: 'small visible black'
1598 },
1599 onChange: function(value) {
1600 jQuery('#mainwp_maximumRequests').val(value);
1601 }
1602 });
1603 const minimumDelay = <?php echo ! empty( get_option( 'mainwp_minimumDelay' ) ) ? esc_js( get_option( 'mainwp_minimumDelay' ) ) : 200; ?>;
1604 jQuery('#mainwp_minimumDelay_slider').slider({
1605 min: 100,
1606 max: 5000,
1607 start: minimumDelay,
1608 step: 100,
1609 restrictedLabels: [100,5000],
1610 showThumbTooltip: true,
1611 tooltipConfig: {
1612 position: 'top center',
1613 variation: 'small visible black'
1614 },
1615 onChange: function(value) {
1616 jQuery('#mainwp_minimumDelay').val(value);
1617 }
1618 });
1619 const maximumIPRequests = <?php echo ! empty( get_option( 'mainwp_maximumIPRequests' ) ) ? esc_js( get_option( 'mainwp_maximumIPRequests' ) ) : 1; ?>;
1620 jQuery('#mainwp_maximumIPRequests_slider').slider({
1621 min: 1,
1622 max: 10,
1623 start: maximumIPRequests,
1624 step: 1,
1625 restrictedLabels: [1,10],
1626 showThumbTooltip: true,
1627 tooltipConfig: {
1628 position: 'top center',
1629 variation: 'small visible black'
1630 },
1631 onChange: function(value) {
1632 jQuery('#mainwp_maximumIPRequests').val(value);
1633 }
1634 });
1635 const minimumIPDelay = <?php echo ! empty( get_option( 'mainwp_minimumIPDelay' ) ) ? esc_js( get_option( 'mainwp_minimumIPDelay' ) ) : 1000; ?>;
1636 jQuery('#mainwp_minimumIPDelay_slider').slider({
1637 min: 500,
1638 max: 5000,
1639 start: minimumIPDelay,
1640 step: 100,
1641 restrictedLabels: [500,5000],
1642 showThumbTooltip: true,
1643 tooltipConfig: {
1644 position: 'top center',
1645 variation: 'small visible black'
1646 },
1647 onChange: function(value) {
1648 jQuery('#mainwp_minimumIPDelay').val(value);
1649 }
1650 });
1651 const maximumSyncRequests = <?php echo ! empty( get_option( 'mainwp_maximumSyncRequests' ) ) ? esc_js( get_option( 'mainwp_maximumSyncRequests' ) ) : 8; ?>;
1652 jQuery('#mainwp_maximumSyncRequests_slider').slider({
1653 min: 1,
1654 max: 20,
1655 start: maximumSyncRequests,
1656 step: 1,
1657 restrictedLabels: [1,20],
1658 showThumbTooltip: true,
1659 tooltipConfig: {
1660 position: 'top center',
1661 variation: 'small visible black'
1662 },
1663 onChange: function(value) {
1664 jQuery('#mainwp_maximumSyncRequests').val(value);
1665 }
1666 });
1667 const maximumInstallUpdateRequests = <?php echo ! empty( get_option( 'mainwp_maximumInstallUpdateRequests' ) ) ? esc_js( get_option( 'mainwp_maximumInstallUpdateRequests' ) ) : 3; ?>;
1668 jQuery('#mainwp_maximumInstallUpdateRequests_slider').slider({
1669 min: 1,
1670 max: 20,
1671 start: maximumInstallUpdateRequests,
1672 step: 1,
1673 restrictedLabels: [1,20],
1674 showThumbTooltip: true,
1675 tooltipConfig: {
1676 position: 'top center',
1677 variation: 'small visible black'
1678 },
1679 onChange: function(value) {
1680 jQuery('#mainwp_maximumInstallUpdateRequests').val(value);
1681 }
1682 });
1683 const maximumUptimeMonitoringRequests = <?php echo ! empty( get_option( 'mainwp_maximum_uptime_monitoring_requests' ) ) ? esc_js( get_option( 'mainwp_maximum_uptime_monitoring_requests' ) ) : 10; ?>;
1684 jQuery('#mainwp_maximumUptimeMonitoringRequests_slider').slider({
1685 min: 1,
1686 max: 100,
1687 start: maximumUptimeMonitoringRequests,
1688 step: 1,
1689 restrictedLabels: [1,100],
1690 showThumbTooltip: true,
1691 tooltipConfig: {
1692 position: 'top center',
1693 variation: 'small visible black'
1694 },
1695 onChange: function(value) {
1696 jQuery('#mainwp_maximumUptimeMonitoringRequests').val(value).change();
1697 }
1698 });
1699 jQuery('#mainwp_maximumUptimeMonitoringRequests_slider').slider('set value', maximumUptimeMonitoringRequests);
1700 </script>
1701 <?php
1702 static::render_footer( 'Advanced' );
1703 }
1704
1705 /**
1706 * Render MainWP Tools SubPage.
1707 *
1708 * @uses \MainWP\Dashboard\MainWP_UI::render_screen_options()
1709 */
1710 public static function render_mainwp_tools() { // phpcs:ignore -- NOSONAR - complex.
1711 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
1712 \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
1713 return;
1714 }
1715 static::render_header( 'MainWPTools' );
1716 $is_demo = MainWP_Demo_Handle::is_demo_mode();
1717 ?>
1718 <div id="mainwp-tools-settings" class="ui segment">
1719 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
1720 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-message' ) ) : ?>
1721 <div class="ui info message">
1722 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-message"></i>
1723 <?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>' ); ?>
1724 </div>
1725 <?php endif; ?>
1726 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-custom-theme' ) ) : ?>
1727 <div class="ui info message">
1728 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-custom-theme"></i>
1729 <div><?php esc_html_e( 'Here you can select a theme for your MainWP Dashboard.', 'mainwp' ); ?></div>
1730 <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>
1731 </div>
1732 <?php endif; ?>
1733 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) : ?>
1734 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
1735 <?php endif; ?>
1736 <?php if ( isset( $_POST['mainwp_restore_info_messages'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) : ?>
1737 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Info messages have been restored successfully!', 'mainwp' ); ?></div>
1738 <?php endif; ?>
1739 <div class="ui form">
1740 <form method="POST" action="">
1741 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1742 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'MainWPTools' ) ); ?>" />
1743 <h3 class="ui dividing header">
1744 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-tools' ); ?>
1745 <?php esc_html_e( 'MainWP Dashboard Tools', 'mainwp' ); ?></h3>
1746 <?php
1747 /**
1748 * Action: mainwp_tools_form_top
1749 *
1750 * Fires at the top of MainWP tools form.
1751 *
1752 * @since 4.1
1753 */
1754 do_action( 'mainwp_tools_form_top' );
1755
1756 $show_qsw = apply_filters( 'mainwp_show_qsw', true );
1757
1758 static::get_instance()->render_select_custom_themes();
1759
1760 ?>
1761 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-tools">
1762 <label class="six wide column middle aligned">
1763 <?php
1764 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_enable_guided_tours', (int) get_option( 'mainwp_enable_guided_tours', 0 ) );
1765 esc_html_e( 'Enable MainWP guided tours', 'mainwp' );
1766 ?>
1767 <span class="ui blue mini label"><?php esc_html_e( 'BETA', 'mainwp' ); ?></span></label>
1768 <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">
1769 <div class="ui info message" style="display:block!important;">
1770 <?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>' ); ?>
1771 </div>
1772 <div class="ui toggle checkbox">
1773 <input type="checkbox" class="settings-field-value-change-handler" name="mainwp-guided-tours-option" id="mainwp-guided-tours-option" <?php echo 1 === (int) get_option( 'mainwp_enable_guided_tours', 0 ) ? 'checked="true"' : ''; ?> />
1774 </div>
1775 </div>
1776 </div>
1777 <?php if ( get_option( 'mainwp_not_start_encrypt_keys' ) ) { ?>
1778 <div class="ui grid field">
1779 <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL Key Encryption', 'mainwp' ); ?></label>
1780 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'To enhance security, we\'ve added a feature to encrypt your private keys stored in the database.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1781 <input type="button" name="" id="increase-connection-security-btn" data-inverted="" data-position="top right" data-tooltip="<?php esc_attr_e( 'To enhance security, we\'ve added a feature to encrypt your private keys stored in the database.', 'mainwp' ); ?>" class="ui green basic button" value="<?php esc_attr_e( 'Encrypt Keys Now', 'mainwp' ); ?>" />
1782 </div>
1783 </div>
1784 <?php } ?>
1785 <div class="ui grid field">
1786 <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashboard to establish a new connection', 'mainwp' ); ?></label>
1787 <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">
1788 <?php
1789 if ( $is_demo ) {
1790 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' ) . '" />' );
1791 } else {
1792 ?>
1793 <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' ); ?>" />
1794 <?php } ?>
1795 </div>
1796 </div>
1797 <div class="ui grid field">
1798 <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashboard to set new pair of OpenSSL Keys', 'mainwp' ); ?></label>
1799 <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">
1800 <?php
1801 if ( $is_demo ) {
1802 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>' );
1803 } else {
1804 ?>
1805 <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>
1806 <?php } ?>
1807 </div>
1808 </div>
1809 <?php if ( $show_qsw ) { ?>
1810 <div class="ui grid field">
1811 <label class="six wide column middle aligned"><?php esc_html_e( 'Start the MainWP Quick Setup Wizard', 'mainwp' ); ?></label>
1812 <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>
1813 </div>
1814 <?php } ?>
1815 <div class="ui grid field">
1816 <label class="six wide column middle aligned"><?php esc_html_e( 'Export child sites to CSV file', 'mainwp' ); ?></label>
1817 <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>
1818 </div>
1819 <div class="ui grid field">
1820 <label class="six wide column middle aligned"><?php esc_html_e( 'Import child sites', 'mainwp' ); ?></label>
1821 <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>
1822 </div>
1823 <div class="ui grid field">
1824 <label class="six wide column middle aligned"><?php esc_html_e( 'Disconnect all child sites', 'mainwp' ); ?></label>
1825 <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">
1826 <?php
1827 if ( $is_demo ) {
1828 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>' );
1829 } else {
1830 ?>
1831 <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>
1832 <?php } ?>
1833 </div>
1834 </div>
1835 <div class="ui grid field">
1836 <label class="six wide column middle aligned"><?php esc_html_e( 'Delete extensions API Activation data', 'mainwp' ); ?></label>
1837 <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">
1838 <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>
1839 </div>
1840 </div>
1841 <div class="ui grid field">
1842 <label class="six wide column middle aligned"><?php esc_html_e( 'Restore all info messages', 'mainwp' ); ?></label>
1843 <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">
1844 <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' ); ?>"/>
1845 </div>
1846 </div>
1847 <?php
1848 $enabled_demo = MainWP_Demo_Handle::is_demo_mode();
1849 $is_new = MainWP_Demo_Handle::get_instance()->is_new_instance();
1850 if ( ! MainWP_Demo_Handle::is_instawp_site() ) {
1851 ?>
1852 <div class="ui grid field">
1853 <label class="six wide column middle aligned"><?php echo esc_html__( 'Demo mode', 'mainwp' ); ?></label>
1854 <div class="ten wide column">
1855 <?php if ( ! $enabled_demo ) { ?>
1856 <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>
1857 <?php } else { ?>
1858 <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>
1859 <?php } ?>
1860 </div>
1861 </div>
1862 <?php
1863 }
1864 /**
1865 * Action: mainwp_tools_form_bottom
1866 *
1867 * Fires at the bottom of mainwp tools form.
1868 *
1869 * @since 4.1
1870 */
1871 do_action( 'mainwp_tools_form_bottom' );
1872 ?>
1873 <div class="ui divider"></div>
1874 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1875 </form>
1876 </div>
1877 </div>
1878 <script type="text/javascript">
1879 jQuery( '#mainwp-disconnect-sites-tool' ).popup();
1880 jQuery( '#mainwp-clear-activation-data' ).popup();
1881 </script>
1882 <?php
1883 static::render_footer( 'MainWPTools' );
1884 MainWP_Connect_Helper::render_renew_connections_modal();
1885 }
1886
1887 /**
1888 * Method is_basic_auth_dashboard_enabled.
1889 *
1890 * @return bool true|false.
1891 */
1892 public static function is_basic_auth_dashboard_enabled() { // phpcs:ignore -- NOSONAR - complex.
1893 $response = wp_remote_get( get_site_url() . '/wp-json' );
1894 $code = wp_remote_retrieve_response_code( $response );
1895 if ( 404 === (int) $code || 401 === (int) $code ) {
1896 return true;
1897 }
1898 return false;
1899 }
1900
1901
1902 /**
1903 * Render MainWP themes selection.
1904 */
1905 public function render_select_custom_themes() { // phpcs:ignore -- NOSONAR - complex.
1906 $custom_theme = $this->get_current_user_theme();
1907 if ( false === $custom_theme ) {
1908 // to compatible with Custom Dashboard extension settings.
1909 $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
1910 if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
1911 $compat_theme = $compat_settings['theme'];
1912 }
1913 if ( null !== $compat_theme ) {
1914 $custom_theme = $compat_theme;
1915 }
1916 }
1917 $themes_files = static::get_instance()->get_custom_themes_files();
1918 if ( empty( $themes_files ) ) {
1919 $themes_files = array();
1920 }
1921 ?>
1922 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-tools" default-indi-value="default">
1923 <label class="six wide column middle aligned">
1924 <?php
1925 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_selected_theme', $custom_theme );
1926 esc_html_e( 'Select MainWP Theme', 'mainwp' );
1927 ?>
1928 </label>
1929 <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">
1930 <select name="mainwp_settings_custom_theme" id="mainwp_settings_custom_theme" class="ui dropdown selection settings-field-value-change-handler">
1931 <option value="default" <?php echo ( 'default' === $custom_theme || empty( $custom_theme ) ) ? 'selected' : ''; ?>><?php esc_html_e( 'Default', 'mainwp' ); ?></option>
1932 <option value="classic" <?php echo ( 'classic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Classic', 'mainwp' ); ?></option>
1933 <option value="dark" <?php echo ( 'dark' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Dark', 'mainwp' ); ?></option>
1934 <option value="wpadmin" <?php echo ( 'wpadmin' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'WP Admin', 'mainwp' ); ?></option>
1935 <option value="minimalistic" <?php echo ( 'minimalistic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Minimalistic', 'mainwp' ); ?></option>
1936 <?php
1937 foreach ( $themes_files as $file_name => $theme ) {
1938 $theme = ucfirst( $theme );
1939 $_select = '';
1940 if ( $custom_theme === $file_name ) {
1941 $_select = 'selected';
1942 }
1943 echo '<option value="' . esc_attr( $file_name ) . '" ' . esc_attr( $_select ) . '>' . esc_html( $theme ) . '</option>';
1944 }
1945 ?>
1946 </select>
1947 </div>
1948 </div>
1949 <?php
1950 }
1951
1952 /**
1953 * Get custom themes files.
1954 */
1955 public function get_custom_themes_files() {
1956 // get themes files.
1957 $dirs = $this->get_custom_theme_folder();
1958 $scan_dir = $dirs[0];
1959 $handle = opendir( $scan_dir );
1960 $themes = array();
1961 if ( $handle ) {
1962 $filename = readdir( $handle );
1963 while ( false !== $filename ) {
1964 $correct_file = true;
1965 if ( '.' === substr( $filename, 0, 1 ) || 'index.php' === $filename || '.css' !== substr( $filename, - 4 ) ) {
1966 $correct_file = false;
1967 }
1968 if ( $correct_file ) {
1969 $theme = basename( $filename, '.css' );
1970 $theme = str_replace( '-theme', '', $theme );
1971 $themes[ $filename ] = trim( $theme );
1972 }
1973 $filename = readdir( $handle ); // to while loop.
1974 }
1975 closedir( $handle );
1976 }
1977 return $themes;
1978 }
1979
1980 /**
1981 * Get selected MainWP theme name.
1982 */
1983 public function get_selected_theme() {
1984 $selected_theme = false;
1985
1986 $custom_theme = $this->get_current_user_theme();
1987
1988 if ( false === $custom_theme ) {
1989 // to compatible with Custom Dashboard extension settings.
1990 $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
1991 if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
1992 $compat_theme = $compat_settings['theme'];
1993 }
1994
1995 if ( null !== $compat_theme ) {
1996 $custom_theme = $compat_theme;
1997 }
1998 }
1999
2000 if ( ! empty( $custom_theme ) ) {
2001 if ( 'default' === $custom_theme || 'dark' === $custom_theme || 'wpadmin' === $custom_theme || 'minimalistic' === $custom_theme ) {
2002 return $custom_theme;
2003 }
2004 $dirs = $this->get_custom_theme_folder();
2005 $theme_dir = $dirs[0];
2006 $file = $theme_dir . $custom_theme;
2007 if ( file_exists( $file ) && '.css' === substr( $file, - 4 ) ) {
2008 $selected_theme = $custom_theme;
2009 }
2010 }
2011 return $selected_theme;
2012 }
2013
2014
2015 /**
2016 * Get custom MainWP theme folder.
2017 */
2018 public function get_custom_theme_folder() {
2019 $dirs = MainWP_System_Utility::get_mainwp_dir();
2020 global $wp_filesystem;
2021 if ( is_array( $dirs ) && ! $wp_filesystem->exists( $dirs[0] . 'themes' ) && $wp_filesystem->exists( $dirs[0] . 'custom-dashboard' ) ) {
2022 // re-name the custom-dashboard folder to compatible.
2023 $wp_filesystem->move( $dirs[0] . 'custom-dashboard', $dirs[0] . 'themes' );
2024 }
2025 return MainWP_System_Utility::get_mainwp_dir_allow_access( 'themes' );
2026 }
2027
2028
2029 /**
2030 * Get current user's selected theme.
2031 */
2032 public function get_current_user_theme() {
2033 $custom_theme = get_user_option( 'mainwp_selected_theme' );
2034 if ( empty( $custom_theme ) ) {
2035 $custom_theme = get_option( 'mainwp_selected_theme', 'default' );
2036 }
2037 return $custom_theme;
2038 }
2039
2040 /**
2041 * Export Child Sites and save as .csv file.
2042 *
2043 * @uses \MainWP\Dashboard\MainWP_DB::query()
2044 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2045 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
2046 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2047 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
2048 */
2049 public static function export_sites() {
2050 if ( isset( $_GET['doExportSites'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'export_sites' ) ) {
2051
2052 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( true );
2053 $websites = MainWP_DB::instance()->query( $sql );
2054
2055 if ( ! $websites ) {
2056 die( 'Not found sites' );
2057 }
2058
2059 $keys = array( 'name', 'url', 'adminname', 'adminpasswd', 'wpgroups', 'uniqueId', 'http_user', 'http_pass', 'verify_certificate', 'ssl_version' );
2060 $allowedHeaders = array( 'site name', 'url', 'admin name', 'admin password', 'tag', 'security id', 'http username', 'http password', 'verify certificate', 'ssl version' );
2061
2062 $csv = implode( ',', $allowedHeaders ) . "\r";
2063 MainWP_DB::data_seek( $websites, 0 );
2064 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2065 if ( empty( $website ) ) {
2066 continue;
2067 }
2068 $row = MainWP_Utility::map_site( $website, $keys, false );
2069 $csv .= '"' . implode( '","', $row ) . '"' . "\r";
2070 }
2071
2072 header( 'Content-Type: text/csv; charset=utf-8' );
2073 header( 'Content-Disposition: attachment; filename=export-sites.csv' );
2074 echo $csv; // phpcs:ignore WordPress.Security.EscapeOutput
2075 exit();
2076 }
2077 }
2078
2079 /**
2080 * Render MainWP Email Settings SubPage.
2081 *
2082 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_notification_types()
2083 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_edit_settings()
2084 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::emails_general_settings_handle()
2085 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_all_settings()
2086 * @uses \MainWP\Dashboard\MainWP_Notification_Template::handle_template_file_action()
2087 */
2088 public static function render_email_settings() {
2089 $notification_emails = MainWP_Notification_Settings::get_notification_types();
2090 static::render_header( 'Emails' );
2091 $edit_email = isset( $_GET['edit-email'] ) ? sanitize_text_field( wp_unslash( $_GET['edit-email'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2092 if ( ! empty( $edit_email ) && isset( $notification_emails[ $edit_email ] ) ) {
2093 $updated_templ = MainWP_Notification_Template::instance()->handle_template_file_action();
2094 MainWP_Notification_Settings::instance()->render_edit_settings( $edit_email, $updated_templ );
2095 } else {
2096 $updated = MainWP_Notification_Settings::emails_general_settings_handle();
2097 MainWP_Notification_Settings::instance()->render_all_settings( $updated );
2098 }
2099 static::render_footer( 'Emails' );
2100 }
2101
2102 /**
2103 * Method mainwp_help_content()
2104 *
2105 * Creates the MainWP Help Documentation List for the help component in the sidebar.
2106 */
2107 public static function mainwp_help_content() {
2108 if ( isset( $_GET['page'] ) && ( 'Settings' === $_GET['page'] || 'SettingsAdvanced' === $_GET['page'] || 'MainWPTools' === $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2109 ?>
2110 <p><?php esc_html_e( 'If you need help with your MainWP Dashboard settings, please review following help documents', 'mainwp' ); ?></p>
2111 <div class="ui list">
2112 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/" target="_blank">MainWP Dashboard Settings</a></div>
2113 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/#updates-settings" target="_blank">Updates Settings</a></div>
2114 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/#basic-uptime-monitoring" target="_blank">Uptime Monitoring Settings</a></div>
2115 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/#site-health-monitoring" target="_blank">Site Health Settings</a></div>
2116 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/#backup-options" target="_blank">Backup Settings</a></div>
2117 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/#advanced-settings" target="_blank">Advanced Settings</a></div>
2118 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/#email-settings" target="_blank">Email Settings</a></div>
2119 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/#mainwp-tools" target="_blank">Tools</a></div>
2120 </div>
2121 <?php
2122 /**
2123 * Action: mainwp_settings_help_item
2124 *
2125 * Fires at the bottom of the help articles list in the Help sidebar on the Settings page.
2126 *
2127 * Suggested HTML markup:
2128 *
2129 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2130 *
2131 * @since 5.2
2132 */
2133 do_action( 'mainwp_settings_help_item' );
2134
2135 }
2136 }
2137 }
2138