PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | pages/page-mainwp-settings.php +2678 -1497 5.0.2 → 6.2.2 View file →
@@ -9,1651 +9,2832 @@
9 9 */
10 10
11 11 namespace MainWP\Dashboard;
12 12
13 +use MainWP\Dashboard\Module\CostTracker\Cost_Tracker_Settings;
14 +
15 +// Exit if accessed directly.
16 +if ( ! defined( 'ABSPATH' ) ) {
17 + exit;
18 +}
19 +
13 20 /**
14 21 * Class MainWP_Settings
15 22 *
16 23 * @package MainWP\Dashboard
17 24 */
18 -class MainWP_Settings {
25 +class MainWP_Settings { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
19 26
20 - // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
27 + // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
21 28
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;
29 + /**
30 + * Protected static variable to hold the single instance of the class.
31 + *
32 + * @var mixed Default null
33 + */
34 + protected static $instance = null;
28 35
29 - /**
30 - * Public static varable to hold Subpages information.
31 - *
32 - * @var array $subPages
33 - */
34 - public static $subPages;
36 + /**
37 + * Public static varable to hold Subpages information.
38 + *
39 + * @var array $subPages
40 + */
41 + public static $subPages;
35 42
36 - /**
37 - * Get Class Name
38 - *
39 - * @return __CLASS__
40 - */
41 - public static function get_class_name() {
42 - return __CLASS__;
43 - }
43 + /**
44 + * Get Class Name
45 + *
46 + * @return __CLASS__
47 + */
48 + public static function get_class_name() {
49 + return __CLASS__;
50 + }
44 51
45 - /**
46 - * Return the single instance of the class.
47 - *
48 - * @return mixed $instance The single instance of the class.
49 - */
50 - public static function get_instance() {
51 - if ( is_null( self::$instance ) ) {
52 - self::$instance = new self();
53 - }
54 - return self::$instance;
55 - }
52 + /**
53 + * Return the single instance of the class.
54 + *
55 + * @return mixed $instance The single instance of the class.
56 + */
57 + public static function get_instance() {
58 + if ( is_null( static::$instance ) ) {
59 + static::$instance = new self();
60 + }
61 + return static::$instance;
62 + }
56 63
57 - /** Instantiate Hooks for the Settings Page. */
58 - public static function init() {
59 - /**
60 - * This hook allows you to render the Settings page header via the 'mainwp_pageheader_settings' action.
61 - *
62 - * This hook is normally used in the same context of 'mainwp_getsubpages_settings'
63 - *
64 - * @see \MainWP_Settings::render_header
65 - */
66 - add_action( 'mainwp-pageheader-settings', array( self::get_class_name(), 'render_header' ) ); // deprecated, use mainwp_pageheader_settings.
64 + /** Instantiate Hooks for the Settings Page. */
65 + public static function init() {
66 + /**
67 + * This hook allows you to render the Settings page header via the 'mainwp_pageheader_settings' action.
68 + *
69 + * This hook is normally used in the same context of 'mainwp_getsubpages_settings'
70 + *
71 + * @see \MainWP_Settings::render_header
72 + */
73 + add_action( 'mainwp-pageheader-settings', array( static::get_class_name(), 'render_header' ) ); // deprecated, use mainwp_pageheader_settings.
67 74
68 - add_action( 'mainwp_pageheader_settings', array( self::get_class_name(), 'render_header' ) );
75 + add_action( 'mainwp_pageheader_settings', array( static::get_class_name(), 'render_header' ) );
69 76
70 - /**
71 - * This hook allows you to render the Settings page footer via the 'mainwp-pagefooter-settings' action.
72 - *
73 - * This hook is normally used in the same context of 'mainwp-getsubpages-settings'
74 - *
75 - * @see \MainWP_Settings::render_footer
76 - */
77 - add_action( 'mainwp-pagefooter-settings', array( self::get_class_name(), 'render_footer' ) ); // deprecated, use mainwp_pagefooter_settings.
77 + /**
78 + * This hook allows you to render the Settings page footer via the 'mainwp-pagefooter-settings' action.
79 + *
80 + * This hook is normally used in the same context of 'mainwp-getsubpages-settings'
81 + *
82 + * @see \MainWP_Settings::render_footer
83 + */
84 + add_action( 'mainwp-pagefooter-settings', array( static::get_class_name(), 'render_footer' ) ); // deprecated, use mainwp_pagefooter_settings.
78 85
79 - add_action( 'mainwp_pagefooter_settings', array( self::get_class_name(), 'render_footer' ) );
86 + add_action( 'mainwp_pagefooter_settings', array( static::get_class_name(), 'render_footer' ) );
80 87
81 - add_action( 'admin_init', array( self::get_class_name(), 'admin_init' ) );
88 + add_action( 'admin_init', array( static::get_class_name(), 'admin_init' ) );
82 89
83 - add_action( 'mainwp_help_sidebar_content', array( self::get_class_name(), 'mainwp_help_content' ) );
84 - }
90 + add_action( 'mainwp_help_sidebar_content', array( static::get_class_name(), 'mainwp_help_content' ) );
91 + }
85 92
86 - /** Run the export_sites method that exports the Child Sites .csv file */
87 - public static function admin_init() {
88 - self::export_sites();
89 - if ( isset( $_GET['clearActivationData'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'clear_activation_data' ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
90 - delete_option( 'mainwp_extensions_api_username' );
91 - delete_option( 'mainwp_extensions_api_password' );
92 - delete_option( 'mainwp_extensions_api_save_login' );
93 - delete_option( 'mainwp_extensions_plan_info' );
94 - MainWP_Keys_Manager::instance()->update_key_value( 'mainwp_extensions_master_api_key', false );
93 + /**
94 + * Get the registered Settings subpages.
95 + *
96 + * @return array<int, array<string, mixed>> Settings subpages.
97 + */
98 + private static function get_subpages() {
99 + if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
100 + return static::$subPages;
101 + }
95 102
96 - $new_extensions = array();
97 - $extensions = get_option( 'mainwp_extensions', array() );
103 + /**
104 + * Settings Subpages
105 + *
106 + * Filters subpages for the Settings page.
107 + *
108 + * @since Unknown
109 + */
110 + $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.
111 + static::$subPages = apply_filters( 'mainwp_getsubpages_settings', $sub_pages );
98 112
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 - }
113 + return is_array( static::$subPages ) ? static::$subPages : array();
114 + }
111 115
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 - }
116 + /**
117 + * Get the built-in Settings pages used across menu registration and navigation rendering.
118 + *
119 + * @return array<int, array<string, mixed>> Settings page definitions.
120 + */
121 + private static function get_core_pages() {
122 + $pages = array(
123 + array(
124 + 'slug' => 'Settings',
125 + 'page_title' => __( 'Settings Global options', 'mainwp' ),
126 + 'menu_title' => ' <span id="mainwp-Settings">' . esc_html__( 'Settings', 'mainwp' ) . '</span>',
127 + 'nav_title' => esc_html__( 'General Settings', 'mainwp' ),
128 + 'callback' => array( static::get_class_name(), 'render' ),
129 + 'active_keys' => array( '', 'Settings' ),
130 + ),
131 + array(
132 + 'slug' => 'MainWPTools',
133 + 'page_title' => __( 'Tools', 'mainwp' ),
134 + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Tools', 'mainwp' ) . '</div>',
135 + 'nav_title' => esc_html__( 'Tools', 'mainwp' ),
136 + 'callback' => array( static::get_class_name(), 'render_mainwp_tools' ),
137 + 'active_keys' => array( 'MainWPTools' ),
138 + ),
139 + array(
140 + 'slug' => 'CostTrackerSettings',
141 + 'page_title' => esc_html__( 'Cost Tracker Settings', 'mainwp' ),
142 + 'menu_title' => '<div class="mainwp-hidden">' . esc_html__( 'Cost Tracker', 'mainwp' ) . '</div>',
143 + 'nav_title' => esc_html__( 'Cost Tracker Settings', 'mainwp' ),
144 + 'callback' => array( Cost_Tracker_Settings::get_instance(), 'render_settings_page' ),
145 + 'active_keys' => array( 'CostTrackerSettings' ),
146 + ),
147 + array(
148 + 'slug' => 'SettingsAdvanced',
149 + 'page_title' => __( 'Advanced Options', 'mainwp' ),
150 + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Advanced Options', 'mainwp' ) . '</div>',
151 + 'nav_title' => esc_html__( 'Advanced Settings', 'mainwp' ),
152 + 'callback' => array( static::get_class_name(), 'render_advanced' ),
153 + 'active_keys' => array( 'Advanced', 'SettingsAdvanced' ),
154 + ),
155 + array(
156 + 'slug' => 'MonitoringSettings',
157 + 'page_title' => __( 'Monitoring Options', 'mainwp' ),
158 + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Monitoring Options', 'mainwp' ) . '</div>',
159 + 'nav_title' => esc_html__( 'Monitoring Settings', 'mainwp' ),
160 + 'callback' => array( static::get_class_name(), 'render_monitoring' ),
161 + 'active_keys' => array( 'Monitoring', 'MonitoringSettings' ),
162 + ),
163 + array(
164 + 'slug' => 'SettingsEmail',
165 + 'page_title' => __( 'Email Settings', 'mainwp' ),
166 + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Email Settings', 'mainwp' ) . '</div>',
167 + 'nav_title' => esc_html__( 'Email Settings', 'mainwp' ),
168 + 'callback' => array( static::get_class_name(), 'render_email_settings' ),
169 + 'active_keys' => array( 'Emails', 'SettingsEmail' ),
170 + ),
171 + array(
172 + 'slug' => 'PremiumUpdates',
173 + 'page_title' => __( 'Premium Updates', 'mainwp' ),
174 + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Premium Updates', 'mainwp' ) . '</div>',
175 + 'nav_title' => esc_html__( 'Premium Updates', 'mainwp' ),
176 + 'callback' => array( MainWP_Settings_Premium_Updates::get_class_name(), 'render' ),
177 + 'active_keys' => array( 'Premium', 'PremiumUpdates' ),
178 + ),
179 + );
127 180
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 - }
181 + $visible_pages = array();
134 182
135 - /**
136 - * Instantiate the Settings Menu.
137 - *
138 - * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
139 - */
140 - public static function init_menu() {
141 - add_submenu_page(
142 - 'mainwp_tab',
143 - __( 'Settings Global options', 'mainwp' ),
144 - ' <span id="mainwp-Settings">' . esc_html__( 'Settings', 'mainwp' ) . '</span>',
145 - 'read',
146 - 'Settings',
147 - array(
148 - self::get_class_name(),
149 - 'render',
150 - )
151 - );
183 + foreach ( $pages as $page ) {
184 + if ( 'Settings' !== $page['slug'] && MainWP_Menu::is_disable_menu_item( 3, $page['slug'] ) ) {
185 + continue;
186 + }
152 187
153 - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) {
154 - add_submenu_page(
155 - 'mainwp_tab',
156 - __( 'Tools', 'mainwp' ),
157 - ' <div class="mainwp-hidden">' . esc_html__( 'Tools', 'mainwp' ) . '</div>',
158 - 'read',
159 - 'MainWPTools',
160 - array(
161 - self::get_class_name(),
162 - 'render_mainwp_tools',
163 - )
164 - );
165 - }
188 + $visible_pages[] = $page;
189 + }
166 190
167 - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) {
168 - add_submenu_page(
169 - 'mainwp_tab',
170 - __( 'Advanced Options', 'mainwp' ),
171 - ' <div class="mainwp-hidden">' . esc_html__( 'Advanced Options', 'mainwp' ) . '</div>',
172 - 'read',
173 - 'SettingsAdvanced',
174 - array(
175 - self::get_class_name(),
176 - 'render_advanced',
177 - )
178 - );
179 - }
191 + return $visible_pages;
192 + }
180 193
181 - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) {
182 - add_submenu_page(
183 - 'mainwp_tab',
184 - __( 'Email Settings', 'mainwp' ),
185 - ' <div class="mainwp-hidden">' . esc_html__( 'Email Settings', 'mainwp' ) . '</div>',
186 - 'read',
187 - 'SettingsEmail',
188 - array(
189 - self::get_class_name(),
190 - 'render_email_settings',
191 - )
192 - );
193 - }
194 + /**
195 + * Convert a navigation href into a usable URL.
196 + *
197 + * @param string $href Navigation href.
198 + *
199 + * @return string Navigation URL.
200 + */
201 + private static function get_navigation_item_url( $href ) {
202 + $href = trim( wp_specialchars_decode( (string) $href, ENT_QUOTES ) );
194 203
195 - /**
196 - * Settings Subpages
197 - *
198 - * Filters subpages for the Settings page.
199 - *
200 - * @since Unknown
201 - */
202 - $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-settings', array( array() ), '4.0.7.2', 'mainwp_getsubpages_settings' ); // @deprecated Use 'mainwp_getsubpages_settings' instead.
203 - self::$subPages = apply_filters( 'mainwp_getsubpages_settings', $sub_pages );
204 + if ( empty( $href ) ) {
205 + return '';
206 + }
204 207
205 - if ( isset( self::$subPages ) && is_array( self::$subPages ) ) {
206 - foreach ( self::$subPages as $subPage ) {
207 - if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
208 - continue;
209 - }
210 - add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'Settings' . $subPage['slug'], $subPage['callback'] );
211 - }
212 - }
213 - }
208 + if ( preg_match( '/^https?:\/\//i', $href ) ) {
209 + return $href;
210 + }
214 211
215 - /**
216 - * Instantiate Settings SubPages Menu.
217 - *
218 - * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
219 - */
220 - public static function init_subpages_menu() {
221 - ?>
222 - <div id="menu-mainwp-Settings" class="mainwp-submenu-wrapper">
223 - <div class="wp-submenu sub-open" style="">
224 - <div class="mainwp_boxout">
225 - <div class="mainwp_boxoutin"></div>
226 - <a href="<?php echo esc_url( admin_url( 'admin.php?page=Settings' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></a>
227 - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) { ?>
228 - <a href="<?php echo esc_url( admin_url( 'admin.php?page=SettingsAdvanced' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Advanced Settings', 'mainwp' ); ?></a>
229 - <?php } ?>
230 - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) { ?>
231 - <a href="<?php echo esc_url( admin_url( 'admin.php?page=SettingsEmail' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Email Settings', 'mainwp' ); ?></a>
232 - <?php } ?>
233 - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) { ?>
234 - <a href="<?php echo esc_url( admin_url( 'admin.php?page=MainWPTools' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Tools', 'mainwp' ); ?></a>
235 - <?php } ?>
236 - <?php
237 - if ( isset( self::$subPages ) && is_array( self::$subPages ) && ( count( self::$subPages ) > 0 ) ) {
238 - foreach ( self::$subPages as $subPage ) {
239 - if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
240 - continue;
241 - }
242 - ?>
243 - <a href="<?php echo esc_url( admin_url( 'admin.php?page=Settings' . $subPage['slug'] ) ); ?>" class="mainwp-submenu"><?php echo esc_html( $subPage['title'] ); ?></a>
244 - <?php
245 - }
246 - }
247 - ?>
248 - </div>
249 - </div>
250 - </div>
251 - <?php
252 - }
212 + return admin_url( ltrim( $href, '/' ) );
213 + }
253 214
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 - );
215 + /**
216 + * Get dynamic Settings subpage items using the legacy left-menu normalization path.
217 + *
218 + * @return array<int, array<string, mixed>> Settings navigation items.
219 + */
220 + private static function get_filtered_subpage_navigation_items() {
221 + $menu_items = array();
222 + $core_slugs = array();
276 223
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 - );
224 + foreach ( static::get_navigation_items( 'left_menu_core' ) as $item ) {
225 + $core_slugs[ $item['slug'] ] = true;
226 + $menu_items[] = array(
227 + 'title' => $item['title'],
228 + 'parent_key' => 'Settings',
229 + 'href' => $item['href'],
230 + 'slug' => $item['slug'],
231 + 'right' => '',
232 + 'before_title' => isset( $item['before_title'] ) ? $item['before_title'] : '',
233 + );
234 + }
307 235
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 - }
236 + MainWP_Menu::init_subpages_left_menu( static::get_subpages(), $menu_items, 'Settings', 'Settings' );
313 237
314 - MainWP_Menu::add_left_menu( $item, 2 );
315 - }
316 - }
238 + $items = array();
317 239
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 = '' ) {
240 + foreach ( $menu_items as $menu_item ) {
241 + if ( empty( $menu_item['slug'] ) || empty( $menu_item['title'] ) || empty( $menu_item['href'] ) ) {
242 + continue;
243 + }
328 244
329 - $params = array(
330 - 'title' => esc_html__( 'MainWP Settings', 'mainwp' ),
331 - );
245 + if ( isset( $core_slugs[ $menu_item['slug'] ] ) ) {
246 + continue;
247 + }
332 248
333 - MainWP_UI::render_top_header( $params );
249 + if ( isset( $menu_item['item_slug'] ) ) {
250 + if ( MainWP_Menu::is_disable_menu_item( 3, $menu_item['item_slug'] ) ) {
251 + continue;
252 + }
253 + } elseif ( MainWP_Menu::is_disable_menu_item( 3, $menu_item['slug'] ) ) {
254 + continue;
255 + }
334 256
335 - $renderItems = array();
257 + $active_slug = 0 === strpos( $menu_item['slug'], 'Settings' ) ? substr( $menu_item['slug'], strlen( 'Settings' ) ) : $menu_item['slug'];
258 + $item = array(
259 + 'slug' => $menu_item['slug'],
260 + 'title' => $menu_item['title'],
261 + 'href' => $menu_item['href'],
262 + 'active_keys' => array( $active_slug, $menu_item['slug'] ),
263 + 'menu_hidden' => false,
264 + );
336 265
337 - $renderItems[] = array(
338 - 'title' => esc_html__( 'General Settings', 'mainwp' ),
339 - 'href' => 'admin.php?page=Settings',
340 - 'active' => ( '' === $shownPage ) ? true : false,
341 - );
266 + if ( ! empty( $menu_item['before_title'] ) ) {
267 + $item['before_title'] = $menu_item['before_title'];
268 + }
342 269
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 - }
270 + if ( isset( $menu_item['item_slug'] ) ) {
271 + $item['item_slug'] = $menu_item['item_slug'];
272 + }
350 273
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 - }
274 + $items[] = $item;
275 + }
358 276
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 - }
277 + return $items;
278 + }
366 279
367 - if ( isset( self::$subPages ) && is_array( self::$subPages ) ) {
368 - foreach ( self::$subPages as $subPage ) {
369 - if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
370 - continue;
371 - }
372 - $item = array();
373 - $item['title'] = $subPage['title'];
374 - $item['href'] = 'admin.php?page=Settings' . $subPage['slug'];
375 - $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false;
280 + /**
281 + * Get the Settings navigation items.
282 + *
283 + * @return array<int, array<string, mixed>> Settings navigation items.
284 + */
285 + public static function get_navigation_items( $context = 'default' ) {
286 + $core_items = array();
287 + $dynamic_items = array();
288 + $items = array();
376 289
377 - if ( isset( $subPage['class'] ) ) {
378 - $item['class'] = $subPage['class'];
379 - }
380 - $renderItems[] = $item;
381 - }
382 - }
290 + foreach ( static::get_core_pages() as $page ) {
291 + $core_items[ $page['slug'] ] = array(
292 + 'slug' => $page['slug'],
293 + 'title' => $page['nav_title'],
294 + 'href' => 'admin.php?page=' . $page['slug'],
295 + 'active_keys' => $page['active_keys'],
296 + 'menu_hidden' => false,
297 + );
298 + }
383 299
384 - MainWP_UI::render_page_navigation( $renderItems );
385 - }
300 + if ( 'command_palette' === $context ) {
301 + $dynamic_items = static::get_filtered_subpage_navigation_items();
302 + } else {
303 + foreach ( static::get_subpages() as $subPage ) {
304 + if ( empty( $subPage['slug'] ) || MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
305 + continue;
306 + }
386 307
387 - /**
388 - * Close the HTML container.
389 - */
390 - public static function render_footer() {
391 - echo '</div>';
392 - }
308 + $item = array(
309 + 'slug' => 'Settings' . $subPage['slug'],
310 + 'title' => $subPage['title'],
311 + 'href' => ! empty( $subPage['href'] ) ? $subPage['href'] : 'admin.php?page=Settings' . $subPage['slug'],
312 + 'active_keys' => array( $subPage['slug'], 'Settings' . $subPage['slug'] ),
313 + 'menu_hidden' => ! empty( $subPage['menu_hidden'] ),
314 + );
393 315
394 - /**
395 - * Method handle_settings_post().
396 - *
397 - * This class handles the $_POST of Settings Options.
398 - *
399 - * @uses MainWP_DB::instance()
400 - * @uses MainWP_Utility::update_option()
401 - *
402 - * @return boolean True|False Posts On True.
403 - *
404 - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
405 - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
406 - * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
407 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
408 - */
409 - public static function handle_settings_post() {
410 - if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) {
411 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
412 - $userExtension->pluginDir = '';
316 + if ( ! empty( $subPage['before_title'] ) ) {
317 + $item['before_title'] = $subPage['before_title'];
318 + }
413 319
414 - MainWP_DB_Common::instance()->update_user_extension( $userExtension );
415 - if ( MainWP_System_Utility::is_admin() ) {
320 + if ( isset( $subPage['class'] ) ) {
321 + $item['class'] = $subPage['class'];
322 + }
416 323
417 - /**
418 - * Action: mainwp_before_save_general_settings
419 - *
420 - * Fires before general settings save.
421 - *
422 - * @since 4.1
423 - */
424 - do_action( 'mainwp_before_save_general_settings', $_POST );
324 + if ( isset( $subPage['item_slug'] ) ) {
325 + $item['item_slug'] = $subPage['item_slug'];
326 + }
425 327
426 - $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) );
427 - MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val );
428 - $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) );
429 - MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val );
430 - $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) );
431 - MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val );
432 - $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 );
433 - MainWP_Utility::update_option( 'mainwp_show_language_updates', $val );
434 - $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) );
435 - MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val );
436 - $val = ( ! isset( $_POST['mainwp_backup_before_upgrade'] ) ? 0 : 1 );
437 - MainWP_Utility::update_option( 'mainwp_backup_before_upgrade', $val );
438 - $val = ( ! isset( $_POST['mainwp_backup_before_upgrade_days'] ) ? 7 : intval( $_POST['mainwp_backup_before_upgrade_days'] ) );
439 - MainWP_Utility::update_option( 'mainwp_backup_before_upgrade_days', $val );
328 + $dynamic_items[] = $item;
329 + }
330 + }
440 331
441 - if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) {
442 - MainWP_Utility::update_option( 'mainwp_maximumComments', isset( $_POST['mainwp_maximumComments'] ) ? intval( $_POST['mainwp_maximumComments'] ) : 50 );
443 - }
332 + $base_order = array( 'Settings', 'SettingsAdvanced', 'MonitoringSettings', 'SettingsEmail', 'PremiumUpdates' );
444 333
445 - $current_timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
446 - $new_timeDailyUpdate = isset( $_POST['mainwp_timeDailyUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_timeDailyUpdate'] ) ) : '';
334 + if ( in_array( $context, array( 'left_menu', 'left_menu_core' ), true ) ) {
335 + $base_order[] = 'MainWPTools';
336 + $base_order[] = 'CostTrackerSettings';
337 + } else {
338 + $base_order[] = 'CostTrackerSettings';
339 + }
447 340
448 - if ( $current_timeDailyUpdate !== $new_timeDailyUpdate ) {
449 - MainWP_Utility::update_option( 'mainwp_timeDailyUpdate', $new_timeDailyUpdate );
450 - }
341 + foreach ( $base_order as $slug ) {
342 + if ( isset( $core_items[ $slug ] ) ) {
343 + $items[] = $core_items[ $slug ];
344 + }
345 + }
451 346
452 - $new_freq = ( isset( $_POST['mainwp_frequencyDailyUpdate'] ) ? intval( $_POST['mainwp_frequencyDailyUpdate'] ) : 2 );
453 - MainWP_Utility::update_option( 'mainwp_frequencyDailyUpdate', $new_freq );
347 + if ( 'left_menu_core' !== $context ) {
348 + $items = array_merge( $items, $dynamic_items );
349 + }
454 350
455 - $new_delay = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 );
456 - MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $new_delay );
351 + if ( ! in_array( $context, array( 'left_menu', 'left_menu_core' ), true ) && isset( $core_items['MainWPTools'] ) ) {
352 + $items[] = $core_items['MainWPTools'];
353 + }
457 354
458 - $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 );
459 - $user = wp_get_current_user();
460 - if ( $user ) {
461 - update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
462 - }
355 + return $items;
356 + }
463 357
464 - MainWP_Utility::update_option( 'mainwp_numberdays_Outdate_Plugin_Theme', ! empty( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) ? intval( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) : 365 );
465 - $ignore_http = isset( $_POST['mainwp_ignore_http_response_status'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_ignore_http_response_status'] ) ) : '';
466 - MainWP_Utility::update_option( 'mainwp_ignore_HTTP_response_status', $ignore_http );
358 + /**
359 + * Get the Settings command palette items.
360 + *
361 + * @return array<int, array<string, mixed>> Command palette item definitions.
362 + */
363 + public static function get_command_palette_items() {
364 + $items = array();
467 365
468 - $check_http_response = ( isset( $_POST['mainwp_check_http_response'] ) ? 1 : 0 );
469 - MainWP_Utility::update_option( 'mainwp_check_http_response', $check_http_response );
366 + foreach ( static::get_navigation_items( 'command_palette' ) as $item ) {
367 + if ( ! empty( $item['menu_hidden'] ) ) {
368 + continue;
369 + }
470 370
471 - $actions_notification_enable = ( isset( $_POST['mainwp_site_actions_notification_enable'] ) ? 1 : 0 );
472 - MainWP_Utility::update_option( 'mainwp_site_actions_notification_enable', $actions_notification_enable );
371 + $path_title = $item['title'];
372 + $path_titles = array( esc_html__( 'Settings', 'mainwp' ), $path_title );
473 373
474 - //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
475 - // Handle custom date/time formats.
476 - if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] )
477 - && '\c\u\s\t\o\m' === wp_unslash( $_POST['date_format'] )
478 - ) {
479 - $_POST['date_format'] = wp_unslash( $_POST['date_format_custom'] );
480 - }
374 + if ( ! empty( $item['before_title'] ) ) {
375 + $path_title = trim( wp_strip_all_tags( $item['before_title'] ) . ' ' . $item['title'] );
376 + $path_titles[1] = $path_title;
377 + }
481 378
482 - if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] )
483 - && '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] )
484 - ) {
485 - $_POST['time_format'] = wp_unslash( $_POST['time_format_custom'] );
486 - }
379 + if ( 'Settings' === $item['slug'] ) {
380 + $path_titles[1] = esc_html__( 'General Settings', 'mainwp' );
381 + }
487 382
488 - if ( isset( $_POST['timezone_string'] ) ) {
489 - // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
490 - if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', wp_unslash( $_POST['timezone_string'] ) ) ) {
491 - $_POST['gmt_offset'] = wp_unslash( $_POST['timezone_string'] );
492 - $_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', wp_unslash( $_POST['gmt_offset'] ) ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
493 - $_POST['timezone_string'] = '';
494 - }
383 + $items[] = array(
384 + 'slug' => $item['slug'],
385 + 'href' => $item['href'],
386 + 'path_titles' => $path_titles,
387 + );
388 + }
495 389
496 - $options = array(
497 - 'gmt_offset',
498 - 'date_format',
499 - 'time_format',
500 - 'timezone_string',
501 - );
390 + return $items;
391 + }
502 392
503 - foreach ( $options as $option ) {
504 - $value = null;
505 - if ( isset( $_POST[ $option ] ) ) {
506 - $value = wp_unslash( $_POST[ $option ] );
507 - if ( ! is_array( $value ) ) {
508 - $value = trim( $value );
509 - }
510 - }
511 - update_option( $option, $value );
512 - }
513 - }
514 - //phpcs:enable
393 + /** Run the export_sites method that exports the Child Sites .csv file */
394 + public static function admin_init() { // phpcs:ignore -- NOSONAR - complex.
395 + static::export_sites();
396 + 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
397 + delete_option( 'mainwp_extensions_api_username' );
398 + delete_option( 'mainwp_extensions_api_password' );
399 + delete_option( 'mainwp_extensions_api_save_login' );
400 + delete_option( 'mainwp_extensions_plan_info' );
401 + MainWP_Keys_Manager::instance()->update_key_value( 'mainwp_extensions_master_api_key', false );
515 402
516 - MainWP_Utility::update_option( 'mainwp_use_favicon', 1 );
403 + $new_extensions = array();
404 + $extensions = get_option( 'mainwp_extensions', array() );
517 405
518 - /**
519 - * Action: mainwp_after_save_general_settings
520 - *
521 - * Fires after save general settings.
522 - *
523 - * @since 4.1
524 - */
525 - do_action( 'mainwp_after_save_general_settings', $_POST );
526 - }
406 + if ( is_array( $extensions ) ) {
407 + foreach ( $extensions as $ext ) {
408 + if ( isset( $ext['api'] ) && isset( $ext['apiManager'] ) && ! empty( $ext['apiManager'] ) ) {
409 + if ( isset( $ext['api_key'] ) ) {
410 + $ext['api_key'] = '';
411 + }
412 + if ( isset( $ext['activation_email'] ) ) {
413 + $ext['activation_email'] = '';
414 + }
415 + if ( isset( $ext['activated_key'] ) ) {
416 + $ext['activated_key'] = 'Deactivated';
417 + }
527 418
528 - return true;
529 - }
419 + $act_info = MainWP_Api_Manager::instance()->get_activation_info( $ext['api'] );
420 + if ( isset( $act_info['api_key'] ) ) {
421 + $act_info['api_key'] = '';
422 + }
423 + if ( isset( $act_info['activation_email'] ) ) {
424 + $act_info['activation_email'] = '';
425 + }
426 + if ( isset( $act_info['activated_key'] ) ) {
427 + $act_info['activated_key'] = 'Deactivated';
428 + }
429 + MainWP_Api_Manager::instance()->set_activation_info( $ext['api'], $act_info );
430 + }
431 + $new_extensions[] = $ext;
432 + }
433 + }
530 434
531 - return false;
532 - }
435 + MainWP_Utility::update_option( 'mainwp_extensions', $new_extensions );
436 + update_option( 'mainwp_extensions_all_activation_cached', '' );
437 + wp_safe_redirect( esc_url( admin_url( 'admin.php?page=MainWPTools' ) ) );
438 + die();
439 + }
440 + }
533 441
534 - /**
535 - * Render the MainWP Settings Page.
536 - *
537 - * @uses \MainWP\Dashboard\MainWP_Monitoring_View
538 - * @uses \MainWP\Dashboard\MainWP_Manage_Backups::render_settings()
539 - * @uses \MainWP\Dashboard\MainWP_Utility::get_http_codes()
540 - */
541 - public static function render() { //phpcs:ignore -- complex method.
542 - if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
543 - mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
544 - return;
545 - }
442 + /**
443 + * Instantiate the Settings Menu.
444 + *
445 + * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
446 + */
447 + public static function init_menu() {
448 + foreach ( static::get_core_pages() as $page ) {
449 + add_submenu_page(
450 + 'mainwp_tab',
451 + $page['page_title'],
452 + $page['menu_title'],
453 + 'read',
454 + $page['slug'],
455 + $page['callback']
456 + );
457 + }
546 458
547 - self::render_header( '' );
548 - ?>
549 - <div id="mainwp-general-settings" class="ui segment">
550 - <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-general-settings-info-message' ) ) : ?>
551 - <div class="ui info message">
552 - <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-general-settings-info-message"></i>
553 - <?php printf( esc_html__( 'Manage MainWP general settings. For additional help, review this %1$shelp document%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?>
554 - </div>
555 - <?php endif; ?>
556 - <?php if ( isset( $_GET['message'] ) && 'saved' === $_GET['message'] ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
557 - <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
558 - <?php endif; ?>
559 - <div class="ui form">
560 - <form method="POST" action="admin.php?page=Settings" id="mainwp-settings-page-form">
561 - <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
562 - <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'Settings' ) ); ?>" />
563 - <?php
564 - /**
565 - * Action: mainwp_settings_form_top
566 - *
567 - * Fires at the top of settings form.
568 - *
569 - * @since 4.1
570 - */
571 - do_action( 'mainwp_settings_form_top' );
572 - ?>
573 - <h3 class="ui dividing header"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></h3>
574 - <?php
575 - $timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
576 - $frequencyDailyUpdate = (int) get_option( 'mainwp_frequencyDailyUpdate', 2 );
577 - $run_timestamp = MainWP_System_Cron_Jobs::get_timestamp_from_hh_mm( $timeDailyUpdate );
578 - $delay_autoupdate = (int) get_option( 'mainwp_delay_autoupdate', 1 );
459 + foreach ( static::get_subpages() as $subPage ) {
460 + if ( empty( $subPage['slug'] ) || MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) {
461 + continue;
462 + }
579 463
580 - ?>
581 - <div class="ui grid field">
582 - <label class="six wide column middle aligned"><?php esc_html_e( 'Daily sync & update time', 'mainwp' ); ?></label>
583 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose a specific time to initiate the first daily synchronization and update process.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
584 - <div class="time-selector">
585 - <div class="ui input left icon">
586 - <i class="clock icon"></i>
587 - <input type="text" current-utc-datetime="<?php echo date( 'Y-m-d H:i:s' ); ?>" sync-time-local-datetime="<?php echo date( 'Y-m-d H:i:s', $run_timestamp ); ?>" local-datetime="<?php echo date( 'Y-m-d H:i:s', MainWP_Utility::get_timestamp() ); // phpcs:ignore -- to get local time. ?>" name="mainwp_timeDailyUpdate" id="mainwp_timeDailyUpdate" value="<?php echo esc_attr( $timeDailyUpdate ); ?>" />
588 - </div>
589 - </div>
590 - <script type="text/javascript">
591 - jQuery( document ).ready( function() {
592 - jQuery( '.time-selector' ).calendar( {
593 - type: 'time',
594 - ampm: false,
595 - formatter: {
596 - time: 'H:mm',
597 - cellTime: 'H:mm'
598 - }
599 - } );
600 - } );
601 - </script>
602 - </div>
603 - </div>
604 - <div class="ui grid field">
605 - <label class="six wide column middle aligned"><?php esc_html_e( 'Frequency of auto sync & updates', 'mainwp' ); ?></label>
606 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set the frequency for automatic synchronization and updates throughout the day.', 'mainwp' ); ?>" data-inverted="" data-position="top left" >
607 - <select name="mainwp_frequencyDailyUpdate" id="mainwp_frequencyDailyUpdate" class="ui dropdown">
608 - <option value="1" <?php echo ( 1 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Once per day', 'mainwp' ); ?></option>
609 - <option value="2" <?php echo ( 2 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Twice per day', 'mainwp' ); ?></option>
610 - <option value="3" <?php echo ( 3 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Three times per day', 'mainwp' ); ?></option>
611 - <option value="4" <?php echo ( 4 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Four times per day', 'mainwp' ); ?></option>
612 - <option value="5" <?php echo ( 5 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Five times per day', 'mainwp' ); ?></option>
613 - <option value="6" <?php echo ( 6 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Six times per day', 'mainwp' ); ?></option>
614 - <option value="7" <?php echo ( 7 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Seven times per day', 'mainwp' ); ?></option>
615 - <option value="8" <?php echo ( 8 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Eight times per day', 'mainwp' ); ?></option>
616 - <option value="9" <?php echo ( 9 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Nine times per day', 'mainwp' ); ?></option>
617 - <option value="10" <?php echo ( 10 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Ten times per day', 'mainwp' ); ?></option>
618 - <option value="11" <?php echo ( 11 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Eleven times per day', 'mainwp' ); ?></option>
619 - <option value="12" <?php echo ( 12 === $frequencyDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Twelve times per day', 'mainwp' ); ?></option>
620 - </select>
621 - </div>
622 - </div>
464 + add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'Settings' . $subPage['slug'], $subPage['callback'] );
465 + }
466 + }
623 467
624 - <?php
625 - self::render_timezone_settings();
626 - self::render_datetime_settings();
468 + /**
469 + * Instantiate Settings SubPages Menu.
470 + *
471 + * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
472 + */
473 + public static function init_subpages_menu() {
474 + ?>
475 + <div id="menu-mainwp-Settings" class="mainwp-submenu-wrapper">
476 + <div class="wp-submenu sub-open" style="">
477 + <div class="mainwp_boxout">
478 + <div class="mainwp_boxoutin"></div>
479 + <?php foreach ( static::get_navigation_items() as $item ) { ?>
480 + <a href="<?php echo esc_url( static::get_navigation_item_url( $item['href'] ) ); ?>" class="mainwp-submenu"><?php echo isset( $item['before_title'] ) ? $item['before_title'] . ' ' : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?><?php echo esc_html( $item['title'] ); ?></a>
481 + <?php } ?>
482 + </div>
483 + </div>
484 + </div>
485 + <?php
486 + }
627 487
628 - $sidebarPosition = get_user_option( 'mainwp_sidebarPosition' );
629 - if ( false === $sidebarPosition ) {
630 - $sidebarPosition = 1;
631 - }
488 + /**
489 + * Instantiate left menu
490 + *
491 + * Settings Page & SubPage link data.
492 + *
493 + * @param array $subPages SubPages Array.
494 + *
495 + * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
496 + * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
497 + * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
498 + */
499 + public static function init_left_menu( $subPages = array() ) {
500 + MainWP_Menu::add_left_menu(
501 + array(
502 + 'title' => esc_html__( 'Settings', 'mainwp' ),
503 + 'parent_key' => 'mainwp_tab',
504 + 'slug' => 'Settings',
505 + 'href' => 'admin.php?page=Settings',
506 + 'icon' => '<i class="cog icon"></i>',
507 + ),
508 + 0
509 + );
632 510
633 - ?>
634 - <div class="ui grid field">
635 - <label class="six wide column middle aligned"><?php esc_html_e( 'Sidebar position', 'mainwp' ); ?></label>
636 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Select if you want to show sidebar with option on left or right.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
637 - <select name="mainwp_sidebarPosition" id="mainwp_sidebarPosition" class="ui dropdown">
638 - <option value="1" <?php echo ( 1 === (int) $sidebarPosition ? 'selected' : '' ); ?>><?php esc_html_e( 'Right (default)', 'mainwp' ); ?></option>
639 - <option value="0" <?php echo ( 0 === (int) $sidebarPosition ? 'selected' : '' ); ?>><?php esc_html_e( 'Left', 'mainwp' ); ?></option>
640 - </select>
641 - </div>
642 - </div>
643 - <?php MainWP_UI::render_screen_options(); ?>
644 -
645 - <h3 class="ui dividing header"><?php esc_html_e( 'Updates Settings', 'mainwp' ); ?></h3>
646 - <?php
647 - $snAutomaticDailyUpdate = (int) get_option( 'mainwp_automaticDailyUpdate', 0 );
648 - $snPluginAutomaticDailyUpdate = (int) get_option( 'mainwp_pluginAutomaticDailyUpdate', 0 );
649 - $snThemeAutomaticDailyUpdate = (int) get_option( 'mainwp_themeAutomaticDailyUpdate', 0 );
650 - $backup_before_upgrade = get_option( 'mainwp_backup_before_upgrade' );
651 - $mainwp_backup_before_upgrade_days = get_option( 'mainwp_backup_before_upgrade_days' );
652 - if ( empty( $mainwp_backup_before_upgrade_days ) || ! ctype_digit( $mainwp_backup_before_upgrade_days ) ) {
653 - $mainwp_backup_before_upgrade_days = 7;
654 - }
511 + $init_sub_subleftmenu = array();
655 512
656 - $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
513 + foreach ( static::get_navigation_items( 'left_menu_core' ) as $item ) {
514 + $init_sub_subleftmenu[] = array(
515 + 'title' => $item['title'],
516 + 'parent_key' => 'Settings',
517 + 'href' => $item['href'],
518 + 'slug' => $item['slug'],
519 + 'right' => '',
520 + 'before_title' => isset( $item['before_title'] ) ? $item['before_title'] : '',
521 + );
522 + }
657 523
658 - $update_time = self::get_websites_automatic_update_time();
659 - $lastAutomaticUpdate = $update_time['last'];
660 - $nextAutomaticUpdate = $update_time['next'];
524 + if ( empty( $subPages ) ) {
525 + $subPages = static::get_subpages();
526 + }
661 527
662 - $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
663 - $primaryBackup = get_option( 'mainwp_primaryBackup' );
664 - $disableUpdateConfirmations = (int) get_option( 'mainwp_disable_update_confirmations', 0 );
528 + MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'Settings', 'Settings' );
665 529
666 - $http_error_codes = MainWP_Utility::get_http_codes();
667 - ?>
668 - <div class="ui grid field">
669 - <label class="six wide column middle aligned"><?php esc_html_e( 'Plugin advanced automatic updates', 'mainwp' ); ?></label>
670 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic plugins updates. If enabled, MainWP will update only plugins that you have marked as Trusted.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
671 - <select name="mainwp_pluginAutomaticDailyUpdate" id="mainwp_pluginAutomaticDailyUpdate" class="ui dropdown">
672 - <option value="1" <?php echo ( 1 === $snPluginAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
673 - <option value="0" <?php echo ( ( 0 === $snPluginAutomaticDailyUpdate ) || 2 === $snPluginAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
674 - </select>
675 - </div>
676 - </div>
677 - <div class="ui grid field">
678 - <label class="six wide column middle aligned"><?php esc_html_e( 'Theme advanced automatic updates', 'mainwp' ); ?></label>
679 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic themes updates. If enabled, MainWP will update only themes that you have marked as Trusted.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
680 - <select name="mainwp_themeAutomaticDailyUpdate" id="mainwp_themeAutomaticDailyUpdate" class="ui dropdown">
681 - <option value="1" <?php echo ( 1 === $snThemeAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
682 - <option value="0" <?php echo ( 0 === $snThemeAutomaticDailyUpdate || 2 === $snThemeAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
683 - </select>
684 - </div>
685 - </div>
686 - <div class="ui grid field">
687 - <label class="six wide column middle aligned"><?php esc_html_e( 'WP Core advanced automatic updates', 'mainwp' ); ?></label>
688 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic WordPress core updates.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
689 - <select name="mainwp_automaticDailyUpdate" id="mainwp_automaticDailyUpdate" class="ui dropdown">
690 - <option value="1" <?php echo ( 1 === $snAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
691 - <option value="0" <?php echo ( 0 === $snAutomaticDailyUpdate || 2 === (int) $snAutomaticDailyUpdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
692 - </select>
693 - </div>
694 - </div>
695 - <div class="ui grid field">
696 - <label class="six wide column middle aligned"><?php esc_html_e( 'Advanced automatic updates delay', 'mainwp' ); ?></label>
697 - <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'Set the number of days to delay automatic updates.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
698 - <select name="mainwp_delay_autoupdate" id="mainwp_delay_autoupdate" class="ui dropdown">
699 - <option value="0" <?php echo ( 0 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( 'Delay off', 'mainwp' ); ?></option>
700 - <option value="1" <?php echo ( 1 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '1 day', 'mainwp' ); ?></option>
701 - <option value="2" <?php echo ( 2 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '2 days', 'mainwp' ); ?></option>
702 - <option value="3" <?php echo ( 3 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '3 days', 'mainwp' ); ?></option>
703 - <option value="4" <?php echo ( 4 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '4 days', 'mainwp' ); ?></option>
704 - <option value="5" <?php echo ( 5 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '5 days', 'mainwp' ); ?></option>
705 - <option value="6" <?php echo ( 6 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '6 days', 'mainwp' ); ?></option>
706 - <option value="7" <?php echo ( 7 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '7 days', 'mainwp' ); ?></option>
707 - <option value="14" <?php echo ( 14 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '14 days', 'mainwp' ); ?></option>
708 - <option value="30" <?php echo ( 30 === $delay_autoupdate ? 'selected' : '' ); ?>><?php esc_html_e( '30 days', 'mainwp' ); ?></option>
709 - </select>
710 - </div>
711 - </div>
712 - <div class="ui grid field">
713 - <label class="six wide column middle aligned"><?php esc_html_e( 'Show WordPress language updates', 'mainwp' ); ?></label>
714 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to manage Translation updates', 'mainwp' ); ?>" data-inverted="" data-position="top left">
715 - <input type="checkbox" name="mainwp_show_language_updates" id="mainwp_show_language_updates" <?php echo ( 1 === (int) $mainwp_show_language_updates ? 'checked="true"' : '' ); ?>/>
716 - </div>
717 - </div>
718 - <div class="ui grid field">
719 - <label class="six wide column middle aligned"><?php esc_html_e( 'Update confirmations', 'mainwp' ); ?></label>
720 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Choose if you want to disable the popup confirmations when performing updates.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
721 - <select name="mainwp_disable_update_confirmations" id="mainwp_disable_update_confirmations" class="ui dropdown">
722 - <option value="0" <?php echo ( 0 === $disableUpdateConfirmations ? 'selected' : '' ); ?>><?php esc_html_e( 'Enable', 'mainwp' ); ?></option>
723 - <option value="2" <?php echo ( 2 === $disableUpdateConfirmations ? 'selected' : '' ); ?>><?php esc_html_e( 'Disable', 'mainwp' ); ?></option>
724 - <option value="1" <?php echo ( 1 === $disableUpdateConfirmations ? 'selected' : '' ); ?>><?php esc_html_e( 'Disable for single updates', 'mainwp' ); ?></option>
725 - </select>
726 - </div>
727 - </div>
728 - <div class="ui grid field">
729 - <label class="six wide column middle aligned"><?php esc_html_e( 'Check site HTTP response after update', 'mainwp' ); ?></label>
730 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want your MainWP Dashboard to check child site header response after updates.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
731 - <input type="checkbox" name="mainwp_check_http_response" id="mainwp_check_http_response" <?php echo ( ( 1 === (int) get_option( 'mainwp_check_http_response', 0 ) ) ? 'checked="true"' : '' ); ?>/>
732 - </div>
733 - </div>
734 - <div class="ui grid field">
735 - <label class="six wide column middle aligned"><?php esc_html_e( 'Ignored HTTP response statuses', 'mainwp' ); ?></label>
736 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Select response codes that you want your MainWP Dashboard to ignore.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
737 - <div class="ui multiple selection dropdown" init-value="<?php echo esc_attr( ( get_option( 'mainwp_ignore_HTTP_response_status', '' ) ) ); ?>">
738 - <input name="mainwp_ignore_http_response_status" type="hidden">
739 - <i class="dropdown icon"></i>
740 - <div class="default text"></div>
741 - <div class="menu">
742 - <?php
743 - foreach ( $http_error_codes as $error_code => $label ) {
744 - ?>
745 - <div class="item" data-value="<?php echo esc_attr( $error_code ); ?>"><?php echo esc_html( $error_code . ' (' . $label . ')' ); ?></div>
746 - <?php
747 - }
748 - ?>
749 - </div>
750 - </div>
751 - </div>
752 - </div>
753 - <?php if ( ( ( $enableLegacyBackupFeature && empty( $primaryBackup ) ) || ( empty( $enableLegacyBackupFeature ) && ! empty( $primaryBackup ) ) ) ) { ?>
754 - <div class="ui grid field mainwp-parent-toggle">
755 - <label class="six wide column middle aligned"><?php esc_html_e( 'Require a backup before an update', 'mainwp' ); ?></label>
756 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will check if full backups exists before updating.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
757 - <input type="checkbox" name="mainwp_backup_before_upgrade" id="mainwp_backup_before_upgrade" <?php echo ( 1 === (int) $backup_before_upgrade ? 'checked="true"' : '' ); ?>/>
758 - </div>
759 - </div>
760 - <div class="ui grid field mainwp-child-field" <?php echo ( 1 === (int) $backup_before_upgrade ? '' : 'style="display:none"' ); ?> >
761 - <label class="six wide column middle aligned"><?php esc_html_e( 'Days without of a full backup tolerance', 'mainwp' ); ?></label>
762 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set the number of days without of backup tolerance.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
763 - <input type="text" name="mainwp_backup_before_upgrade_days" id="mainwp_backup_before_upgrade_days" value="<?php echo esc_attr( $mainwp_backup_before_upgrade_days ); ?>" />
764 - </div>
765 - </div>
766 - <?php } ?>
530 + foreach ( $init_sub_subleftmenu as $item ) {
531 + if ( isset( $item['item_slug'] ) ) {
532 + if ( MainWP_Menu::is_disable_menu_item( 3, $item['item_slug'] ) ) {
533 + continue;
534 + }
535 + } elseif ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
536 + continue;
537 + }
767 538
768 - <div class="ui grid field">
769 - <label class="six wide column middle aligned"><?php esc_html_e( 'Abandoned plugins/themes tolerance', 'mainwp' ); ?></label>
770 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set how many days without an update before plugin or theme will be considered as abandoned.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
771 - <input type="text" name="mainwp_numberdays_Outdate_Plugin_Theme" id="mainwp_numberdays_Outdate_Plugin_Theme" value="<?php echo ( ( false === get_option( 'mainwp_numberdays_Outdate_Plugin_Theme' ) ) ? 365 : intval( get_option( 'mainwp_numberdays_Outdate_Plugin_Theme' ) ) ); ?>"/>
772 - </div>
773 - </div>
774 - <?php MainWP_Monitoring_View::render_settings(); ?>
775 - <?php MainWP_Manage_Backups::render_settings(); ?>
776 - <?php
777 - /**
778 - * Action: mainwp_settings_form_bottom
779 - *
780 - * Fires at the bottom of settings form.
781 - *
782 - * @since 4.1
783 - */
784 - do_action( 'mainwp_settings_form_bottom' );
785 - ?>
786 - <div class="ui divider"></div>
787 - <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
788 - <div style="clear:both"></div>
789 - </form>
790 - </div>
791 - </div>
792 - <?php
793 - self::render_footer( '' );
794 - }
539 + MainWP_Menu::add_left_menu( $item, 2 );
540 + }
541 + }
795 542
796 - /**
797 - * Render Timezone settings.
798 - */
799 - public static function render_timezone_settings() {
543 + /**
544 + * Render Page Header.
545 + *
546 + * @param string $shownPage The page slug shown at this moment.
547 + *
548 + * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
549 + * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
550 + * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation()
551 + */
552 + public static function render_header( $shownPage = '' ) { // phpcs:ignore -- NOSONAR - complex.
800 553
801 - $current_offset = get_option( 'gmt_offset' );
802 - $tzstring = get_option( 'timezone_string' );
803 - $check_zone_info = true;
554 + $params = array(
555 + 'title' => esc_html__( 'MainWP Settings', 'mainwp' ),
556 + );
804 557
805 - // Remove old Etc mappings. Fallback to gmt_offset.
806 - if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
807 - $tzstring = '';
808 - }
558 + MainWP_UI::render_top_header( $params );
809 559
810 - if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists.
811 - $check_zone_info = false;
812 - if ( empty( $current_offset ) ) {
813 - $tzstring = 'UTC+0';
814 - } elseif ( $current_offset < 0 ) {
815 - $tzstring = 'UTC' . $current_offset;
816 - } else {
817 - $tzstring = 'UTC+' . $current_offset;
818 - }
819 - }
560 + $renderItems = array();
820 561
821 - $timezone_format = _x( 'Y-m-d H:i:s', 'timezone date format' );
562 + foreach ( static::get_navigation_items() as $item ) {
563 + $render_item = array(
564 + 'title' => $item['title'],
565 + 'href' => $item['href'],
566 + 'active' => in_array( $shownPage, $item['active_keys'], true ),
567 + );
822 568
823 - ?>
824 - <div class="ui grid field">
825 - <label class="six wide column middle aligned"><?php esc_html_e( 'Timezone', 'mainwp' ); ?></label>
826 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Choose either a city in the same timezone as you or a %s (Coordinated Universal Time) time offset.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
827 - <select id="timezone_string" class="ui dropdown" name="timezone_string" aria-describedby="timezone-description">
828 - <?php echo wp_timezone_choice( $tzstring, get_user_locale() ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
829 - </select>
830 - <div class="ui hidden fitted divider"></div>
831 - <div class="ui secondary segment">
832 - <?php printf( esc_html__( 'Universal time is %s.' ), '<code>' . esc_html( date_i18n( $timezone_format, false, true ) ) . '</code>' ); ?>
833 - <div class="ui hidden fitted divider"></div>
834 - <?php if ( get_option( 'timezone_string' ) || ! empty( $current_offset ) ) : ?>
835 - <?php printf( esc_html__( 'Local time is %s.' ), '<code>' . esc_html( date_i18n( $timezone_format ) ) . '</code>' ); ?>
836 - <div class="ui hidden fitted divider"></div>
837 - <?php endif; ?>
838 - <?php if ( $check_zone_info && $tzstring ) : ?>
839 - <?php
840 - $now = new \DateTime( 'now', new \DateTimeZone( $tzstring ) );
841 - $dst = (bool) $now->format( 'I' );
569 + if ( ! empty( $item['before_title'] ) ) {
570 + $render_item['before_title'] = $item['before_title'];
571 + }
842 572
843 - if ( $dst ) {
844 - esc_html_e( 'This timezone is currently in daylight saving time.', 'mainwp' );
845 - } else {
846 - esc_html_e( 'This timezone is currently in standard time.', 'mainwp' );
847 - }
848 - ?>
849 - <div class="ui hidden fitted divider"></div>
850 - <?php
851 - if ( in_array( $tzstring, timezone_identifiers_list(), true ) ) {
852 - $transitions = timezone_transitions_get( timezone_open( $tzstring ), time() );
573 + if ( isset( $item['class'] ) ) {
574 + $render_item['class'] = $item['class'];
575 + }
853 576
854 - if ( ! empty( $transitions[1] ) ) {
855 - echo ' ';
856 - $message = $transitions[1]['isdst'] ? esc_html__( 'Daylight saving time begins on: %s.', 'mainwp' ) : esc_html__( 'Standard time begins on: %s.', 'mainwp' );
857 - printf( $message, '<code>' . wp_date( esc_html__( 'F j, Y' ) . ' ' . esc_html__( 'g:i a' ), esc_html( $transitions[1]['ts'] ) ) . '</code>' ); // phpcs:ignore WordPress.Security.EscapeOutput
858 - } else {
859 - esc_html_e( 'This timezone does not observe daylight saving time.', 'mainwp' );
860 - }
861 - }
862 - ?>
863 - <?php endif; ?>
864 - </div>
865 - </div>
866 - </div>
867 - <?php
868 - }
577 + $renderItems[] = $render_item;
578 + }
869 579
870 - /**
871 - * Render Date/Time settings.
872 - */
873 - public static function render_datetime_settings() {
874 - ?>
875 - <div class="ui grid field">
876 - <label class="six wide column middle aligned"><?php esc_html_e( 'Date format', 'mainwp' ); ?></label>
877 - <div class="ten wide column fieldset-wrapper" data-tooltip="<?php esc_attr_e( 'Choose the display format for date.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
878 - <?php
879 - /**
880 - * Filters the default date formats.
881 - *
882 - * @since 2.7.0
883 - * @since 4.0.0 Added ISO date standard YYYY-MM-DD format.
884 - *
885 - * @param string[] $default_date_formats Array of default date formats.
886 - */
887 - $date_formats = array_unique( apply_filters( 'date_formats', array( esc_html__( 'F j, Y' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) );
580 + MainWP_UI::render_page_navigation( $renderItems, 'nav_mainwp_settings' );
581 + }
888 582
889 - $custom = true;
583 + /**
584 + * Close the HTML container.
585 + */
586 + public static function render_footer() {
587 + echo '</div>';
588 + }
890 589
891 - foreach ( $date_formats as $format ) {
892 - echo "\t<label><input type='radio' name='date_format' value='" . esc_attr( $format ) . "'";
893 - if ( get_option( 'date_format' ) === $format ) { // checked() uses "==" rather than "===".
894 - echo " checked='checked'";
895 - $custom = false;
896 - }
897 - echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
898 - }
590 + /**
591 + * Method handle_settings_post().
592 + *
593 + * This class handles the $_POST of Settings Options.
594 + *
595 + * @uses MainWP_DB::instance()
596 + * @uses MainWP_Utility::update_option()
597 + *
598 + * @return boolean True|False Posts On True.
599 + *
600 + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
601 + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
602 + * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
603 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
604 + */
605 + public static function handle_settings_post() { // phpcs:ignore -- NOSONAR - complex.
606 + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) {
607 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
608 + $userExtension->pluginDir = '';
899 609
900 - echo '<label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
901 - checked( $custom );
902 - echo '/> <span class="date-time-text date-time-custom-text">' . esc_html__( 'Custom:' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom date format in the following field' ) . '</span></span></label>' .
903 - '<label for="date_format_custom" class="screen-reader-text">' . esc_html__( 'Custom date format:' ) . '</label>' .
904 - '<input type="text" name="date_format_custom" id="date_format_custom" value="' . esc_attr( get_option( 'date_format' ) ) . '" class="small-text" />' .
905 - '<br />' .
906 - '<em><strong>' . esc_html__( 'Preview:' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'date_format' ) ) ) . '</span>' .
907 - "<span class='spinner'></span>\n" . '</em>';
908 - ?>
909 - </div>
910 - </div>
610 + MainWP_DB_Common::instance()->update_user_extension( $userExtension );
611 + if ( MainWP_System_Utility::is_admin() ) {
911 612
912 - <div class="ui grid field">
913 - <label class="six wide column middle aligned"><?php esc_html_e( 'Time format', 'mainwp' ); ?></label>
914 - <div class="ten wide column fieldset-wrapper" data-tooltip="<?php esc_attr_e( 'Choose the display format for time.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
915 - <?php
916 - /**
917 - * Filters the default time formats.
918 - *
919 - * @since 2.7.0
920 - *
921 - * @param string[] $default_time_formats Array of default time formats.
922 - */
923 - $time_formats = array_unique( apply_filters( 'time_formats', array( esc_html__( 'g:i a' ), 'g:i A', 'H:i' ) ) );
613 + $old_settings = self::get_all_settings_values();
924 614
925 - $custom = true;
615 + /**
616 + * Action: mainwp_before_save_general_settings
617 + *
618 + * Fires before general settings save.
619 + *
620 + * @since 4.1
621 + */
622 + do_action( 'mainwp_before_save_general_settings', $_POST );
926 623
927 - foreach ( $time_formats as $format ) {
928 - echo "\t<label><input type='radio' name='time_format' value='" . esc_attr( $format ) . "'";
929 - if ( get_option( 'time_format' ) === $format ) { // checked() uses "==" rather than "===".
930 - echo " checked='checked'";
931 - $custom = false;
932 - }
933 - echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
934 - }
935 - echo '<label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
936 - checked( $custom );
937 - echo '/> <span class="date-time-text date-time-custom-text">' . esc_html__( 'Custom:' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom time format in the following field' ) . '</span></span></label>' .
938 - '<label for="time_format_custom" class="screen-reader-text">' . esc_html__( 'Custom time format:' ) . '</label>' .
939 - '<input type="text" name="time_format_custom" id="time_format_custom" value="' . esc_attr( get_option( 'time_format' ) ) . '" class="small-text" />' .
940 - '<br />' .
941 - '<em><strong>' . esc_html__( 'Preview:' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'time_format' ) ) ) . '</span>' .
942 - "<span class='spinner'></span>\n" . '</em>';
943 - ?>
944 - </div>
945 - </div>
946 - <script type="text/javascript">
947 - jQuery(document).ready( function($) {
948 - $( 'input[name="date_format"]' ).on( 'click', function() {
949 - if ( 'date_format_custom_radio' !== $( this ).attr( 'id' ) )
950 - $( 'input[name="date_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
951 - } );
624 + $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) );
625 + MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val );
626 + $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) );
627 + MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val );
628 + $val = ( ! isset( $_POST['mainwp_transAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_transAutomaticDailyUpdate'] ) );
629 + MainWP_Utility::update_option( 'mainwp_transAutomaticDailyUpdate', $val );
630 + $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) );
631 + MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val );
632 + $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 );
633 + MainWP_Utility::update_option( 'mainwp_show_language_updates', $val );
634 + $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) );
635 + MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val );
636 + $val = ( ! isset( $_POST['mainwp_backup_before_upgrade'] ) ? 0 : 1 );
637 + MainWP_Utility::update_option( 'mainwp_backup_before_upgrade', $val );
638 + $val = ( ! isset( $_POST['mainwp_backup_before_upgrade_days'] ) ? 7 : intval( $_POST['mainwp_backup_before_upgrade_days'] ) );
639 + MainWP_Utility::update_option( 'mainwp_backup_before_upgrade_days', $val );
952 640
953 - $( 'input[name="date_format_custom"]' ).on( 'click input', function() {
954 - $( '#date_format_custom_radio' ).prop( 'checked', true );
955 - } );
641 + if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) {
642 + MainWP_Utility::update_option( 'mainwp_maximumComments', isset( $_POST['mainwp_maximumComments'] ) ? intval( $_POST['mainwp_maximumComments'] ) : 50 );
643 + }
956 644
957 - $( 'input[name="time_format"]' ).on( 'click', function() {
958 - if ( 'time_format_custom_radio' !== $(this).attr( 'id' ) )
959 - $( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
960 - } );
645 + $current_timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
646 + $new_timeDailyUpdate = isset( $_POST['mainwp_timeDailyUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_timeDailyUpdate'] ) ) : '';
961 647
962 - $( 'input[name="time_format_custom"]' ).on( 'click input', function() {
963 - $( '#time_format_custom_radio' ).prop( 'checked', true );
964 - } );
648 + if ( $current_timeDailyUpdate !== $new_timeDailyUpdate ) {
649 + MainWP_Utility::update_option( 'mainwp_timeDailyUpdate', $new_timeDailyUpdate );
650 + }
965 651
966 - $( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() {
967 - var format = $( this ),
968 - fieldset = format.closest( '.fieldset-wrapper' ),
969 - example = fieldset.find( '.example' ),
970 - spinner = fieldset.find( '.spinner' );
652 + $old_freq = (int) get_option( 'mainwp_frequencyDailyUpdate', 2 );
653 + $new_freq = ( isset( $_POST['mainwp_frequencyDailyUpdate'] ) ? intval( $_POST['mainwp_frequencyDailyUpdate'] ) : 2 );
654 + if ( $old_freq !== $new_freq ) {
655 + MainWP_Utility::update_option( 'mainwp_frequencyDailyUpdate', $new_freq );
656 + MainWP_Logger::instance()->log_update_check( 'New frequency daily :: ' . $new_freq );
657 + }
971 658
972 - // Debounce the event callback while users are typing.
973 - clearTimeout( $.data( this, 'timer' ) );
974 - $( this ).data( 'timer', setTimeout( function() {
975 - // If custom date is not empty.
976 - if ( format.val() ) {
977 - spinner.addClass( 'is-active' );
659 + $curr_frequency_updates = get_option( 'mainwp_frequency_AutoUpdate', 'daily' );
660 + $new_frequency_updates = isset( $_POST['mainwp_frequency_AutoUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_frequency_AutoUpdate'] ) ) : 'daily';
661 + if ( $new_frequency_updates !== $curr_frequency_updates ) {
662 + MainWP_Utility::update_option( 'mainwp_frequency_AutoUpdate', $new_frequency_updates );
663 + }
978 664
979 - $.post( ajaxurl, {
980 - action: 'date_format_custom' === format.attr( 'name' ) ? 'date_format' : 'time_format',
981 - date : format.val()
982 - }, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
983 - }
984 - }, 500 ) );
985 - } );
986 - });
987 - </script>
988 - <?php
989 - }
665 + $curr_day_updates = (int) get_option( 'mainwp_dayinweek_AutoUpdate', 0 );
666 + $new_day_updates = isset( $_POST['mainwp_dayinweek_AutoUpdate'] ) ? intval( wp_unslash( $_POST['mainwp_dayinweek_AutoUpdate'] ) ) : 0;
667 + if ( $new_day_updates !== $curr_day_updates ) {
668 + MainWP_Utility::update_option( 'mainwp_dayinweek_AutoUpdate', $new_day_updates );
669 + }
990 670
991 - /**
992 - * Method get_websites_automatic_update_time()
993 - *
994 - * Get websites automatic update time.
995 - *
996 - * @return mixed array
997 - *
998 - * @uses \MainWP\Dashboard\MainWP_DB::get_websites_last_automatic_sync()
999 - * @uses \MainWP\Dashboard\MainWP_DB::get_websites_count_where_dts_automatic_sync_smaller_then_start()
1000 - * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
1001 - */
1002 - public static function get_websites_automatic_update_time() {
1003 - $lastAutomaticUpdate = MainWP_DB::instance()->get_websites_last_automatic_sync();
1004 - $lasttimeAutomatic = get_option( 'mainwp_updatescheck_last_timestamp' );
1005 - $lasttimeStartAutomatic = get_option( 'mainwp_updatescheck_start_last_timestamp' );
1006 - $local_timestamp = MainWP_Utility::get_timestamp();
1007 - $running = get_option( 'mainwp_cron_checksites_running' );
671 + $curr_dayinmonth_updates = (int) get_option( 'mainwp_dayinmonth_AutoUpdate', 1 );
672 + $new_dayinmonth_updates = isset( $_POST['mainwp_dayinmonth_AutoUpdate'] ) ? intval( wp_unslash( $_POST['mainwp_dayinmonth_AutoUpdate'] ) ) : 1;
673 + if ( $new_dayinmonth_updates !== $curr_dayinmonth_updates ) {
674 + MainWP_Utility::update_option( 'mainwp_dayinmonth_AutoUpdate', $new_dayinmonth_updates );
675 + }
1008 676
1009 - if ( empty( $lasttimeStartAutomatic ) && ! empty( $lasttimeAutomatic ) ) {
1010 - $lasttimeStartAutomatic = $lasttimeAutomatic;
1011 - }
677 + $curr_time_updates = get_option( 'mainwp_time_AutoUpdate', '00:00' );
678 + $new_time_updates = isset( $_POST['mainwp_time_AutoUpdate'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_time_AutoUpdate'] ) ) : '00:00';
679 + if ( $new_time_updates !== $curr_time_updates ) {
680 + MainWP_Utility::update_option( 'mainwp_time_AutoUpdate', $new_time_updates );
681 + }
1012 682
1013 - if ( empty( $lastAutomaticUpdate ) ) {
1014 - $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1015 - } elseif ( 'yes' === $running && ( 0 < MainWP_DB::instance()->get_websites_count_where_dts_automatic_sync_smaller_then_start( $lasttimeStartAutomatic ) || 0 < MainWP_DB::instance()->get_websites_check_updates_count( $lasttimeStartAutomatic ) ) ) {
1016 - $nextAutomaticUpdate = esc_html__( 'Processing your websites.', 'mainwp' );
1017 - } else {
1018 - $next_time = MainWP_System_Cron_Jobs::get_next_time_automatic_update_to_show();
1019 - if ( $next_time < $local_timestamp + 5 * MINUTE_IN_SECONDS ) {
1020 - $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1021 - } else {
1022 - $nextAutomaticUpdate = MainWP_Utility::format_timestamp( $next_time );
1023 - }
1024 - }
683 + MainWP_Cron_Jobs_Auto_Updates::set_next_auto_updates_time();
1025 684
1026 - if ( empty( $lastAutomaticUpdate ) ) {
1027 - $lastAutomaticUpdate = esc_html__( 'Never', 'mainwp' );
1028 - } else {
1029 - $lastAutomaticUpdate = MainWP_Utility::format_timestamp( $lastAutomaticUpdate );
1030 - }
685 + $new_delay = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 );
686 + MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $new_delay );
1031 687
1032 - return array(
1033 - 'last' => $lastAutomaticUpdate,
1034 - 'next' => $nextAutomaticUpdate,
1035 - );
1036 - }
688 + $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 );
689 + $user = wp_get_current_user();
690 + if ( $user ) {
691 + update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
692 + }
1037 693
1038 - /**
1039 - * Returns false or the location of the OpenSSL Lib File.
1040 - *
1041 - * @return mixed false|opensslLibLocation
1042 - *
1043 - * @uses \MainWP\Dashboard\MainWP_Server_Information_Handler::is_openssl_config_warning()
1044 - */
1045 - public static function show_openssl_lib_config() {
1046 - if ( MainWP_Server_Information_Handler::is_openssl_config_warning() ) {
1047 - return true;
1048 - } else {
1049 - return false;
1050 - }
1051 - }
694 + MainWP_Utility::update_option( 'mainwp_numberdays_Outdate_Plugin_Theme', ! empty( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) ? intval( $_POST['mainwp_numberdays_Outdate_Plugin_Theme'] ) : 365 );
1052 695
1053 - /**
1054 - * Render Advanced Options Subpage.
1055 - *
1056 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
1057 - */
1058 - public static function render_advanced() { //phpcs:ignore -- complex method.
1059 - if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
1060 - mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
1061 - return;
1062 - }
696 + $actions_notification_enable = ( isset( $_POST['mainwp_site_actions_notification_enable'] ) ? 1 : 0 );
697 + MainWP_Utility::update_option( 'mainwp_site_actions_notification_enable', $actions_notification_enable );
1063 698
1064 - if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) {
699 + //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
700 + // Handle custom date/time formats.
701 + if ( ! empty( $_POST['date_format'] ) && isset( $_POST['date_format_custom'] )
702 + && '\c\u\s\t\o\m' === wp_unslash( $_POST['date_format'] )
703 + ) {
704 + $_POST['date_format'] = wp_unslash( $_POST['date_format_custom'] );
705 + }
1065 706
1066 - /**
1067 - * Action: mainwp_before_save_advanced_settings
1068 - *
1069 - * Fires before save advanced settings.
1070 - *
1071 - * @since 4.1
1072 - */
1073 - do_action( 'mainwp_before_save_advanced_settings', $_POST );
707 + if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] )
708 + && '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] )
709 + ) {
710 + $_POST['time_format'] = wp_unslash( $_POST['time_format_custom'] );
711 + }
1074 712
1075 - MainWP_Utility::update_option( 'mainwp_maximumRequests', ! empty( $_POST['mainwp_maximumRequests'] ) ? intval( $_POST['mainwp_maximumRequests'] ) : 4 );
1076 - MainWP_Utility::update_option( 'mainwp_minimumDelay', ! empty( $_POST['mainwp_minimumDelay'] ) ? intval( $_POST['mainwp_minimumDelay'] ) : 200 );
1077 - MainWP_Utility::update_option( 'mainwp_maximumIPRequests', ! empty( $_POST['mainwp_maximumIPRequests'] ) ? intval( $_POST['mainwp_maximumIPRequests'] ) : 1 );
1078 - MainWP_Utility::update_option( 'mainwp_minimumIPDelay', ! empty( $_POST['mainwp_minimumIPDelay'] ) ? intval( $_POST['mainwp_minimumIPDelay'] ) : 1000 );
1079 - MainWP_Utility::update_option( 'mainwp_maximumSyncRequests', ! empty( $_POST['mainwp_maximumSyncRequests'] ) ? intval( $_POST['mainwp_maximumSyncRequests'] ) : 8 );
1080 - MainWP_Utility::update_option( 'mainwp_maximumInstallUpdateRequests', ! empty( $_POST['mainwp_maximumInstallUpdateRequests'] ) ? intval( $_POST['mainwp_maximumInstallUpdateRequests'] ) : 3 );
1081 - MainWP_Utility::update_option( 'mainwp_sslVerifyCertificate', isset( $_POST['mainwp_sslVerifyCertificate'] ) ? 1 : 0 );
1082 - MainWP_Utility::update_option( 'mainwp_connect_signature_algo', isset( $_POST['mainwp_settings_openssl_alg'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_settings_openssl_alg'] ) ) : 0 );
1083 - MainWP_Utility::update_option( 'mainwp_verify_connection_method', isset( $_POST['mainwp_settings_verify_connection_method'] ) ? intval( $_POST['mainwp_settings_verify_connection_method'] ) : 0 );
1084 - MainWP_Utility::update_option( 'mainwp_forceUseIPv4', isset( $_POST['mainwp_forceUseIPv4'] ) ? 1 : 0 );
1085 - MainWP_Utility::update_option( 'mainwp_wp_cron', ( ! isset( $_POST['mainwp_options_wp_cron'] ) ? 0 : 1 ) );
1086 - MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) );
713 + if ( isset( $_POST['timezone_string'] ) ) {
714 + // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
715 + if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', wp_unslash( $_POST['timezone_string'] ) ) ) {
716 + $_POST['gmt_offset'] = wp_unslash( $_POST['timezone_string'] );
717 + $_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', wp_unslash( $_POST['gmt_offset'] ) ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
718 + $_POST['timezone_string'] = '';
719 + }
1087 720
1088 - if ( isset( $_POST['mainwp_openssl_lib_location'] ) ) {
1089 - $openssl_loc = ! empty( $_POST['mainwp_openssl_lib_location'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_openssl_lib_location'] ) ) : '';
1090 - MainWP_Utility::update_option( 'mainwp_opensslLibLocation', $openssl_loc );
1091 - }
721 + $options = array(
722 + 'gmt_offset',
723 + 'date_format',
724 + 'time_format',
725 + 'timezone_string',
726 + );
1092 727
1093 - /**
1094 - * Action: mainwp_after_save_advanced_settings
1095 - *
1096 - * Fires after advanced settings save.
1097 - *
1098 - * @since 4.1
1099 - */
1100 - do_action( 'mainwp_after_save_advanced_settings', $_POST );
1101 - }
1102 - self::render_header( 'Advanced' );
1103 - ?>
728 + foreach ( $options as $option ) {
729 + $value = null;
730 + if ( isset( $_POST[ $option ] ) ) {
731 + $value = wp_unslash( $_POST[ $option ] );
732 + if ( ! is_array( $value ) ) {
733 + $value = trim( $value );
734 + }
735 + }
736 + update_option( $option, $value );
737 + }
738 + }
739 + //phpcs:enable
1104 740
1105 - <div id="mainwp-advanced-settings" class="ui segment">
1106 - <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-advanced-settings-info-notice' ) ) : ?>
1107 - <div class="ui info message">
1108 - <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-advanced-settings-info-notice"></i>
1109 - <?php echo esc_html__( 'Set how many requests are performed at once and delay between requests in order to optimize your MainWP Dashboard performance. Both Cross IP and IP Settings handle the majority of work connecting to your Child sites, while the sync, update, and installation request have specialized options under the Frontend Requests Settings section.', 'mainwp' ); ?>
1110 - </div>
1111 - <?php endif; ?>
1112 - <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) : ?>
1113 - <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
1114 - <?php endif; ?>
1115 - <div class="ui form">
1116 - <form method="POST" action="">
1117 - <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1118 - <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'SettingsAdvanced' ) ); ?>" />
1119 - <?php
741 + MainWP_Utility::update_option( 'mainwp_use_favicon', 1 );
742 + /**
743 + * Action: mainwp_after_save_general_settings
744 + *
745 + * Fires after save general settings.
746 + *
747 + * @since 4.1
748 + */
749 + do_action( 'mainwp_after_save_general_settings', $_POST );
1120 750
1121 - /**
1122 - * Action: mainwp_advanced_settings_form_top
1123 - *
1124 - * Fires at the top of advanced settings form.
1125 - *
1126 - * @since 4.1
1127 - */
1128 - do_action( 'mainwp_advanced_settings_form_top' );
751 + $new_settings = self::get_all_settings_values();
1129 752
1130 - if ( self::show_openssl_lib_config() ) {
1131 - $openssl_loc = MainWP_System_Utility::get_openssl_conf();
1132 - ?>
1133 - <h3 class="ui dividing header">
1134 - <?php esc_html_e( 'OpenSSL Settings', 'mainwp' ); ?>
1135 - <div class="sub header"><?php esc_html_e( 'Due to bug with PHP on some servers it is required to set the OpenSSL Library location so MainWP Dashboard can connect to your child sites.', 'mainwp' ); ?></div>
1136 - </h3>
1137 - <div class="ui grid field">
1138 - <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL.cnf location', 'mainwp' ); ?></label>
1139 - <div class="ten wide column ui field">
1140 - <input type="text" name="mainwp_openssl_lib_location" value="<?php echo esc_html( $openssl_loc ); ?>">
1141 - <em><?php esc_html_e( 'If your openssl.cnf file is saved to a different path from what is entered please enter your exact path.', 'mainwp' ); ?> <?php printf( esc_html__( 'If you are not sure how to find the openssl.cnf location, please %1$scheck this help document%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/how-to-find-the-openssl-cnf-file/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?></em>
1142 - <em><?php esc_html_e( 'If you have confirmed the placement of your openssl.cnf and are still receiving an error banner, click the "Error Fixed" button to dismiss it.', 'mainwp' ); ?></em>
1143 - </div>
1144 - </div>
1145 - <?php } ?>
753 + /**
754 + * Action: mainwp_after_save_settings
755 + *
756 + * Fires after save settings.
757 + *
758 + * @since 6.0
759 + *
760 + * @param array $new_settings The new settings.
761 + * @param array $old_settings The old settings.
762 + */
763 + do_action( 'mainwp_after_save_settings', $new_settings, $old_settings );
1146 764
1147 - <h3 class="ui dividing header"><?php esc_html_e( 'Cross IP Settings', 'mainwp' ); ?></h3>
765 + }
1148 766
1149 - <div class="ui grid field">
1150 - <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous requests (Default: 4)', 'mainwp' ); ?></label>
1151 - <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'If too many requests are sent out, they will begin to time out. This causes your sites to be shown as offline while they are up and running.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1152 - <input type="text" name="mainwp_maximumRequests" id="mainwp_maximumRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumRequests' ) ) ? 4 : esc_attr( get_option( 'mainwp_maximumRequests' ) ) ); ?>"/>
1153 - </div>
1154 - </div>
767 + return true;
768 + }
1155 769
1156 - <div class="ui grid field">
1157 - <label class="six wide column middle aligned"><?php esc_html_e( 'Minimum delay between requests (Default: 200)', 'mainwp' ); ?></label>
1158 - <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control minimum time delay between two requests.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1159 - <input type="text" name="mainwp_minimumDelay" id="mainwp_minimumDelay" value="<?php echo ( ( false === get_option( 'mainwp_minimumDelay' ) ) ? 200 : esc_attr( get_option( 'mainwp_minimumDelay' ) ) ); ?>"/>
1160 - </div>
1161 - </div>
770 + return false;
771 + }
1162 772
1163 - <h3 class="ui dividing header"><?php esc_html_e( 'Per IP Settings', 'mainwp' ); ?></h3>
773 + /**
774 + * Method get_all_settings_values().
775 + *
776 + * @param mixed $keys_only True if get Keys only.
777 + *
778 + * @return array All Settings Fields.
779 + */
780 + public static function get_all_settings_values( $keys_only = false ) {
781 + $keys = array(
782 + 'mainwp_hide_update_everything',
783 + 'mainwp_pluginAutomaticDailyUpdate',
784 + 'mainwp_themeAutomaticDailyUpdate',
785 + 'mainwp_transAutomaticDailyUpdate',
786 + 'mainwp_automaticDailyUpdate',
787 + 'mainwp_show_language_updates',
788 + 'mainwp_disable_update_confirmations',
789 + 'mainwp_backup_before_upgrade',
790 + 'mainwp_backup_before_upgrade_days',
791 + 'mainwp_maximumComments',
792 + 'mainwp_automatic_update_next_run_timestamp',
793 + 'mainwp_delay_autoupdate',
794 + 'mainwp_numberdays_Outdate_Plugin_Theme',
795 + 'mainwp_check_http_response',
796 + 'mainwp_check_http_response_method',
797 + 'mainwp_site_actions_notification_enable',
798 + 'mainwp_use_favicon',
799 + 'mainwp_backupsOnServer',
800 + 'mainwp_maximumFileDescriptors',
801 + 'mainwp_maximumFileDescriptorsAuto',
802 + 'mainwp_backupOnExternalSources',
803 + 'mainwp_archiveFormat',
804 + 'mainwp_notificationOnBackupFail',
805 + 'mainwp_notificationOnBackupStart',
806 + 'mainwp_chunkedBackupTasks',
807 + 'mainwp_primaryBackup',
808 + 'mainwp_enableLegacyBackupFeature',
809 + 'mainwp_global_uptime_monitoring_settings',
810 + 'mainwp_disableSitesHealthMonitoring',
811 + 'mainwp_sitehealthThreshold',
812 + 'mainwp_maximumRequests',
813 + 'mainwp_minimumDelay',
814 + 'mainwp_maximumIPRequests',
815 + 'mainwp_minimumIPDelay',
816 + 'mainwp_maximumSyncRequests',
817 + 'mainwp_maximumInstallUpdateRequests',
818 + 'mainwp_sslVerifyCertificate',
819 + 'mainwp_connect_signature_algo',
820 + 'mainwp_verify_connection_method',
821 + 'mainwp_forceUseIPv4',
822 + 'mainwp_wp_cron',
823 + 'mainwp_warm_cache_pages_ttl',
824 + 'mainwp_optimize',
825 + 'mainwp_maximum_uptime_monitoring_requests',
826 + 'mainwp_chunksitesnumber',
827 + 'mainwp_chunksleepinterval',
828 + 'mainwp_settings_sync_data',
829 + 'mainwp_module_log_settings',
830 + 'mainwp_module_log_settings_logs_selection_data',
831 + 'mainwp_uptimecheck_running',
832 + 'mainwp_uptimecheck_auto_main_counter_lasttime_started',
833 + 'mainwp_enable_guided_tours',
834 + 'mainwp_enable_guided_chatbase',
835 + 'mainwp_enable_guided_video',
836 + 'mainwp_enable_cloudways_api',
837 + 'mainwp_enable_gridpane_api',
838 + 'mainwp_enable_vultr_api',
839 + 'mainwp_enable_linode_api',
840 + 'mainwp_enable_digitalocean_api',
841 + 'mainwp_enable_cpanel_api',
842 + 'mainwp_enable_plesk_api',
843 + 'mainwp_enable_kinsta_api',
844 + );
1164 845
1165 - <div class="ui grid field">
1166 - <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous requests per IP (Default: 1)', 'mainwp' ); ?></label>
1167 - <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'If too many requests are sent out, they will begin to time out. This causes your sites to be shown as offline while they are up and running.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1168 - <input type="text" name="mainwp_maximumIPRequests" id="mainwp_maximumIPRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumIPRequests' ) ) ? 1 : esc_attr( get_option( 'mainwp_maximumIPRequests' ) ) ); ?>"/>
1169 - </div>
1170 - </div>
846 + if ( $keys_only ) {
847 + return $keys;
848 + }
1171 849
1172 - <div class="ui grid field">
1173 - <label class="six wide column middle aligned"><?php esc_html_e( 'Minimum delay between requests to the same IP (Default: 1000)', 'mainwp' ); ?></label>
1174 - <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control minimum time delay between two requests.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1175 - <input type="text" name="mainwp_minimumIPDelay" id="mainwp_minimumIPDelay" value="<?php echo ( ( false === get_option( 'mainwp_minimumIPDelay' ) ) ? 1000 : esc_attr( get_option( 'mainwp_minimumIPDelay' ) ) ); ?>"/>
1176 - </div>
1177 - </div>
850 + $values = array();
851 + foreach ( $keys as $key ) {
852 + $values[ $key ] = get_option( $key );
853 + }
854 + return $values;
855 + }
1178 856
1179 - <h3 class="ui dividing header"><?php esc_html_e( 'Frontend Request Settings', 'mainwp' ); ?></h3>
857 + /**
858 + * Render the MainWP Settings Page.
859 + *
860 + * @uses \MainWP\Dashboard\MainWP_Monitoring_View
861 + * @uses \MainWP\Dashboard\MainWP_Manage_Backups::render_settings()
862 + * @uses \MainWP\Dashboard\MainWP_Utility::get_http_codes()
863 + */
864 + public static function render() { //phpcs:ignore -- NOSONAR - complex method.
865 + if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
866 + \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
867 + return;
868 + }
1180 869
1181 - <div class="ui grid field">
1182 - <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous sync requests (Default: 8)', 'mainwp' ); ?></label>
1183 - <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control how many sites your MainWP Dashboard should sync at once.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1184 - <input type="text" name="mainwp_maximumSyncRequests" id="mainwp_maximumSyncRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumSyncRequests' ) ) ? 8 : esc_attr( get_option( 'mainwp_maximumSyncRequests' ) ) ); ?>"/>
1185 - </div>
1186 - </div>
870 + static::render_header( '' );
871 + ?>
872 + <div id="mainwp-general-settings" class="ui padded segment">
1187 873
1188 - <div class="ui grid field">
1189 - <label class="six wide column middle aligned"><?php esc_html_e( 'Maximum simultaneous install and update requests (Default: 3)', 'mainwp' ); ?></label>
1190 - <div class="ten wide column ui input" data-tooltip="<?php esc_attr_e( 'This option allows you to control how many update and install requests your MainWP Dashboard should process at once.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1191 - <input type="text" name="mainwp_maximumInstallUpdateRequests" id="mainwp_maximumInstallUpdateRequests" value="<?php echo ( ( false === get_option( 'mainwp_maximumInstallUpdateRequests' ) ) ? 3 : esc_attr( get_option( 'mainwp_maximumInstallUpdateRequests' ) ) ); ?>"/>
1192 - </div>
1193 - </div>
874 + <?php if ( isset( $_GET['message'] ) && 'saved' === $_GET['message'] ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
875 + <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
876 + <?php endif; ?>
877 + <div class="ui form">
878 + <form method="POST" action="admin.php?page=Settings" id="mainwp-settings-page-form">
879 + <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
880 + <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'Settings' ) ); ?>" />
881 + <?php
882 + /**
883 + * Action: mainwp_settings_form_top
884 + *
885 + * Fires at the top of settings form.
886 + *
887 + * @since 4.1
888 + */
889 + do_action( 'mainwp_settings_form_top' );
890 + ?>
891 + <h3 class="ui dividing header">
892 + <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-general' ); ?>
893 + <?php esc_html_e( 'General Settings', 'mainwp' ); ?></h3>
894 + <?php
895 + $timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
896 + $frequencyDailyUpdate = (int) get_option( 'mainwp_frequencyDailyUpdate', 2 );
897 + $run_timestamp = MainWP_System_Cron_Jobs::get_timestamp_from_hh_mm( $timeDailyUpdate );
898 + $delay_autoupdate = (int) get_option( 'mainwp_delay_autoupdate', 1 );
1194 899
1195 - <h3 class="ui dividing header"><?php esc_html_e( 'Miscellaneous Settings', 'mainwp' ); ?></h3>
1196 - <div class="ui grid field">
1197 - <label class="six wide column middle aligned"><?php esc_html_e( 'Optimize data loading', 'mainwp' ); ?></label>
1198 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will cache updates for faster loading.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1199 - <input type="checkbox" name="mainwp_optimize" id="mainwp_optimize" <?php echo ( ( 1 === (int) get_option( 'mainwp_optimize', 1 ) ) ? 'checked="true"' : '' ); ?> /><label><?php esc_html_e( 'Default: Off', 'mainwp' ); ?></label>
1200 - </div>
1201 - </div>
1202 - <div class="ui grid field">
1203 - <label class="six wide column middle aligned"><?php esc_html_e( 'Use WP Cron', 'mainwp' ); ?></label>
1204 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Disabling this option will disable the WP Cron so all scheduled events will stop working.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1205 - <input type="checkbox" name="mainwp_options_wp_cron" id="mainwp_options_wp_cron" <?php echo ( ( 1 === (int) get_option( 'mainwp_wp_cron' ) ) || ( false === get_option( 'mainwp_wp_cron' ) ) ? 'checked="true"' : '' ); ?>/><label><?php esc_html_e( 'Default: On', 'mainwp' ); ?></label>
1206 - </div>
1207 - </div>
1208 - <div class="ui grid field" >
1209 - <label class="six wide column middle aligned"><?php esc_html_e( 'Verify SSL certificate', 'mainwp' ); ?></label>
1210 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will verify the SSL Certificate on your Child Site (if exists) while connecting the Child Site.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1211 - <input type="checkbox" name="mainwp_sslVerifyCertificate" id="mainwp_sslVerifyCertificate" value="checked" <?php echo ( ( false === get_option( 'mainwp_sslVerifyCertificate' ) ) || ( 1 === (int) get_option( 'mainwp_sslVerifyCertificate' ) ) ) ? 'checked="checked"' : ''; ?>/><label><?php esc_html_e( 'Default: On', 'mainwp' ); ?></label>
1212 - </div>
1213 - </div>
1214 - <?php
1215 - $general_verify_con = (int) get_option( 'mainwp_verify_connection_method', 0 );
1216 - ?>
1217 - <div class="ui grid field">
1218 - <label class="six wide column middle aligned"><?php esc_html_e( 'Verify connection method', 'mainwp' ); ?></label>
1219 - <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Select Verify connection method. If you are not sure, select "Default".', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1220 - <select class="ui dropdown" id="mainwp_settings_verify_connection_method" name="mainwp_settings_verify_connection_method">
1221 - <option <?php echo ( empty( $general_verify_con ) || 1 === $general_verify_con ) ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'OpenSSL (default)', 'mainwp' ); ?></option>
1222 - <option <?php echo ( 2 === $general_verify_con ) ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'PHPSECLIB (fallback)', 'mainwp' ); ?></option>
1223 - </select>
1224 - </div>
1225 - </div>
1226 - <?php
1227 - $sign_note = MainWP_Connect_Lib::get_connection_algo_settings_note();
1228 - $sign_algs = MainWP_System_Utility::get_open_ssl_sign_algos();
1229 - $general_sign_alg = get_option( 'mainwp_connect_signature_algo', false );
1230 - if ( false === $general_sign_alg ) {
1231 - $general_sign_alg = defined( 'OPENSSL_ALGO_SHA256' ) ? OPENSSL_ALGO_SHA256 : 1;
1232 - MainWP_Utility::update_option( 'mainwp_connect_signature_algo', $general_sign_alg );
1233 - } else {
1234 - $general_sign_alg = intval( $general_sign_alg );
1235 - }
1236 - ?>
1237 - <div class="ui grid field mainwp-hide-elemenent-sign-algo" <?php echo ( 2 === $general_verify_con ) ? 'style="display:none;"' : ''; ?> >
1238 - <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL signature algorithm', 'mainwp' ); ?></label>
1239 - <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Select OpenSSL signature algorithm. If you are not sure, select "Default".', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1240 - <select class="ui dropdown" id="mainwp_settings_openssl_alg" name="mainwp_settings_openssl_alg">
1241 - <?php
1242 - foreach ( $sign_algs as $val => $text ) {
1243 - ?>
1244 - <option <?php echo ( $val === $general_sign_alg ) ? 'selected' : ''; ?> value="<?php echo esc_attr( $val ); ?>"><?php echo esc_html( $text ); ?></option>
1245 - <?php
1246 - }
1247 - ?>
1248 - </select>
1249 - <div class="ui yellow message mainwp-hide-elemenent-sign-algo-note" <?php echo ( 1 === $general_sign_alg ) ? '' : 'style="display:none;"'; ?>><?php echo esc_html( $sign_note ); ?></div>
1250 - </div>
1251 - </div>
1252 - <div class="ui grid field">
1253 - <label class="six wide column middle aligned"><?php esc_html_e( 'Force IPv4', 'mainwp' ); ?></label>
1254 - <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to force your MainWP Dashboard to use IPv4 while tryig to connect child sites.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1255 - <input type="checkbox" name="mainwp_forceUseIPv4" id="mainwp_forceUseIPv4" value="checked" <?php echo ( 1 === (int) get_option( 'mainwp_forceUseIPv4' ) ) ? 'checked="checked"' : ''; ?>/><label><?php esc_html_e( 'Default: Off', 'mainwp' ); ?></label>
1256 - </div>
1257 - </div>
1258 - <?php
900 + ?>
901 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general">
902 + <label class="six wide column middle aligned">
903 + <?php
904 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_timeDailyUpdate', $timeDailyUpdate );
905 + esc_html_e( 'Daily sync time', 'mainwp' );
906 + ?>
907 + </label>
908 + <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">
909 + <div class="time-selector">
910 + <div class="ui input left icon">
911 + <i class="clock icon"></i>
912 + <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 ); ?>" />
913 + </div>
914 + </div>
915 + </div>
916 + </div>
917 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="2">
918 + <label class="six wide column middle aligned">
919 + <?php
920 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_frequencyDailyUpdate', $frequencyDailyUpdate );
921 + esc_html_e( 'Frequency of auto sync', 'mainwp' );
922 + ?>
923 + </label>
924 + <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" >
925 + <select name="mainwp_frequencyDailyUpdate" id="mainwp_frequencyDailyUpdate" class="ui dropdown settings-field-value-change-handler">
926 + <option value="1" <?php echo 1 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Once per day', 'mainwp' ); ?></option>
927 + <option value="2" <?php echo 2 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Twice per day', 'mainwp' ); ?></option>
928 + <option value="3" <?php echo 3 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Three times per day', 'mainwp' ); ?></option>
929 + <option value="4" <?php echo 4 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Four times per day', 'mainwp' ); ?></option>
930 + <option value="5" <?php echo 5 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Five times per day', 'mainwp' ); ?></option>
931 + <option value="6" <?php echo 6 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Six times per day', 'mainwp' ); ?></option>
932 + <option value="7" <?php echo 7 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Seven times per day', 'mainwp' ); ?></option>
933 + <option value="8" <?php echo 8 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Eight times per day', 'mainwp' ); ?></option>
934 + <option value="9" <?php echo 9 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Nine times per day', 'mainwp' ); ?></option>
935 + <option value="10" <?php echo 10 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Ten times per day', 'mainwp' ); ?></option>
936 + <option value="11" <?php echo 11 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Eleven times per day', 'mainwp' ); ?></option>
937 + <option value="12" <?php echo 12 === $frequencyDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Twelve times per day', 'mainwp' ); ?></option>
938 + </select>
939 + </div>
940 + </div>
941 + <script type="text/javascript">
942 + jQuery( document ).ready( function() {
943 + jQuery( '.time-selector' ).calendar( {
944 + type: 'time',
945 + ampm: false,
946 + formatter: {
947 + time: 'H:mm',
948 + cellTime: 'H:mm'
949 + }
950 + } );
951 + } );
952 + </script>
1259 953
1260 - /**
1261 - * Action: mainwp_advanced_settings_form_bottom
1262 - *
1263 - * Fires at the bottom of advanced settings form.
1264 - *
1265 - * @since 4.1
1266 - */
1267 - do_action( 'mainwp_advanced_settings_form_bottom' );
954 + <?php
1268 955
1269 - ?>
1270 - <div class="ui divider"></div>
1271 - <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1272 - </form>
1273 - </div>
1274 - </div>
1275 - <?php
1276 - self::render_footer( 'Advanced' );
1277 - }
956 + static::render_timezone_settings();
957 + static::render_datetime_settings();
1278 958
1279 - /**
1280 - * Render MainWP Tools SubPage.
1281 - *
1282 - * @uses \MainWP\Dashboard\MainWP_UI::render_screen_options()
1283 - */
1284 - public static function render_mainwp_tools() {
1285 - if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_dashboard_settings' ) ) {
1286 - mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
959 + $sidebarPosition = get_user_option( 'mainwp_sidebarPosition' );
960 + if ( false === $sidebarPosition ) {
961 + $sidebarPosition = 1;
962 + }
1287 963
1288 - return;
1289 - }
1290 - self::render_header( 'MainWPTools' );
1291 - $is_demo = MainWP_Demo_Handle::is_demo_mode();
1292 - ?>
1293 - <div id="mainwp-tools-settings" class="ui segment">
1294 - <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
1295 - <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-message' ) ) : ?>
1296 - <div class="ui info message">
1297 - <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-message"></i>
1298 - <?php printf( esc_html__( 'Use MainWP tools to adjust your MainWP Dashboard to your needs and perform specific actions when needed. For additional help, review this %1$shelp document%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?>
1299 - </div>
1300 - <?php endif; ?>
1301 - <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-custom-theme' ) ) : ?>
1302 - <div class="ui info message">
1303 - <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-custom-theme"></i>
1304 - <div><?php esc_html_e( 'Here you can select a theme for your MainWP Dashboard.', 'mainwp' ); ?></div>
1305 - <div><?php esc_html_e( 'To create a custom theme, copy the `mainwp-dark-theme.css` file from the MainWP Custom Dashboard Extension located in the `css` directory, make your edits and upload the file to the `../wp-content/uploads/mainwp/custom-dashboard/` directory.', 'mainwp' ); ?></div>
1306 - </div>
1307 - <?php endif; ?>
1308 - <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) : ?>
1309 - <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
1310 - <?php endif; ?>
1311 - <?php if ( isset( $_POST['mainwp_restore_info_messages'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) : ?>
1312 - <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Info messages have been restored successfully!', 'mainwp' ); ?></div>
1313 - <?php endif; ?>
1314 - <div class="ui form">
1315 - <form method="POST" action="">
1316 - <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1317 - <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'MainWPTools' ) ); ?>" />
1318 - <h3 class="ui dividing header"><?php esc_html_e( 'MainWP Dashboard Tools', 'mainwp' ); ?></h3>
1319 - <?php
1320 - /**
1321 - * Action: mainwp_tools_form_top
1322 - *
1323 - * Fires at the top of MainWP tools form.
1324 - *
1325 - * @since 4.1
1326 - */
1327 - do_action( 'mainwp_tools_form_top' );
964 + ?>
965 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="1">
966 + <label class="six wide column middle aligned">
967 + <?php
968 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_sidebarPosition', (int) $sidebarPosition );
969 + esc_html_e( 'Sidebar position', 'mainwp' );
970 + ?>
971 + </label>
972 + <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">
973 + <select name="mainwp_sidebarPosition" id="mainwp_sidebarPosition" class="ui dropdown settings-field-value-change-handler">
974 + <option value="1" <?php echo 1 === (int) $sidebarPosition ? 'selected' : ''; ?>><?php esc_html_e( 'Right (default)', 'mainwp' ); ?></option>
975 + <option value="0" <?php echo 0 === (int) $sidebarPosition ? 'selected' : ''; ?>><?php esc_html_e( 'Left', 'mainwp' ); ?></option>
976 + </select>
977 + </div>
978 + </div>
979 + <?php MainWP_UI::render_screen_options(); ?>
1328 980
1329 - $show_qsw = apply_filters( 'mainwp_show_qsw', true );
981 + <h3 class="ui dividing header">
982 + <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-updates' ); ?>
983 + <?php esc_html_e( 'Updates Settings', 'mainwp' ); ?></h3>
984 + <?php
985 + $snAutomaticDailyUpdate = (int) get_option( 'mainwp_automaticDailyUpdate', 0 );
986 + $snPluginAutomaticDailyUpdate = (int) get_option( 'mainwp_pluginAutomaticDailyUpdate', 0 );
987 + $snThemeAutomaticDailyUpdate = (int) get_option( 'mainwp_themeAutomaticDailyUpdate', 0 );
988 + $snTransAutomaticUpdate = (int) get_option( 'mainwp_transAutomaticDailyUpdate', 0 );
1330 989
1331 - self::get_instance()->render_select_custom_themes();
990 + $backup_before_upgrade = get_option( 'mainwp_backup_before_upgrade' );
991 + $mainwp_backup_before_upgrade_days = get_option( 'mainwp_backup_before_upgrade_days' );
992 + if ( empty( $mainwp_backup_before_upgrade_days ) || ! ctype_digit( $mainwp_backup_before_upgrade_days ) ) {
993 + $mainwp_backup_before_upgrade_days = 7;
994 + }
995 + $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
996 + $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
997 + $primaryBackup = get_option( 'mainwp_primaryBackup' );
998 + $disableUpdateConfirmations = (int) get_option( 'mainwp_disable_update_confirmations', 0 );
999 + ?>
1000 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
1001 + <label class="six wide column middle aligned">
1002 + <?php
1003 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_pluginAutomaticDailyUpdate', $snPluginAutomaticDailyUpdate );
1004 + esc_html_e( 'Plugin advanced automatic updates', 'mainwp' );
1005 + ?>
1006 + </label>
1007 + <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">
1008 + <select name="mainwp_pluginAutomaticDailyUpdate" id="mainwp_pluginAutomaticDailyUpdate" class="ui dropdown settings-field-value-change-handler">
1009 + <option value="1" <?php echo 1 === $snPluginAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
1010 + <option value="0" <?php echo 0 === $snPluginAutomaticDailyUpdate || 2 === $snPluginAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
1011 + </select>
1012 + </div>
1013 + </div>
1014 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
1015 + <label class="six wide column middle aligned">
1016 + <?php
1017 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_themeAutomaticDailyUpdate', $snThemeAutomaticDailyUpdate );
1018 + esc_html_e( 'Theme advanced automatic updates', 'mainwp' );
1019 + ?>
1020 + </label>
1021 + <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">
1022 + <select name="mainwp_themeAutomaticDailyUpdate" id="mainwp_themeAutomaticDailyUpdate" class="ui dropdown settings-field-value-change-handler">
1023 + <option value="1" <?php echo 1 === $snThemeAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
1024 + <option value="0" <?php echo 0 === $snThemeAutomaticDailyUpdate || 2 === $snThemeAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
1025 + </select>
1026 + </div>
1027 + </div>
1028 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
1029 + <label class="six wide column middle aligned">
1030 + <?php
1031 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_stransAutomaticUpdate', $snTransAutomaticUpdate );
1032 + esc_html_e( 'Translation advanced automatic updates', 'mainwp' );
1033 + ?>
1034 + </label>
1035 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Enable or disable automatic Translation updates.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1036 + <select name="mainwp_transAutomaticDailyUpdate" id="mainwp_transAutomaticDailyUpdate" class="ui dropdown settings-field-value-change-handler">
1037 + <option value="1" <?php echo 1 === $snTransAutomaticUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
1038 + <option value="0" <?php echo 0 === $snTransAutomaticUpdate || 2 === (int) $snTransAutomaticUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
1039 + </select>
1040 + </div>
1041 + </div>
1042 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
1043 + <label class="six wide column middle aligned">
1044 + <?php
1045 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_automaticDailyUpdate', $snAutomaticDailyUpdate );
1046 + esc_html_e( 'WP Core advanced automatic updates', 'mainwp' );
1047 + ?>
1048 + </label>
1049 + <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">
1050 + <select name="mainwp_automaticDailyUpdate" id="mainwp_automaticDailyUpdate" class="ui dropdown settings-field-value-change-handler">
1051 + <option value="1" <?php echo 1 === $snAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Install Trusted Updates', 'mainwp' ); ?></option>
1052 + <option value="0" <?php echo 0 === $snAutomaticDailyUpdate || 2 === (int) $snAutomaticDailyUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Disabled', 'mainwp' ); ?></option>
1053 + </select>
1054 + </div>
1055 + </div>
1056 + <?php static::render_auto_updates_settings(); ?>
1057 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates" default-indi-value="1">
1058 + <label class="six wide column middle aligned">
1059 + <?php
1060 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_delay_autoupdate', $delay_autoupdate );
1061 + esc_html_e( 'Advanced automatic updates delay', 'mainwp' );
1062 + ?>
1063 + </label>
1064 + <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">
1065 + <select name="mainwp_delay_autoupdate" id="mainwp_delay_autoupdate" class="ui dropdown settings-field-value-change-handler">
1066 + <option value="0" <?php echo 0 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( 'Delay off', 'mainwp' ); ?></option>
1067 + <option value="1" <?php echo 1 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '1 day', 'mainwp' ); ?></option>
1068 + <option value="2" <?php echo 2 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '2 days', 'mainwp' ); ?></option>
1069 + <option value="3" <?php echo 3 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '3 days', 'mainwp' ); ?></option>
1070 + <option value="4" <?php echo 4 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '4 days', 'mainwp' ); ?></option>
1071 + <option value="5" <?php echo 5 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '5 days', 'mainwp' ); ?></option>
1072 + <option value="6" <?php echo 6 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '6 days', 'mainwp' ); ?></option>
1073 + <option value="7" <?php echo 7 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '7 days', 'mainwp' ); ?></option>
1074 + <option value="14" <?php echo 14 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '14 days', 'mainwp' ); ?></option>
1075 + <option value="30" <?php echo 30 === $delay_autoupdate ? 'selected' : ''; ?>><?php esc_html_e( '30 days', 'mainwp' ); ?></option>
1076 + </select>
1077 + </div>
1078 + </div>
1079 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates" default-indi-value="1">
1080 + <label class="six wide column middle aligned">
1081 + <?php
1082 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_show_language_updates', $mainwp_show_language_updates );
1083 + esc_html_e( 'Show WordPress language updates', 'mainwp' );
1084 + ?>
1085 + </label>
1086 + <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">
1087 + <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"' : ''; ?>/>
1088 + </div>
1089 + </div>
1090 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates">
1091 + <label class="six wide column middle aligned">
1092 + <?php
1093 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_disable_update_confirmations', $disableUpdateConfirmations );
1094 + esc_html_e( 'Update confirmations', 'mainwp' );
1095 + ?>
1096 + </label>
1097 + <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">
1098 + <select name="mainwp_disable_update_confirmations" id="mainwp_disable_update_confirmations" class="ui dropdown settings-field-value-change-handler">
1099 + <option value="0" <?php echo 0 === $disableUpdateConfirmations ? 'selected' : ''; ?>><?php esc_html_e( 'Enable', 'mainwp' ); ?></option>
1100 + <option value="2" <?php echo 2 === $disableUpdateConfirmations ? 'selected' : ''; ?>><?php esc_html_e( 'Disable', 'mainwp' ); ?></option>
1101 + <option value="1" <?php echo 1 === $disableUpdateConfirmations ? 'selected' : ''; ?>><?php esc_html_e( 'Disable for single updates', 'mainwp' ); ?></option>
1102 + </select>
1103 + </div>
1104 + </div>
1105 + <?php if ( ( $enableLegacyBackupFeature && empty( $primaryBackup ) ) || ( empty( $enableLegacyBackupFeature ) && ! empty( $primaryBackup ) ) ) { ?>
1106 + <div class="ui grid field mainwp-parent-toggle settings-field-indicator-wrapper settings-field-indicator-updates">
1107 + <label class="six wide column middle aligned">
1108 + <?php
1109 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_backup_before_upgrade', (int) $backup_before_upgrade );
1110 + esc_html_e( 'Require a backup before an update', 'mainwp' );
1111 + ?>
1112 + </label>
1113 + <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">
1114 + <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"' : ''; ?>/>
1115 + </div>
1116 + </div>
1117 + <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"'; ?> >
1118 + <label class="six wide column middle aligned">
1119 + <?php
1120 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_backup_before_upgrade_days', (int) $mainwp_backup_before_upgrade_days );
1121 + esc_html_e( 'Days without of a full backup tolerance', 'mainwp' );
1122 + ?>
1123 + </label>
1124 + <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">
1125 + <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 ); ?>" />
1126 + </div>
1127 + </div>
1128 + <?php } ?>
1332 1129
1333 - ?>
1334 - <div class="ui grid field">
1335 - <label class="six wide column middle aligned"><?php esc_html_e( 'Enable MainWP guided tours', 'mainwp' ); ?> <span class="ui blue mini label"><?php esc_html_e( 'BETA', 'mainwp' ); ?></span></label>
1336 - <div class="ten wide column " data-tooltip="<?php esc_attr_e( 'Check this option to enable, or uncheck to disable MainWP guided tours.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1337 - <div class="ui info message" style="display:block!important;">
1338 - <?php printf( esc_html__( 'This feature is implemented using Javascript provided by Usetiful and is subject to the %1$sUsetiful Privacy Policy%2$s.', 'mainwp' ), '<a href="https://www.usetiful.com/privacy-policy" target="_blank">', '</a>' ); ?>
1339 - </div>
1340 - <div class="ui toggle checkbox">
1341 - <input type="checkbox" name="mainwp-guided-tours-option" id="mainwp-guided-tours-option" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_guided_tours', 0 ) ) ? 'checked="true"' : '' ); ?> />
1342 - </div>
1343 - </div>
1344 - </div>
1345 - <div class="ui grid field">
1346 - <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashboard to establish a new connection', 'mainwp' ); ?></label>
1347 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Force your MainWP Dashboard to reconnect with your child sites. Only needed if suggested by MainWP Support.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1348 - <?php
1349 - if ( $is_demo ) {
1350 - MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<input type="button" disabled="disabled" class="ui green basic button disabled" value="' . esc_attr__( 'Re-establish Connections', 'mainwp' ) . '" />' );
1351 - } else {
1352 - ?>
1353 - <input type="button" name="" id="force-destroy-sessions-button" data-inverted="" data-position="top right" data-tooltip="<?php esc_attr_e( 'Forces your dashboard to reconnect with your child sites. This feature will log out any currently logged in users on the Child sites and require them to re-log in. Only needed if suggested by MainWP Support.', 'mainwp' ); ?>" class="ui green basic button" value="<?php esc_attr_e( 'Re-establish Connections', 'mainwp' ); ?>" />
1354 - <?php } ?>
1355 - </div>
1356 - </div>
1357 - <div class="ui grid field">
1358 - <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashbaord to set new pair of OpenSSL Keys', 'mainwp' ); ?></label>
1359 - <div class="ten wide column" id="mainwp-renew-connections-tool" data-content="<?php esc_attr_e( 'This will function renew connection and reconnect site right away.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
1360 - <?php
1361 - if ( $is_demo ) {
1362 - MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="javascript:void(0)" disabled="disabled" class="ui button green basic disabled">' . esc_html__( 'Reset OpenSSL Key Pair', 'mainwp' ) . '</a>' );
1363 - } else {
1364 - ?>
1365 - <a href="javascript:void(0)" onclick="mainwp_tool_renew_connections_show(); return false;" class="ui button green basic"><?php esc_html_e( 'Reset OpenSSL Key Pair', 'mainwp' ); ?></a>
1366 - <?php } ?>
1367 - </div>
1368 - </div>
1369 - <?php if ( $show_qsw ) { ?>
1370 - <div class="ui grid field">
1371 - <label class="six wide column middle aligned"><?php esc_html_e( 'Start the MainWP Quick Setup Wizard', 'mainwp' ); ?></label>
1372 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to start the Quick Setup Wizard', 'mainwp' ); ?>" data-inverted="" data-position="top left"><a href="admin.php?page=mainwp-setup" class="ui green button basic" ><?php esc_html_e( 'Start Quick Setup Wizard', 'mainwp' ); ?></a></div>
1373 - </div>
1374 - <?php } ?>
1375 - <div class="ui grid field">
1376 - <label class="six wide column middle aligned"><?php esc_html_e( 'Export child sites to CSV file', 'mainwp' ); ?></label>
1377 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to export all connected sites to a CSV file.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><a href="admin.php?page=MainWPTools&doExportSites=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'export_sites' ) ); ?>" class="ui button green basic"><?php esc_html_e( 'Export Child Sites', 'mainwp' ); ?></a></div>
1378 - </div>
1379 - <div class="ui grid field">
1380 - <label class="six wide column middle aligned"><?php esc_html_e( 'Import child sites', 'mainwp' ); ?></label>
1381 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to import websites to your MainWP Dashboard.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><a href="admin.php?page=managesites&do=bulknew" class="ui button green basic"><?php esc_html_e( 'Import Child Sites', 'mainwp' ); ?></a></div>
1382 - </div>
1383 - <div class="ui grid field">
1384 - <label class="six wide column middle aligned"><?php esc_html_e( 'Disconnect all child sites', 'mainwp' ); ?></label>
1385 - <div class="ten wide column" id="mainwp-disconnect-sites-tool" data-content="<?php esc_attr_e( 'This will function will break the connection and leave the MainWP Child plugin active and which makes your sites vulnerable. Use only if you attend to reconnect site to the same or a different dashboard right away.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
1386 - <?php
1387 - if ( $is_demo ) {
1388 - MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="#" class="ui button green basic disabled" disabled="disabled">' . esc_html__( 'Disconnect Sites', 'mainwp' ) . '</a>' );
1389 - } else {
1390 - ?>
1391 - <a href="admin.php?page=MainWPTools&disconnectSites=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'disconnect_sites' ) ); ?>" onclick="mainwp_tool_disconnect_sites(); return false;" class="ui button green basic"><?php esc_html_e( 'Disconnect Sites', 'mainwp' ); ?></a>
1392 - <?php } ?>
1393 - </div>
1394 - </div>
1395 - <div class="ui grid field">
1396 - <label class="six wide column middle aligned"><?php esc_html_e( 'Delete extensions API Activation data', 'mainwp' ); ?></label>
1397 - <div class="ten wide column" id="mainwp-clear-activation-data" data-content="<?php esc_attr_e( 'Delete extensions API activation data. This will not affect extensions settings, it just removes API activation data.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
1398 - <a href="admin.php?page=MainWPTools&clearActivationData=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'clear_activation_data' ) ); ?>" onclick="mainwp_tool_clear_activation_data(this); return false;" class="ui button green basic"><?php esc_html_e( 'Delete Extensions API Activation Data', 'mainwp' ); ?></a>
1399 - </div>
1400 - </div>
1401 - <div class="ui grid field">
1402 - <label class="six wide column middle aligned"><?php esc_html_e( 'Restore all info messages', 'mainwp' ); ?></label>
1403 - <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Click this button to restore all info messages in your MainWP Dashboard and Extensions.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1404 - <input type="submit" name="mainwp_restore_info_messages" id="mainwp_restore_info_messages" class="ui button" value="<?php esc_attr_e( 'Restore Info Messages', 'mainwp' ); ?>"/>
1405 - </div>
1406 - </div>
1407 - <?php
1408 - $enabled_demo = MainWP_Demo_Handle::is_demo_mode();
1409 - $is_new = MainWP_Demo_Handle::get_instance()->is_new_instance();
1410 - if ( ! MainWP_Demo_Handle::is_instawp_site() ) {
1411 - ?>
1412 - <div class="ui grid field">
1413 - <label class="six wide column middle aligned"><?php echo esc_html__( 'Demo mode', 'mainwp' ); ?></label>
1414 - <div class="ten wide column">
1415 - <?php if ( ! $enabled_demo ) { ?>
1416 - <span data-tooltip="<?php esc_attr_e( 'Demo Mode can not be enabled on MainWP Dashboards that already have sites connected, clients created or extensions installed.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><button page-import="settings" class="ui green button mainwp-import-demo-data-button" <?php echo ( ! $is_new ? 'disabled="disabled"' : '' ); ?>><?php esc_html_e( 'Import Demo Content', 'mainwp' ); ?></button></span>
1417 - <?php } else { ?>
1418 - <span data-tooltip="<?php esc_attr_e( 'Click this button to delete the Demo content from your MainWP Dashboard and disable the Demo mode.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><button class="ui green button mainwp-remove-demo-data-button"><?php esc_html_e( 'Delete Demo Content', 'mainwp' ); ?></button></span>
1419 - <?php } ?>
1420 - </div>
1421 - </div>
1422 - <?php
1423 - }
1424 - /**
1425 - * Action: mainwp_tools_form_bottom
1426 - *
1427 - * Fires at the bottom of mainwp tools form.
1428 - *
1429 - * @since 4.1
1430 - */
1431 - do_action( 'mainwp_tools_form_bottom' );
1432 - ?>
1433 - <div class="ui divider"></div>
1434 - <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1435 - </form>
1436 - </div>
1437 - </div>
1438 - <script type="text/javascript">
1439 - jQuery( '#mainwp-disconnect-sites-tool' ).popup();
1440 - jQuery( '#mainwp-clear-activation-data' ).popup();
1441 - </script>
1442 - <?php
1443 - self::render_footer( 'MainWPTools' );
1444 - MainWP_Connect_Helper::render_renew_connections_modal();
1445 - }
1130 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-updates" default-indi-value="365">
1131 + <label class="six wide column middle aligned">
1132 + <?php
1133 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_numberdays_Outdate_Plugin_Theme', (int) get_option( 'mainwp_numberdays_Outdate_Plugin_Theme', 365 ) );
1446 1134
1447 - /**
1448 - * Render MainWP themes selection.
1449 - */
1450 - public function render_select_custom_themes() {
1451 - $custom_theme = $this->get_current_user_theme();
1452 - if ( false === $custom_theme ) {
1453 - // to compatible with Custom Dashboard extension settings.
1454 - $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
1455 - if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
1456 - $compat_theme = $compat_settings['theme'];
1457 - }
1458 - if ( null !== $compat_theme ) {
1459 - $custom_theme = $compat_theme;
1460 - }
1461 - }
1462 - $themes_files = self::get_instance()->get_custom_themes_files();
1463 - if ( empty( $themes_files ) ) {
1464 - $themes_files = array();
1465 - }
1466 - ?>
1467 - <div class="ui grid field">
1468 - <label class="six wide column middle aligned"><?php esc_html_e( 'Select MainWP Theme', 'mainwp' ); ?></label>
1469 - <div class="ten wide column" tabindex="0" data-tooltip="<?php esc_attr_e( 'Select your MainWP Dashboard theme.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1470 - <select name="mainwp_settings_custom_theme" id="mainwp_settings_custom_theme" class="ui dropdown selection">
1471 - <option value="default" <?php echo ( 'default' === $custom_theme || empty( $custom_theme ) ) ? 'selected' : ''; ?>><?php esc_html_e( 'Default', 'mainwp' ); ?></option>
1472 - <option value="classic" <?php echo ( 'classic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Classic', 'mainwp' ); ?></option>
1473 - <option value="dark" <?php echo ( 'dark' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Dark', 'mainwp' ); ?></option>
1474 - <option value="wpadmin" <?php echo ( 'wpadmin' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'WP Admin', 'mainwp' ); ?></option>
1475 - <option value="minimalistic" <?php echo ( 'minimalistic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Minimalistic', 'mainwp' ); ?></option>
1476 - <?php
1477 - foreach ( $themes_files as $file_name => $theme ) {
1478 - $theme = ucfirst( $theme );
1479 - $_select = '';
1480 - if ( $custom_theme === $file_name ) {
1481 - $_select = 'selected';
1482 - }
1483 - echo '<option value="' . esc_attr( $file_name ) . '" ' . esc_attr( $_select ) . '>' . esc_html( $theme ) . '</option>';
1484 - }
1485 - ?>
1486 - </select>
1487 - </div>
1488 - </div>
1489 - <?php
1490 - }
1135 + esc_html_e( 'Abandoned plugins/themes tolerance', 'mainwp' );
1136 + ?>
1137 + </label>
1138 + <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">
1139 + <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' ) ); ?>"/>
1140 + </div>
1141 + </div>
1491 1142
1492 - /**
1493 - * Get custom themes files.
1494 - */
1495 - public function get_custom_themes_files() {
1496 - // get themes files.
1497 - $dirs = $this->get_custom_theme_folder();
1498 - $scan_dir = $dirs[0];
1499 - $handle = opendir( $scan_dir );
1500 - $themes = array();
1501 - $scan_files = array();
1502 - if ( $handle ) {
1503 - $filename = readdir( $handle );
1504 - while ( false !== $filename ) {
1505 - $correct_file = true;
1506 - if ( '.' === substr( $filename, 0, 1 ) || 'index.php' === $filename ) {
1507 - $correct_file = false;
1508 - } elseif ( '.css' !== substr( $filename, - 4 ) ) {
1509 - $correct_file = false;
1510 - }
1511 - if ( $correct_file ) {
1512 - $theme = basename( $filename, '.css' );
1513 - $theme = str_replace( '-theme', '', $theme );
1514 - $themes[ $filename ] = trim( $theme );
1515 - }
1516 - $filename = readdir( $handle ); // to while loop.
1517 - }
1518 - closedir( $handle );
1519 - }
1520 - return $themes;
1521 - }
1143 + <?php MainWP_Manage_Backups::render_settings(); ?>
1144 + <?php
1145 + /**
1146 + * Action: mainwp_settings_form_bottom
1147 + *
1148 + * Fires at the bottom of settings form.
1149 + *
1150 + * @since 4.1
1151 + */
1152 + do_action( 'mainwp_settings_form_bottom' );
1153 + ?>
1154 + <div class="ui divider"></div>
1155 + <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1156 + <div style="clear:both"></div>
1157 + </form>
1158 + </div>
1159 + </div>
1160 + <?php
1161 + static::render_footer( '' );
1162 + }
1522 1163
1523 - /**
1524 - * Get selected MainWP theme name.
1525 - */
1526 - public function get_selected_theme() {
1527 - $selected_theme = false;
1164 + /**
1165 + * Method render_auto_updates_settings().
1166 + */
1167 + public static function render_auto_updates_settings() { // phpcs:ignore -- NOSONAR - complex.
1528 1168
1529 - $custom_theme = $this->get_current_user_theme();
1169 + $time_AutoUpdate = get_option( 'mainwp_time_AutoUpdate' );
1170 + $dayinweek_AutoUpdate = (int) get_option( 'mainwp_dayinweek_AutoUpdate', 0 );
1171 + $dayinmonth_AutoUpdate = (int) get_option( 'mainwp_dayinmonth_AutoUpdate', 1 );
1172 + $frequency_AutoUpdate = get_option( 'mainwp_frequency_AutoUpdate', 'daily' );
1530 1173
1531 - if ( false === $custom_theme ) {
1532 - // to compatible with Custom Dashboard extension settings.
1533 - $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
1534 - if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
1535 - $compat_theme = $compat_settings['theme'];
1536 - }
1174 + if ( empty( $time_AutoUpdate ) ) {
1175 + $time_AutoUpdate = '00:00';
1176 + }
1537 1177
1538 - if ( null !== $compat_theme ) {
1539 - $custom_theme = $compat_theme;
1540 - }
1541 - }
1178 + if ( ! in_array( $frequency_AutoUpdate, array( 'daily', 'weekly', 'monthly' ) ) ) {
1179 + $frequency_AutoUpdate = 'daily';
1180 + }
1542 1181
1543 - if ( ! empty( $custom_theme ) ) {
1544 - if ( 'default' === $custom_theme || 'dark' === $custom_theme || 'wpadmin' === $custom_theme || 'minimalistic' === $custom_theme ) {
1545 - return $custom_theme;
1546 - }
1547 - $dirs = $this->get_custom_theme_folder();
1548 - $theme_dir = $dirs[0];
1549 - $file = $theme_dir . $custom_theme;
1550 - if ( file_exists( $file ) && '.css' === substr( $file, - 4 ) ) {
1551 - $selected_theme = $custom_theme;
1552 - }
1553 - }
1554 - return $selected_theme;
1555 - }
1182 + ?>
1183 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="daily">
1184 + <label class="six wide column middle aligned">
1185 + <?php
1186 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_frequency_AutoUpdate', $frequency_AutoUpdate );
1187 + esc_html_e( 'Frequency of automatic updates', 'mainwp' );
1188 + ?>
1189 + </label>
1190 + <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" >
1191 + <select name="mainwp_frequency_AutoUpdate" id="mainwp_frequency_AutoUpdate" class="ui dropdown settings-field-value-change-handler">
1192 + <option value="daily" <?php echo 'daily' === $frequency_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Daily', 'mainwp' ); ?></option>
1193 + <option value="weekly" <?php echo 'weekly' === $frequency_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Weekly', 'mainwp' ); ?></option>
1194 + <option value="monthly" <?php echo 'monthly' === $frequency_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Monthly', 'mainwp' ); ?></option>
1195 + </select>
1196 + </div>
1197 + </div>
1556 1198
1199 + <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;"'; ?>>
1200 + <label class="six wide column middle aligned">
1201 + <?php
1202 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_dayinmonth_AutoUpdate', $dayinmonth_AutoUpdate );
1203 + esc_html_e( 'Select day', 'mainwp' );
1204 + ?>
1205 + </label>
1206 + <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" >
1207 + <select name="mainwp_dayinmonth_AutoUpdate" id="mainwp_dayinmonth_AutoUpdate" class="ui dropdown settings-field-value-change-handler">
1208 + <?php
1209 + $day_suffix = array(
1210 + 1 => 'st',
1211 + 2 => 'nd',
1212 + 3 => 'rd',
1213 + );
1214 + for ( $x = 1; $x <= 31; $x++ ) {
1215 + $_select = '';
1216 + if ( $dayinmonth_AutoUpdate === $x ) {
1217 + $_select = 'selected';
1218 + }
1219 + $remain = $x % 10;
1220 + $day_sf = isset( $day_suffix[ $remain ] ) ? $day_suffix[ $remain ] : 'th';
1221 + echo '<option value="' . intval( $x ) . '" ' . esc_html( $_select ) . '>' . esc_html( $x . $day_sf ) . ' of the month</option>';
1222 + }
1223 + ?>
1224 + </select>
1225 + </div>
1226 + </div>
1557 1227
1558 - /**
1559 - * Get custom MainWP theme folder.
1560 - */
1561 - public function get_custom_theme_folder() {
1562 - $dirs = MainWP_System_Utility::get_mainwp_dir();
1563 - global $wp_filesystem;
1564 - if ( is_array( $dirs ) && ! $wp_filesystem->exists( $dirs[0] . 'themes' ) && $wp_filesystem->exists( $dirs[0] . 'custom-dashboard' ) ) {
1565 - // re-name the custom-dashboard folder to compatible.
1566 - $wp_filesystem->move( $dirs[0] . 'custom-dashboard', $dirs[0] . 'themes' );
1567 - }
1568 - $dirs = MainWP_System_Utility::get_mainwp_dir_allow_access( 'themes' );
1569 - return $dirs;
1570 - }
1228 + <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;"'; ?>>
1229 + <label class="six wide column middle aligned">
1230 + <?php
1231 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_dayinweek_AutoUpdate', $dayinweek_AutoUpdate );
1232 + esc_html_e( 'Select day', 'mainwp' );
1233 + ?>
1234 + </label>
1235 + <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">
1236 + <select name="mainwp_dayinweek_AutoUpdate" id="mainwp_dayinweek_AutoUpdate" class="ui dropdown settings-field-value-change-handler">
1237 + <option value="0" <?php echo 0 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Mon', 'mainwp' ); ?></option>
1238 + <option value="1" <?php echo 1 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Tue', 'mainwp' ); ?></option>
1239 + <option value="2" <?php echo 2 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Wed', 'mainwp' ); ?></option>
1240 + <option value="3" <?php echo 3 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Thus', 'mainwp' ); ?></option>
1241 + <option value="4" <?php echo 4 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Fri', 'mainwp' ); ?></option>
1242 + <option value="5" <?php echo 5 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Sat', 'mainwp' ); ?></option>
1243 + <option value="6" <?php echo 6 === $dayinweek_AutoUpdate ? 'selected' : ''; ?>><?php esc_html_e( 'Sun', 'mainwp' ); ?></option>
1244 + </select>
1245 + </div>
1246 + </div>
1247 + <div id="mainwp-time-autoupdate-wrapper" class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="00:00">
1248 + <label class="six wide column middle aligned">
1249 + <?php
1250 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_time_AutoUpdate', $time_AutoUpdate );
1251 + esc_html_e( 'Select time', 'mainwp' );
1252 + $_last_start_auto_updates = get_option( 'mainwp_automatic_updates_start_lasttime', 0 );
1253 + $_next_auto_updates = get_option( 'mainwp_automatic_update_next_run_timestamp', 0 );
1254 + ?>
1255 + </label>
1256 + <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">
1257 + <div class="time-selector">
1258 + <div class="ui input left icon">
1259 + <i class="clock icon"></i>
1260 + <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 ); ?>" />
1261 + </div>
1262 + </div>
1263 + </div>
1264 + </div>
1265 + <script type="text/javascript">
1266 + jQuery(document).on('change', '#mainwp_frequency_AutoUpdate', function () {
1267 + if( jQuery(this).val() == 'monthly' ){
1268 + jQuery('#mainwp-dayinweek-autoupdate-wrapper').hide();
1269 + jQuery('#mainwp-dayinmonth-autoupdate-wrapper').show();
1270 + } else if( jQuery(this).val() == 'weekly'){
1271 + jQuery('#mainwp-dayinweek-autoupdate-wrapper').show();
1272 + jQuery('#mainwp-dayinmonth-autoupdate-wrapper').hide();
1273 + } else {
1274 + jQuery('#mainwp-dayinweek-autoupdate-wrapper').hide();
1275 + jQuery('#mainwp-dayinmonth-autoupdate-wrapper').hide();
1276 + }
1277 + });
1278 + </script>
1279 + <?php
1280 + }
1571 1281
1282 + /**
1283 + * Render Timezone settings.
1284 + */
1285 + public static function render_timezone_settings() { // phpcs:ignore -- NOSONAR - complex.
1572 1286
1573 - /**
1574 - * Get current user's selected theme.
1575 - */
1576 - public function get_current_user_theme() {
1577 - $custom_theme = get_user_option( 'mainwp_selected_theme' );
1578 - if ( empty( $custom_theme ) ) {
1579 - $custom_theme = get_option( 'mainwp_selected_theme', 'default' );
1580 - }
1581 - return $custom_theme;
1582 - }
1287 + $current_offset = get_option( 'gmt_offset' );
1288 + $tzstring = get_option( 'timezone_string' );
1289 + $tzstring = MainWP_Utility::clean_wp_timezone_string( $tzstring );
1583 1290
1584 - /**
1585 - * Export Child Sites and save as .csv file.
1586 - *
1587 - * @uses \MainWP\Dashboard\MainWP_DB::query()
1588 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
1589 - * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
1590 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
1591 - * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
1592 - */
1593 - public static function export_sites() {
1594 - if ( isset( $_GET['doExportSites'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'export_sites' ) ) {
1291 + $check_zone_info = true;
1595 1292
1596 - $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( true );
1597 - $websites = MainWP_DB::instance()->query( $sql );
1293 + // Remove old Etc mappings. Fallback to gmt_offset.
1294 + if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
1295 + $tzstring = '';
1296 + }
1598 1297
1599 - if ( ! $websites ) {
1600 - die( 'Not found sites' );
1601 - }
1298 + if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists.
1299 + $check_zone_info = false;
1300 + if ( empty( $current_offset ) ) {
1301 + $tzstring = 'UTC+0';
1302 + } elseif ( $current_offset < 0 ) {
1303 + $tzstring = 'UTC' . $current_offset;
1304 + } else {
1305 + $tzstring = 'UTC+' . $current_offset;
1306 + }
1307 + }
1602 1308
1603 - $keys = array( 'name', 'url', 'adminname', 'wpgroups', 'uniqueId', 'http_user', 'http_pass', 'verify_certificate', 'ssl_version' );
1604 - $allowedHeaders = array( 'site name', 'url', 'admin name', 'group', 'security id', 'http username', 'http password', 'verify certificate', 'ssl version' );
1309 + $timezone_format = _x( 'Y-m-d H:i:s', 'timezone date format', 'mainwp' );
1605 1310
1606 - $csv = implode( ',', $allowedHeaders ) . "\r";
1607 - MainWP_DB::data_seek( $websites, 0 );
1608 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1609 - if ( empty( $website ) ) {
1610 - continue;
1611 - }
1612 - $row = MainWP_Utility::map_site( $website, $keys, false );
1613 - $csv .= '"' . implode( '","', $row ) . '"' . "\r";
1614 - }
1311 + ?>
1312 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general">
1313 + <label class="six wide column middle aligned"><?php esc_html_e( 'Timezone', 'mainwp' ); ?></label>
1314 + <?php
1315 + // translators: %s is the abbreviation "UTC".
1316 + $timezone_tooltip = esc_attr__( 'Choose either a city in the same timezone as you or a %s (Coordinated Universal Time) time offset.', 'mainwp' );
1317 + ?>
1318 + <div class="ten wide column" data-tooltip="<?php echo $timezone_tooltip; // phpcs:ignore WordPress.Security.EscapeOutput ?>" data-inverted="" data-position="top left">
1319 + <select id="timezone_string" class="ui dropdown" name="timezone_string" aria-describedby="timezone-description">
1320 + <?php echo wp_timezone_choice( $tzstring, get_user_locale() ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
1321 + </select>
1322 + <div class="ui hidden fitted divider"></div>
1323 + <div class="ui secondary segment">
1324 + <?php
1325 + // translators: %s is the current UTC date and time.
1326 + printf( esc_html__( 'Universal time is %s.', 'mainwp' ), '<code>' . esc_html( date_i18n( $timezone_format, false, true ) ) . '</code>' );
1327 + ?>
1328 + <div class="ui hidden fitted divider"></div>
1329 + <?php if ( get_option( 'timezone_string' ) || ! empty( $current_offset ) ) : ?>
1330 + <?php
1331 + // translators: %s is the current local date and time.
1332 + printf( esc_html__( 'Local time is %s.', 'mainwp' ), '<code>' . esc_html( date_i18n( $timezone_format ) ) . '</code>' );
1333 + ?>
1334 + <div class="ui hidden fitted divider"></div>
1335 + <?php endif; ?>
1336 + <?php if ( $check_zone_info && $tzstring ) : ?>
1337 + <?php
1338 + $now = new \DateTime( 'now', new \DateTimeZone( $tzstring ) );
1339 + $dst = (bool) $now->format( 'I' );
1615 1340
1616 - header( 'Content-Type: text/csv; charset=utf-8' );
1617 - header( 'Content-Disposition: attachment; filename=export-sites.csv' );
1618 - echo $csv; // phpcs:ignore WordPress.Security.EscapeOutput
1619 - exit();
1620 - }
1621 - }
1341 + if ( $dst ) {
1342 + esc_html_e( 'This timezone is currently in daylight saving time.', 'mainwp' );
1343 + } else {
1344 + esc_html_e( 'This timezone is currently in standard time.', 'mainwp' );
1345 + }
1346 + ?>
1347 + <div class="ui hidden fitted divider"></div>
1348 + <?php
1349 + if ( in_array( $tzstring, timezone_identifiers_list(), true ) ) {
1350 + $transitions = timezone_transitions_get( timezone_open( $tzstring ), time() );
1622 1351
1623 - /**
1624 - * Render MainWP Email Settings SubPage.
1625 - *
1626 - * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_notification_types()
1627 - * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_edit_settings()
1628 - * @uses \MainWP\Dashboard\MainWP_Notification_Settings::emails_general_settings_handle()
1629 - * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_all_settings()
1630 - * @uses \MainWP\Dashboard\MainWP_Notification_Template::handle_template_file_action()
1631 - */
1632 - public static function render_email_settings() {
1633 - $notification_emails = MainWP_Notification_Settings::get_notification_types();
1634 - self::render_header( 'Emails' );
1635 - $edit_email = isset( $_GET['edit-email'] ) ? sanitize_text_field( wp_unslash( $_GET['edit-email'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1636 - if ( ! empty( $edit_email ) && isset( $notification_emails[ $edit_email ] ) ) {
1637 - $updated_templ = MainWP_Notification_Template::instance()->handle_template_file_action();
1638 - MainWP_Notification_Settings::instance()->render_edit_settings( $edit_email, $updated_templ );
1639 - } else {
1640 - $updated = MainWP_Notification_Settings::emails_general_settings_handle();
1641 - MainWP_Notification_Settings::instance()->render_all_settings( $updated );
1642 - }
1643 - self::render_footer( 'Emails' );
1644 - }
1352 + if ( ! empty( $transitions[1] ) ) {
1353 + echo ' ';
1354 + // translators: %s is the date and time when the timezone transition occurs.
1355 + $message = $transitions[1]['isdst'] ? esc_html__( 'Daylight saving time begins on: %s.', 'mainwp' ) : esc_html__( 'Standard time begins on: %s.', 'mainwp' );
1356 + printf( $message, '<code>' . wp_date( esc_html__( 'F j, Y', 'mainwp' ) . ' ' . esc_html__( 'g:i a', 'mainwp' ), esc_html( $transitions[1]['ts'] ) ) . '</code>' ); // phpcs:ignore WordPress.Security.EscapeOutput
1357 + } else {
1358 + esc_html_e( 'This timezone does not observe daylight saving time.', 'mainwp' );
1359 + }
1360 + }
1361 + ?>
1362 + <?php endif; ?>
1363 + </div>
1364 + </div>
1365 + </div>
1366 + <?php
1367 + }
1645 1368
1646 - /**
1647 - * Hook the section help content to the Help Sidebar element
1648 - */
1649 - public static function mainwp_help_content() {
1650 - if ( isset( $_GET['page'] ) && ( 'Settings' === $_GET['page'] || 'SettingsAdvanced' === $_GET['page'] || 'MainWPTools' === $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1651 - ?>
1652 - <p><?php esc_html_e( 'If you need help with your MainWP Dashboard settings, please review following help documents', 'mainwp' ); ?></p>
1653 - <div class="ui relaxed bulleted list">
1654 - <div class="item"><a href="https://kb.mainwp.com/docs/mainwp-dashboard-settings/" target="_blank">MainWP Dashboard Settings</a> <i class="external alternate icon"></i></div>
1655 - </div>
1656 - <?php
1657 - }
1658 - }
1369 + /**
1370 + * Render Date/Time settings.
1371 + */
1372 + public static function render_datetime_settings() {
1373 + ?>
1374 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" default-indi-value="F j, Y">
1375 + <label class="six wide column middle aligned">
1376 + <?php
1377 + MainWP_Settings_Indicator::render_not_default_indicator( 'date_format', get_option( 'date_format' ) );
1378 + esc_html_e( 'Date format', 'mainwp' );
1379 + ?>
1380 + </label>
1381 + <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">
1382 + <?php
1383 + /**
1384 + * Filters the default date formats.
1385 + *
1386 + * @since 2.7.0
1387 + * @since 4.0.0 Added ISO date standard YYYY-MM-DD format.
1388 + *
1389 + * @param string[] $default_date_formats Array of default date formats.
1390 + */
1391 + $date_formats = array_unique( apply_filters( 'date_formats', array( esc_html__( 'F j, Y', 'mainwp' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) );
1392 +
1393 + $custom = true;
1394 +
1395 + foreach ( $date_formats as $format ) {
1396 + echo "\t<label><input type='radio' name='date_format' value='" . esc_attr( $format ) . "'";
1397 + if ( get_option( 'date_format' ) === $format ) { // checked() uses "==" rather than "===".
1398 + echo " checked='checked'";
1399 + $custom = false;
1400 + }
1401 + echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
1402 + }
1403 + echo '<label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
1404 + checked( $custom );
1405 + echo '/> <span class="date-time-text date-time-custom-text">' . esc_html__( 'Custom:', 'mainwp' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom date format in the following field', 'mainwp' ) . '</span></span></label>' .
1406 + '<label for="date_format_custom" class="screen-reader-text">' . esc_html__( 'Custom date format:', 'mainwp' ) . '</label>' .
1407 + '<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" />' .
1408 + '<br />' .
1409 + '<em><strong>' . esc_html__( 'Preview:', 'mainwp' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'date_format' ) ) ) . '</span>' .
1410 + "<span class='spinner'></span>\n" . '</em>';
1411 + ?>
1412 + </div>
1413 + </div>
1414 +
1415 + <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="g:i a">
1416 + <label class="six wide column middle aligned">
1417 + <?php
1418 + MainWP_Settings_Indicator::render_not_default_indicator( 'time_format', get_option( 'time_format' ) );
1419 + esc_html_e( 'Time format', 'mainwp' );
1420 + ?>
1421 + </label>
1422 + <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">
1423 + <?php
1424 + /**
1425 + * Filters the default time formats.
1426 + *
1427 + * @since 2.7.0
1428 + *
1429 + * @param string[] $default_time_formats Array of default time formats.
1430 + */
1431 + $time_formats = array_unique( apply_filters( 'time_formats', array( esc_html__( 'g:i a', 'mainwp' ), 'g:i A', 'H:i' ) ) );
1432 +
1433 + $custom = true;
1434 +
1435 + foreach ( $time_formats as $format ) {
1436 + echo "\t<label><input type='radio' name='time_format' value='" . esc_attr( $format ) . "'";
1437 + if ( get_option( 'time_format' ) === $format ) { // checked() uses "==" rather than "===".
1438 + echo " checked='checked'";
1439 + $custom = false;
1440 + }
1441 + echo ' /> <span class="date-time-text format-i18n">' . esc_html( date_i18n( $format ) ) . '</span><code>' . esc_html( $format ) . "</code></label><br />\n";
1442 + }
1443 + echo '<label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
1444 + checked( $custom );
1445 + echo '/> <span class="date-time-text date-time-custom-text">' . esc_html__( 'Custom:', 'mainwp' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom time format in the following field', 'mainwp' ) . '</span></span></label>' .
1446 + '<label for="time_format_custom" class="screen-reader-text">' . esc_html__( 'Custom time format:', 'mainwp' ) . '</label>' .
1447 + '<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' ) ) . '" />' .
1448 + '<br />' .
1449 + '<em><strong>' . esc_html__( 'Preview:', 'mainwp' ) . '</strong> <span class="example">' . esc_html( date_i18n( get_option( 'time_format' ) ) ) . '</span>' .
1450 + "<span class='spinner'></span>\n" . '</em>';
1451 + ?>
1452 + </div>
1453 + </div>
1454 + <script type="text/javascript">
1455 + jQuery(function($) {
1456 + $( 'input[name="date_format"]' ).on( 'click', function() {
1457 + if ( 'date_format_custom_radio' !== $( this ).attr( 'id' ) ){
1458 + $( 'input[name="date_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
1459 + $( 'input[name="date_format_custom"]' ).trigger("change"); // support indicator.
1460 + }
1461 + } );
1462 +
1463 + $( 'input[name="date_format_custom"]' ).on( 'click input', function() {
1464 + $( '#date_format_custom_radio' ).prop( 'checked', true );
1465 + } );
1466 +
1467 + $( 'input[name="time_format"]' ).on( 'click', function() {
1468 + if ( 'time_format_custom_radio' !== $(this).attr( 'id' ) ){
1469 + $( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( '.fieldset-wrapper' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() );
1470 + $( 'input[name="time_format_custom"]' ).trigger("change"); // support indicator.
1471 + }
1472 + } );
1473 +
1474 + $( 'input[name="time_format_custom"]' ).on( 'click input', function() {
1475 + $( '#time_format_custom_radio' ).prop( 'checked', true );
1476 + } );
1477 +
1478 + $( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() {
1479 + let format = $( this ),
1480 + fieldset = format.closest( '.fieldset-wrapper' ),
1481 + example = fieldset.find( '.example' ),
1482 + spinner = fieldset.find( '.spinner' );
1483 +
1484 + // Debounce the event callback while users are typing.
1485 + clearTimeout( $.data( this, 'timer' ) );
1486 + $( this ).data( 'timer', setTimeout( function() {
1487 + // If custom date is not empty.
1488 + if ( format.val() ) {
1489 + spinner.addClass( 'is-active' );
1490 +
1491 + $.post( ajaxurl, {
1492 + action: 'date_format_custom' === format.attr( 'name' ) ? 'date_format' : 'time_format',
1493 + date : format.val()
1494 + }, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } );
1495 + }
1496 + }, 500 ) );
1497 + } );
1498 + });
1499 + </script>
1500 + <?php
1501 + }
1502 +
1503 + /**
1504 + * Method get_websites_automatic_update_time()
1505 + *
1506 + * Get websites automatic update time.
1507 + *
1508 + * @return mixed array
1509 + *
1510 + * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
1511 + */
1512 + public static function get_websites_automatic_update_time() {
1513 + $lastAutomaticUpdate = MainWP_Auto_Updates_DB::instance()->get_websites_last_automatic_sync();
1514 + $lasttimeAutomatic = get_option( 'mainwp_updatescheck_last_timestamp' );
1515 + $lasttimeStartAutomatic = get_option( 'mainwp_updatescheck_start_last_timestamp' );
1516 + $local_timestamp = MainWP_Utility::get_timestamp();
1517 +
1518 + if ( empty( $lasttimeStartAutomatic ) && ! empty( $lasttimeAutomatic ) ) {
1519 + $lasttimeStartAutomatic = $lasttimeAutomatic;
1520 + }
1521 +
1522 + if ( empty( $lastAutomaticUpdate ) ) {
1523 + $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1524 + } elseif ( 0 < MainWP_Auto_Updates_DB::instance()->get_websites_check_updates_count( $lasttimeStartAutomatic ) ) {
1525 + $nextAutomaticUpdate = esc_html__( 'Processing your websites.', 'mainwp' );
1526 + } else {
1527 + $next_time = MainWP_System_Cron_Jobs::get_next_time_automatic_update_to_show();
1528 + if ( $next_time < $local_timestamp + 5 * MINUTE_IN_SECONDS ) {
1529 + $nextAutomaticUpdate = esc_html__( 'Any minute', 'mainwp' );
1530 + } else {
1531 + $nextAutomaticUpdate = MainWP_Utility::format_timestamp( $next_time );
1532 + }
1533 + }
1534 +
1535 + if ( empty( $lastAutomaticUpdate ) ) {
1536 + $lastAutomaticUpdate = esc_html__( 'Never', 'mainwp' );
1537 + } else {
1538 + $lastAutomaticUpdate = MainWP_Utility::format_timestamp( $lastAutomaticUpdate );
1539 + }
1540 +
1541 + return array(
1542 + 'last' => $lastAutomaticUpdate,
1543 + 'next' => $nextAutomaticUpdate,
1544 + );
1545 + }
1546 +
1547 + /**
1548 + * Returns false or the location of the OpenSSL Lib File.
1549 + *
1550 + * @return mixed false|opensslLibLocation
1551 + *
1552 + * @uses \MainWP\Dashboard\MainWP_Server_Information_Handler::is_openssl_config_warning()
1553 + */
1554 + public static function show_openssl_lib_config() {
1555 + return MainWP_Server_Information_Handler::is_openssl_config_warning() ? true : false;
1556 + }
1557 +
1558 + /**
1559 + * Render Advanced Options Subpage.
1560 + *
1561 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
1562 + */
1563 + public static function render_advanced() { //phpcs:ignore -- NOSONAR - complex method.
1564 + if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
1565 + \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
1566 + return;
1567 + }
1568 +
1569 + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) {
1570 +
1571 + $old_settings = static::get_all_settings_values();
1572 +
1573 + /**
1574 + * Action: mainwp_before_save_advanced_settings
1575 + *
1576 + * Fires before save advanced settings.
1577 + *
1578 + * @since 4.1
1579 + */
1580 + do_action( 'mainwp_before_save_advanced_settings', $_POST );
1581 +
1582 + MainWP_Utility::update_option( 'mainwp_maximumRequests', ! empty( $_POST['mainwp_maximumRequests'] ) ? intval( $_POST['mainwp_maximumRequests'] ) : 4 );
1583 + MainWP_Utility::update_option( 'mainwp_minimumDelay', ! empty( $_POST['mainwp_minimumDelay'] ) ? intval( $_POST['mainwp_minimumDelay'] ) : 200 );
1584 + MainWP_Utility::update_option( 'mainwp_maximumIPRequests', ! empty( $_POST['mainwp_maximumIPRequests'] ) ? intval( $_POST['mainwp_maximumIPRequests'] ) : 1 );
1585 + MainWP_Utility::update_option( 'mainwp_minimumIPDelay', ! empty( $_POST['mainwp_minimumIPDelay'] ) ? intval( $_POST['mainwp_minimumIPDelay'] ) : 1000 );
1586 + MainWP_Utility::update_option( 'mainwp_maximumSyncRequests', ! empty( $_POST['mainwp_maximumSyncRequests'] ) ? intval( $_POST['mainwp_maximumSyncRequests'] ) : 8 );
1587 + MainWP_Utility::update_option( 'mainwp_maximumInstallUpdateRequests', ! empty( $_POST['mainwp_maximumInstallUpdateRequests'] ) ? intval( $_POST['mainwp_maximumInstallUpdateRequests'] ) : 3 );
1588 + MainWP_Utility::update_option( 'mainwp_sslVerifyCertificate', isset( $_POST['mainwp_sslVerifyCertificate'] ) ? 1 : 0 );
1589 + 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 );
1590 + MainWP_Utility::update_option( 'mainwp_verify_connection_method', isset( $_POST['mainwp_settings_verify_connection_method'] ) ? intval( $_POST['mainwp_settings_verify_connection_method'] ) : 0 );
1591 + MainWP_Utility::update_option( 'mainwp_forceUseIPv4', isset( $_POST['mainwp_forceUseIPv4'] ) ? 1 : 0 );
1592 + $use_wpcron = ! isset( $_POST['mainwp_options_wp_cron'] ) ? 0 : 1;
1593 + MainWP_Utility::update_option( 'mainwp_wp_cron', $use_wpcron );
1594 + MainWP_Utility::update_option( 'mainwp_warm_cache_pages_ttl', intval( $_POST['mainwp_warm_cache_pages_ttl'] ) );
1595 +
1596 + MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) );
1597 + MainWP_Utility::update_option( 'mainwp_auto_correct_site_url', ( ! isset( $_POST['mainwp_auto_correct_site_url'] ) ? 0 : 1 ) );
1598 + MainWP_Utility::update_option( 'mainwp_maximum_uptime_monitoring_requests', ! empty( $_POST['mainwp_maximumUptimeMonitoringRequests'] ) ? intval( $_POST['mainwp_maximumUptimeMonitoringRequests'] ) : 10 );
1599 + MainWP_Utility::update_option( 'mainwp_chunksitesnumber', isset( $_POST['mainwp_chunksitesnumber'] ) ? intval( $_POST['mainwp_chunksitesnumber'] ) : 10 );
1600 + MainWP_Utility::update_option( 'mainwp_chunksleepinterval', isset( $_POST['mainwp_chunksleepinterval'] ) ? intval( $_POST['mainwp_chunksleepinterval'] ) : 5 );
1601 +
1602 + $sync_data = array();
1603 +
1604 + if ( isset( $_POST['mainwp_settings_sync_data'] ) && is_array( $_POST['mainwp_settings_sync_data'] ) ) {
1605 + $selected_data = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_settings_sync_data'] ) );
1606 + foreach ( $selected_data as $name ) {
1607 + $sync_data[ $name ] = 1;
1608 + }
1609 + }
1610 +
1611 + if ( isset( $_POST['mainwp_settings_sync_name'] ) && is_array( $_POST['mainwp_settings_sync_name'] ) ) {
1612 + $name_data = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_settings_sync_name'] ) );
1613 + foreach ( $name_data as $name ) {
1614 + if ( ! isset( $sync_data[ $name ] ) ) {
1615 + $sync_data[ $name ] = 0;
1616 + }
1617 + }
1618 + }
1619 +
1620 + MainWP_Utility::update_option( 'mainwp_settings_sync_data', wp_json_encode( $sync_data ) );
1621 +
1622 + // required check.
1623 + MainWP_Uptime_Monitoring_Schedule::instance()->check_to_disable_schedule_individual_uptime_monitoring(); // required a check to sync the settings.
1624 +
1625 + if ( isset( $_POST['mainwp_openssl_lib_location'] ) ) {
1626 + $openssl_loc = ! empty( $_POST['mainwp_openssl_lib_location'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_openssl_lib_location'] ) ) : '';
1627 + MainWP_Utility::update_option( 'mainwp_opensslLibLocation', $openssl_loc );
1628 + }
1629 + /**
1630 + * Action: mainwp_after_save_advanced_settings
1631 + *
1632 + * Fires after advanced settings save.
1633 + *
1634 + * @since 4.1
1635 + */
1636 + do_action( 'mainwp_after_save_advanced_settings', $_POST );
1637 +
1638 + $new_settings = self::get_all_settings_values();
1639 +
1640 + /**
1641 + * Action: mainwp_after_save_settings
1642 + *
1643 + * Fires after save settings.
1644 + *
1645 + * @since 6.0
1646 + *
1647 + * @param array $new_settings The new settings.
1648 + * @param array $old_settings The old settings.
1649 + */
1650 + do_action( 'mainwp_after_save_settings', $new_settings, $old_settings );
1651 +
1652 + }
1653 + static::render_header( 'Advanced' );
1654 + ?>
1655 +
1656 + <div id="mainwp-advanced-settings" class="ui padded segment">
1657 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-advanced-settings-info-notice' ) ) : ?>
1658 + <div class="ui info message">
1659 + <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-advanced-settings-info-notice"></i>
1660 + <?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' ); ?>
1661 + </div>
1662 + <?php endif; ?>
1663 + <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SettingsAdvanced' ) ) : ?>
1664 + <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?></div>
1665 + <?php endif; ?>
1666 + <div class="ui form">
1667 + <form method="POST" action="">
1668 + <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
1669 + <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'SettingsAdvanced' ) ); ?>" />
1670 + <?php
1671 +
1672 + /**
1673 + * Action: mainwp_advanced_settings_form_top
1674 + *
1675 + * Fires at the top of advanced settings form.
1676 + *
1677 + * @since 4.1
1678 + */
1679 + do_action( 'mainwp_advanced_settings_form_top' );
1680 +
1681 + if ( static::show_openssl_lib_config() ) {
1682 + $openssl_loc = MainWP_System_Utility::get_openssl_conf();
1683 + ?>
1684 + <h3 class="ui dividing header">
1685 + <?php esc_html_e( 'OpenSSL Settings', 'mainwp' ); ?>
1686 + <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>
1687 + </h3>
1688 + <div class="ui grid field">
1689 + <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL.cnf location', 'mainwp' ); ?></label>
1690 + <div class="ten wide column ui field">
1691 + <input type="text" name="mainwp_openssl_lib_location" value="<?php echo esc_html( $openssl_loc ); ?>">
1692 + <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' ); ?>
1693 + <?php
1694 + // translators: 1: Opening anchor tag. 2: Closing anchor tag.
1695 + 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://docs.mainwp.com/troubleshooting/potential-issues#openssl-library-error-invalid-request" target="_blank">', '</a> <i class="external alternate icon"></i>' );
1696 + ?>
1697 + </em>
1698 + <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>
1699 + </div>
1700 + </div>
1701 + <?php } ?>
1702 +
1703 + <h3 class="ui dividing header">
1704 + <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-cross-ip' ); ?>
1705 + <?php esc_html_e( 'Rate Limiting & Concurrency Controls', 'mainwp' ); ?>
1706 + <div class="sub header"><?php esc_html_e( 'Fine-tune how your system handles outgoing requests by managing both global and per-server concurrency limits.', 'mainwp' ); ?></div>
1707 + </h3>
1708 +
1709 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cross-ip" default-indi-value="4">
1710 + <label class="six wide column middle aligned">
1711 + <?php
1712 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumRequests', (int) get_option( 'mainwp_maximumRequests', 4 ) );
1713 + esc_html_e( 'Global request limit (Default: 4)', 'mainwp' );
1714 + ?>
1715 + </label>
1716 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Defines the overall maximum number of simultaneous requests that can be active. Adjust this setting to balance system throughput with resource constraints (default is 4).', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1717 + <div class="ui bottom aligned labeled slider" id="mainwp_maximumRequests_slider"></div>
1718 + <div class="ui input">
1719 + <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' ) ); ?>"/>
1720 + </div>
1721 + </div>
1722 + </div>
1723 +
1724 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cross-ip" default-indi-value="200">
1725 + <label class="six wide column middle aligned">
1726 + <?php
1727 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_minimumDelay', (int) get_option( 'mainwp_minimumDelay', 200 ) );
1728 + esc_html_e( 'Minimum delay between requests in milliseconds (Default: 200ms)', 'mainwp' );
1729 + ?>
1730 + </label>
1731 + <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">
1732 + <div class="ui bottom aligned labeled slider" id="mainwp_minimumDelay_slider"></div>
1733 + <div class="ui input">
1734 + <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' ) ); ?>"/>
1735 + </div>
1736 + </div>
1737 + </div>
1738 +
1739 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-per-ip" default-indi-value="1">
1740 + <label class="six wide column middle aligned">
1741 + <?php
1742 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumIPRequests', (int) get_option( 'mainwp_maximumIPRequests', 1 ) );
1743 + esc_html_e( 'Per-IP request limit (Default: 1)', 'mainwp' );
1744 + ?>
1745 + </label>
1746 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Sets the maximum number of concurrent requests allowed for any individual website\'s IP address. This setting safeguards target servers from excessive load (default is 1).', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1747 + <div class="ui bottom aligned labeled slider" id="mainwp_maximumIPRequests_slider"></div>
1748 + <div class="ui input">
1749 + <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' ) ); ?>"/>
1750 + </div>
1751 + </div>
1752 + </div>
1753 +
1754 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-per-ip" default-indi-value="1000">
1755 + <label class="six wide column middle aligned">
1756 + <?php
1757 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_minimumIPDelay', (int) get_option( 'mainwp_minimumIPDelay', 1000 ) );
1758 + esc_html_e( 'Minimum delay between requests to the same IP in milliseconds (Default: 1000ms)', 'mainwp' );
1759 + ?>
1760 + </label>
1761 + <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">
1762 + <div class="ui bottom aligned labeled slider" id="mainwp_minimumIPDelay_slider"></div>
1763 + <div class="ui input">
1764 + <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' ) ); ?>"/>
1765 + </div>
1766 + </div>
1767 + </div>
1768 +
1769 + <h3 class="ui dividing header">
1770 + <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-chunk-site' ); ?>
1771 + <?php esc_html_e( 'Batch Processing Settings', 'mainwp' ); ?>
1772 + <div class="sub header"><?php esc_html_e( 'Configure how many websites are processed at once and the delay between each batch to optimize system performance and prevent server overload.', 'mainwp' ); ?></div>
1773 + </h3>
1774 +
1775 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cross-ip" default-indi-value="10">
1776 + <label class="six wide column middle aligned">
1777 + <?php
1778 + MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', 10 === (int) get_option( 'mainwp_chunksitesnumber', 10 ) ? '' : 1 );
1779 + esc_html_e( 'Maximum sites per batch (Default: 10)', 'mainwp' );
1780 + ?>
1781 + </label>
1782 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'The maximum number of websites processed concurrently. If too many requests are sent out, they will begin to time out.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1783 + <div class="ui bottom aligned labeled slider" id="mainwp_chunksitesnumber_slider"></div>
1784 + <div class="ui input">
1785 + <input type="hidden" class="settings-field-value-change-handler" name="mainwp_chunksitesnumber" id="mainwp_chunksitesnumber" value="<?php echo false === get_option( 'mainwp_chunksitesnumber' ) ? 10 : (int) get_option( 'mainwp_chunksitesnumber' ); ?>"/>
1786 + </div>
1787 + </div>
1788 + </div>
1789 +
1790 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cross-ip" default-indi-value="5">
1791 + <label class="six wide column middle aligned">
1792 + <?php
1793 + MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', 5 === (int) get_option( 'mainwp_chunksleepinterval', 5 ) ? '' : 1 );
1794 + esc_html_e( 'Delay between batches (Default: 5ms)', 'mainwp' );
1795 + ?>
1796 + </label>
1797 + <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'The pause duration between processing each batch of websites.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1798 + <div class="ui bottom aligned labeled slider" id="mainwp_chunksleepinterval_slider"></div>
1799 + <div class="ui input">
1800 + <input type="hidden" class="settings-field-value-change-handler" name="mainwp_chunksleepinterval" id="mainwp_chunksleepinterval" value="<?php echo false === get_option( 'mainwp_chunksleepinterval' ) ? 5 : (int) get_option( 'mainwp_chunksleepinterval' ); ?>"/>
1801 + </div>
1802 + </div>
1803 + </div>
1804 +
1805 + <h3 class="ui dividing header">
1806 + <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-frontend-request' ); ?>
1807 + <?php esc_html_e( 'Frontend Request Settings', 'mainwp' ); ?>
1808 + <div class="sub header"><?php esc_html_e( 'Configure limits for concurrent background tasks such as synchronization, installation/updating, and uptime monitoring, ensuring efficient resource use and system stability.', 'mainwp' ); ?></div>
1809 + </h3>
1810 +
1811 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-frontend-request" default-indi-value="8">
1812 + <label class="six wide column middle aligned">
1813 + <?php
1814 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumSyncRequests', (int) get_option( 'mainwp_maximumSyncRequests', 8 ) );
1815 + esc_html_e( 'Maximum simultaneous sync requests (Default: 8)', 'mainwp' );
1816 + ?>
1817 + </label>
1818 + <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">
1819 + <div class="ui bottom aligned labeled slider" id="mainwp_maximumSyncRequests_slider"></div>
1820 + <div class="ui input">
1821 + <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' ) ); ?>"/>
1822 + </div>
1823 + </div>
1824 + </div>
1825 +
1826 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-frontend-request" default-indi-value="3">
1827 + <label class="six wide column middle aligned">
1828 + <?php
1829 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumInstallUpdateRequests', (int) get_option( 'mainwp_maximumInstallUpdateRequests', 3 ) );
1830 + esc_html_e( 'Maximum simultaneous install and update requests (Default: 3)', 'mainwp' );
1831 + ?>
1832 + </label>
1833 + <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">
1834 + <div class="ui bottom aligned labeled slider" id="mainwp_maximumInstallUpdateRequests_slider"></div>
1835 + <div class="ui input">
1836 + <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' ) ); ?>"/>
1837 + </div>
1838 + </div>
1839 + </div>
1840 +
1841 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-frontend-request" default-indi-value="10">
1842 + <label class="six wide column middle aligned">
1843 + <?php
1844 + $maximum_monitoring_requests = (int) get_option( 'mainwp_maximum_uptime_monitoring_requests', 10 );
1845 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximum_uptime_monitoring_requests', $maximum_monitoring_requests );
1846 + esc_html_e( 'Maximum simultaneous uptime monitoring requests (Default: 10)', 'mainwp' );
1847 + ?>
1848 + </label>
1849 + <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">
1850 + <div class="ui bottom aligned labeled slider settings-field-value-change-handler" id="mainwp_maximumUptimeMonitoringRequests_slider"></div>
1851 + <div class="ui input">
1852 + <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' ) ); ?>"/>
1853 + </div>
1854 + </div>
1855 + </div>
1856 +
1857 + <h3 class="ui dividing header">
1858 + <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-miscellaneous' ); ?>
1859 + <?php esc_html_e( 'Miscellaneous Settings', 'mainwp' ); ?></h3>
1860 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1">
1861 + <label class="six wide column middle aligned">
1862 + <?php
1863 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_optimize', (int) get_option( 'mainwp_optimize', 1 ) );
1864 + esc_html_e( 'Optimize data loading', 'mainwp' );
1865 + ?>
1866 + </label>
1867 + <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">
1868 + <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: Enabled', 'mainwp' ); ?></label>
1869 + </div>
1870 + </div>
1871 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1">
1872 + <label class="six wide column middle aligned">
1873 + <?php
1874 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_auto_correct_site_url', (int) get_option( 'mainwp_auto_correct_site_url', 1 ) );
1875 + esc_html_e( 'Auto-correct site URLs', 'mainwp' );
1876 + ?>
1877 + </label>
1878 + <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will automatically correct the stored site URL when the child site reports a different address. Only safe changes are applied (www variant and HTTP to HTTPS); the corrected URL is verified before saving, and sites with a locked URL are never changed.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1879 + <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_auto_correct_site_url" id="mainwp_auto_correct_site_url" <?php echo 1 === (int) get_option( 'mainwp_auto_correct_site_url', 1 ) ? 'checked="true"' : ''; ?> /><label><?php esc_html_e( 'Default: Enabled', 'mainwp' ); ?></label>
1880 + </div>
1881 + </div>
1882 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="10">
1883 + <label class="six wide column middle aligned">
1884 + <?php
1885 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_warm_cache_pages_ttl', (int) get_option( 'mainwp_warm_cache_pages_ttl', 10 ) );
1886 + esc_html_e( 'Browser cache expiration time', 'mainwp' );
1887 + $browser_cache_ttl = (int) get_option( 'mainwp_warm_cache_pages_ttl', 10 );
1888 + ?>
1889 + </label>
1890 + <div class="five wide column" data-tooltip="<?php esc_attr_e( 'Set how many minutes the browser cache should retain page content before it expires', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1891 + <input type="number" class="settings-field-value-change-handler small-text" name="mainwp_warm_cache_pages_ttl" id="mainwp_warm_cache_pages_ttl" placeholder="" min="1" max="24" step="1" value="<?php echo intval( $browser_cache_ttl ); ?>">
1892 + </div>
1893 + </div>
1894 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1">
1895 + <label class="six wide column middle aligned">
1896 + <?php
1897 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_wp_cron', (int) get_option( 'mainwp_wp_cron', 1 ) );
1898 + esc_html_e( 'Use WP Cron', 'mainwp' );
1899 + ?>
1900 + </label>
1901 + <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">
1902 + <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: Enabled', 'mainwp' ); ?></label>
1903 + </div>
1904 + </div>
1905 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1" >
1906 + <label class="six wide column middle aligned">
1907 + <?php
1908 + $indi_val = (int) get_option( 'mainwp_sslVerifyCertificate', 1 );
1909 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_sslVerifyCertificate', $indi_val );
1910 + esc_html_e( 'Verify SSL certificate', 'mainwp' );
1911 + ?>
1912 + </label>
1913 + <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">
1914 + <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: Enabled', 'mainwp' ); ?></label>
1915 + </div>
1916 + </div>
1917 + <?php
1918 + $general_verify_con = (int) get_option( 'mainwp_verify_connection_method', 1 );
1919 + ?>
1920 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1">
1921 + <label class="six wide column middle aligned">
1922 + <?php
1923 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_verify_connection_method', (int) $general_verify_con );
1924 + esc_html_e( 'Verify connection method', 'mainwp' );
1925 + ?>
1926 + </label>
1927 + <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">
1928 + <select class="ui dropdown settings-field-value-change-handler" id="mainwp_settings_verify_connection_method" name="mainwp_settings_verify_connection_method">
1929 + <option <?php echo ( empty( $general_verify_con ) || 1 === $general_verify_con ) ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'OpenSSL (default)', 'mainwp' ); ?></option>
1930 + <option <?php echo ( 2 === $general_verify_con ) ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'PHPSECLIB (fallback)', 'mainwp' ); ?></option>
1931 + </select>
1932 + </div>
1933 + </div>
1934 + <?php
1935 + $sign_note = MainWP_Connect_Lib::get_connection_algo_settings_note();
1936 + $sign_algs = MainWP_System_Utility::get_open_ssl_sign_algos();
1937 + $general_sign_alg = get_option( 'mainwp_connect_signature_algo', false );
1938 + if ( false === $general_sign_alg ) {
1939 + $general_sign_alg = defined( 'OPENSSL_ALGO_SHA256' ) ? OPENSSL_ALGO_SHA256 : 1;
1940 + MainWP_Utility::update_option( 'mainwp_connect_signature_algo', $general_sign_alg );
1941 + } else {
1942 + $general_sign_alg = intval( $general_sign_alg );
1943 + }
1944 + $algo_def = defined( 'OPENSSL_ALGO_SHA256' ) ? (int) OPENSSL_ALGO_SHA256 : 1;
1945 + ?>
1946 + <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;"' : ''; ?> >
1947 + <label class="six wide column middle aligned">
1948 + <?php
1949 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_connect_signature_algo', (int) $general_sign_alg );
1950 + esc_html_e( 'OpenSSL signature algorithm', 'mainwp' );
1951 + ?>
1952 + </label>
1953 + <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">
1954 + <select class="ui dropdown settings-field-value-change-handler" id="mainwp_settings_openssl_alg" name="mainwp_settings_openssl_alg">
1955 + <?php
1956 + foreach ( $sign_algs as $val => $text ) {
1957 + ?>
1958 + <option <?php echo ( $val === $general_sign_alg ) ? 'selected' : ''; ?> value="<?php echo esc_attr( $val ); ?>"><?php echo esc_html( $text ); ?></option>
1959 + <?php
1960 + }
1961 + ?>
1962 + </select>
1963 + <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>
1964 + </div>
1965 + </div>
1966 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous">
1967 + <label class="six wide column middle aligned">
1968 + <?php
1969 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_forceUseIPv4', (int) get_option( 'mainwp_forceUseIPv4' ) );
1970 + esc_html_e( 'Force IPv4', 'mainwp' );
1971 + ?>
1972 + </label>
1973 + <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 trying to connect child sites.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1974 + <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: Disabled', 'mainwp' ); ?></label>
1975 + </div>
1976 + </div>
1977 + <?php
1978 + static::render_sync_data_selection();
1979 + /**
1980 + * Action: mainwp_advanced_settings_form_bottom
1981 + *
1982 + * Fires at the bottom of advanced settings form.
1983 + *
1984 + * @since 4.1
1985 + */
1986 + do_action( 'mainwp_advanced_settings_form_bottom' );
1987 +
1988 + ?>
1989 + <div class="ui divider"></div>
1990 + <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1991 + </form>
1992 + </div>
1993 + </div>
1994 + <?php static::render_disable_installed_plugins_sync_modal(); ?>
1995 + <script>
1996 + jQuery(document).ready(function() {
1997 + const maximumRequests = <?php echo ! empty( get_option( 'mainwp_maximumRequests' ) ) ? esc_js( get_option( 'mainwp_maximumRequests' ) ) : 4; ?>;
1998 + jQuery('#mainwp_maximumRequests_slider').slider({
1999 + min: 1,
2000 + max: 20,
2001 + start: maximumRequests,
2002 + step: 1,
2003 + restrictedLabels: [1,20],
2004 + showThumbTooltip: true,
2005 + tooltipConfig: {
2006 + position: 'top center',
2007 + variation: 'small visible black'
2008 + },
2009 + onChange: function(value) {
2010 + jQuery('#mainwp_maximumRequests').val(value);
2011 + }
2012 + });
2013 + const minimumDelay = <?php echo ! empty( get_option( 'mainwp_minimumDelay' ) ) ? esc_js( get_option( 'mainwp_minimumDelay' ) ) : 200; ?>;
2014 + jQuery('#mainwp_minimumDelay_slider').slider({
2015 + min: 100,
2016 + max: 5000,
2017 + start: minimumDelay,
2018 + step: 100,
2019 + restrictedLabels: [100,5000],
2020 + showThumbTooltip: true,
2021 + tooltipConfig: {
2022 + position: 'top center',
2023 + variation: 'small visible black'
2024 + },
2025 + onChange: function(value) {
2026 + jQuery('#mainwp_minimumDelay').val(value);
2027 + }
2028 + });
2029 + const maximumIPRequests = <?php echo ! empty( get_option( 'mainwp_maximumIPRequests' ) ) ? esc_js( get_option( 'mainwp_maximumIPRequests' ) ) : 1; ?>;
2030 + jQuery('#mainwp_maximumIPRequests_slider').slider({
2031 + min: 1,
2032 + max: 10,
2033 + start: maximumIPRequests,
2034 + step: 1,
2035 + restrictedLabels: [1,10],
2036 + showThumbTooltip: true,
2037 + tooltipConfig: {
2038 + position: 'top center',
2039 + variation: 'small visible black'
2040 + },
2041 + onChange: function(value) {
2042 + jQuery('#mainwp_maximumIPRequests').val(value);
2043 + }
2044 + });
2045 + const minimumIPDelay = <?php echo ! empty( get_option( 'mainwp_minimumIPDelay' ) ) ? esc_js( get_option( 'mainwp_minimumIPDelay' ) ) : 1000; ?>;
2046 + jQuery('#mainwp_minimumIPDelay_slider').slider({
2047 + min: 500,
2048 + max: 5000,
2049 + start: minimumIPDelay,
2050 + step: 100,
2051 + restrictedLabels: [500,5000],
2052 + showThumbTooltip: true,
2053 + tooltipConfig: {
2054 + position: 'top center',
2055 + variation: 'small visible black'
2056 + },
2057 + onChange: function(value) {
2058 + jQuery('#mainwp_minimumIPDelay').val(value);
2059 + }
2060 + });
2061 + const maximumSyncRequests = <?php echo ! empty( get_option( 'mainwp_maximumSyncRequests' ) ) ? esc_js( get_option( 'mainwp_maximumSyncRequests' ) ) : 8; ?>;
2062 + jQuery('#mainwp_maximumSyncRequests_slider').slider({
2063 + min: 1,
2064 + max: 20,
2065 + start: maximumSyncRequests,
2066 + step: 1,
2067 + restrictedLabels: [1,20],
2068 + showThumbTooltip: true,
2069 + tooltipConfig: {
2070 + position: 'top center',
2071 + variation: 'small visible black'
2072 + },
2073 + onChange: function(value) {
2074 + jQuery('#mainwp_maximumSyncRequests').val(value);
2075 + }
2076 + });
2077 + const maximumInstallUpdateRequests = <?php echo ! empty( get_option( 'mainwp_maximumInstallUpdateRequests' ) ) ? esc_js( get_option( 'mainwp_maximumInstallUpdateRequests' ) ) : 3; ?>;
2078 + jQuery('#mainwp_maximumInstallUpdateRequests_slider').slider({
2079 + min: 1,
2080 + max: 20,
2081 + start: maximumInstallUpdateRequests,
2082 + step: 1,
2083 + restrictedLabels: [1,20],
2084 + showThumbTooltip: true,
2085 + tooltipConfig: {
2086 + position: 'top center',
2087 + variation: 'small visible black'
2088 + },
2089 + onChange: function(value) {
2090 + jQuery('#mainwp_maximumInstallUpdateRequests').val(value);
2091 + }
2092 + });
2093 + const maximumUptimeMonitoringRequests = <?php echo ! empty( get_option( 'mainwp_maximum_uptime_monitoring_requests' ) ) ? esc_js( get_option( 'mainwp_maximum_uptime_monitoring_requests' ) ) : 10; ?>;
2094 + jQuery('#mainwp_maximumUptimeMonitoringRequests_slider').slider({
2095 + min: 1,
2096 + max: 100,
2097 + start: maximumUptimeMonitoringRequests,
2098 + step: 1,
2099 + restrictedLabels: [1,100],
2100 + showThumbTooltip: true,
2101 + tooltipConfig: {
2102 + position: 'top center',
2103 + variation: 'small visible black'
2104 + },
2105 + onChange: function(value) {
2106 + jQuery('#mainwp_maximumUptimeMonitoringRequests').val(value).change();
2107 + }
2108 + });
2109 + jQuery('#mainwp_maximumUptimeMonitoringRequests_slider').slider('set value', maximumUptimeMonitoringRequests);
2110 +
2111 + jQuery('#mainwp_chunksitesnumber_slider').slider({
2112 + min: 1,
2113 + max: 30,
2114 + start: <?php echo false !== get_option( 'mainwp_chunksitesnumber' ) ? intval( get_option( 'mainwp_chunksitesnumber' ) ) : 10; ?>,
2115 + step: 1,
2116 + restrictedLabels: [1,30],
2117 + showThumbTooltip: true,
2118 + tooltipConfig: {
2119 + position: 'top center',
2120 + variation: 'small visible black'
2121 + },
2122 + onChange: function(value) {
2123 + jQuery('#mainwp_chunksitesnumber').val(value).change();
2124 + }
2125 + });
2126 +
2127 + jQuery('#mainwp_chunksleepinterval_slider').slider({
2128 + min: 0,
2129 + max: 20,
2130 + start: <?php echo false !== get_option( 'mainwp_chunksleepinterval' ) ? intval( get_option( 'mainwp_chunksleepinterval' ) ) : 5; ?>,
2131 + step: 1,
2132 + restrictedLabels: [0,20],
2133 + showThumbTooltip: true,
2134 + tooltipConfig: {
2135 + position: 'top center',
2136 + variation: 'small visible black'
2137 + },
2138 + onChange: function(value) {
2139 + jQuery('#mainwp_chunksleepinterval').val(value).change();
2140 + }
2141 + });
2142 + });
2143 + </script>
2144 + <?php
2145 + static::render_footer( 'Advanced' );
2146 + }
2147 +
2148 + /**
2149 + * Method render_sync_data_selection().
2150 + *
2151 + * @return void
2152 + */
2153 + public static function render_sync_data_selection() {
2154 +
2155 + $default_sync = static::get_data_sync_default();
2156 +
2157 + $sync_data_settings = get_option( 'mainwp_settings_sync_data' );
2158 +
2159 + $sync_data_settings = ! empty( $sync_data_settings ) ? json_decode( $sync_data_settings, true ) : array();
2160 +
2161 + if ( ! is_array( $sync_data_settings ) ) {
2162 + $sync_data_settings = array();
2163 + }
2164 +
2165 + $setting_page = true;
2166 +
2167 + ?>
2168 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous">
2169 + <label class="six wide column top aligned">
2170 + <?php
2171 + MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-sync-data' );
2172 + esc_html_e( 'Select data to sync', 'mainwp' );
2173 + ?>
2174 + </label>
2175 + <div class="ten wide column" <?php echo $setting_page ? 'data-tooltip="' . esc_attr__( 'Select data that you want to sync.', 'mainwp' ) . '"' : ''; ?> data-inverted="" data-position="top left">
2176 + <ul class="mainwp_hide_wpmenu_checkboxes">
2177 + <?php
2178 + foreach ( $default_sync as $name => $title ) {
2179 + $_selected = '';
2180 + if ( ! isset( $sync_data_settings[ $name ] ) || 1 === (int) $sync_data_settings[ $name ] ) {
2181 + $_selected = 'checked';
2182 + }
2183 + ?>
2184 + <li>
2185 + <div class="ui checkbox">
2186 + <input type="checkbox" class="settings-field-value-change-handler" id="mainwp_select_sync_<?php echo esc_attr( $name ); ?>" name="mainwp_settings_sync_data[]" <?php echo esc_html( $_selected ); ?> value="<?php echo esc_attr( $name ); ?>">
2187 + <label for="mainwp_select_sync_<?php echo esc_attr( $name ); ?>" ><?php echo esc_html( $title ); ?></label>
2188 + </div>
2189 + <input type="hidden" name="mainwp_settings_sync_name[]" value="<?php echo esc_attr( $name ); ?>">
2190 + </li>
2191 + <?php
2192 + }
2193 + ?>
2194 + </ul>
2195 + </div>
2196 + </div>
2197 + <?php
2198 + }
2199 +
2200 + /**
2201 + * Render the Installed plugins sync warning modal.
2202 + *
2203 + * @since 6.1.3
2204 + *
2205 + * @return void
2206 + */
2207 + public static function render_disable_installed_plugins_sync_modal() {
2208 + ?>
2209 + <div class="ui small modal" id="mainwp-disable-installed-plugins-sync-modal">
2210 + <div class="header"><?php esc_html_e( 'Disable Installed Plugins Sync?', 'mainwp' ); ?></div>
2211 + <div class="content">
2212 + <div class="ui yellow message">
2213 + <div class="header"><?php esc_html_e( 'MainWP Add-ons may not work as expected', 'mainwp' ); ?></div>
2214 + <p><?php esc_html_e( 'Some MainWP Add-ons need the installed plugins data to detect required plugins on your Child Sites. If you disable this option, those Add-ons may not work as expected.', 'mainwp' ); ?></p>
2215 + </div>
2216 + </div>
2217 + <div class="actions">
2218 + <div class="ui basic cancel button"><?php esc_html_e( 'Cancel', 'mainwp' ); ?></div>
2219 + <div class="ui green approve button"><?php esc_html_e( 'I understand', 'mainwp' ); ?></div>
2220 + </div>
2221 + </div>
2222 + <script type="text/javascript">
2223 + jQuery( document ).ready( function () {
2224 + const installedPluginsCheckbox = jQuery( '#mainwp_select_sync_plugins' );
2225 + const warningModal = jQuery( '#mainwp-disable-installed-plugins-sync-modal' );
2226 + let disableConfirmed = false;
2227 +
2228 + installedPluginsCheckbox.on( 'change', function () {
2229 + if ( installedPluginsCheckbox.is( ':checked' ) ) {
2230 + disableConfirmed = false;
2231 + return;
2232 + }
2233 +
2234 + if ( disableConfirmed ) {
2235 + return;
2236 + }
2237 +
2238 + warningModal.modal( {
2239 + closable: false,
2240 + onApprove: function () {
2241 + disableConfirmed = true;
2242 + },
2243 + onDeny: function () {
2244 + installedPluginsCheckbox.prop( 'checked', true ).trigger( 'change' );
2245 + }
2246 + } ).modal( 'show' );
2247 + } );
2248 + } );
2249 + </script>
2250 + <?php
2251 + }
2252 +
2253 + /**
2254 + * Method get_data_sync_default().
2255 + *
2256 + * @return array data.
2257 + */
2258 + public static function get_data_sync_default() {
2259 + return array(
2260 + 'wp_updates' => __( 'WordPress updates information', 'mainwp' ),
2261 + 'plugin_updates' => __( 'Plugins updates information', 'mainwp' ),
2262 + 'theme_updates' => __( 'Themes updates information', 'mainwp' ),
2263 + 'translation_updates' => __( 'Translations updates information', 'mainwp' ),
2264 + 'recent_comments' => __( 'Recent comments', 'mainwp' ),
2265 + 'recent_posts' => __( 'Recent posts', 'mainwp' ),
2266 + 'recent_pages' => __( 'Recent pages', 'mainwp' ),
2267 + 'securityStats' => __( 'Site hardening information', 'mainwp' ),
2268 + 'directories' => __( 'Site directory listing (needed for legacy backup feature)', 'mainwp' ),
2269 + 'categories' => __( 'Posts catetegories', 'mainwp' ),
2270 + 'totalsize' => __( 'Website size (needed for Clone and legacy backup features)', 'mainwp' ),
2271 + 'dbsize' => __( 'Database size information', 'mainwp' ),
2272 + 'plugins' => __( 'Installed plugins', 'mainwp' ),
2273 + 'themes' => __( 'Installed Themes', 'mainwp' ),
2274 + 'users' => __( 'Users information', 'mainwp' ),
2275 + 'plugins_outdate_info' => __( 'Abandoned plugins information', 'mainwp' ),
2276 + 'themes_outdate_info' => __( 'Abandoned themes information', 'mainwp' ),
2277 + 'health_site_status' => __( 'Site health information', 'mainwp' ),
2278 + 'child_site_actions_data' => __( 'Non-MainWP changes data', 'mainwp' ),
2279 + 'othersData' => __( 'Other data (required by some extensions)', 'mainwp' ),
2280 + );
2281 + }
2282 +
2283 + /**
2284 + * Method get_data_list_to_sync().
2285 + *
2286 + * @return array Data list to sync.
2287 + */
2288 + public function get_data_list_to_sync() {
2289 + $sync_data_settings = get_option( 'mainwp_settings_sync_data' );
2290 +
2291 + if ( false === $sync_data_settings ) {
2292 + $default_sync = static::get_data_sync_default();
2293 + $sync_lists = array_fill_keys( array_keys( $default_sync ), 1 );
2294 + MainWP_Utility::update_option( 'mainwp_settings_sync_data', wp_json_encode( $sync_lists ) );
2295 + return $sync_lists;
2296 + }
2297 +
2298 + $sync_lists = ! empty( $sync_data_settings ) ? json_decode( $sync_data_settings, true ) : array();
2299 +
2300 + if ( ! is_array( $sync_lists ) ) {
2301 + $sync_lists = array();
2302 + }
2303 + return $sync_lists;
2304 + }
2305 +
2306 +
2307 + /**
2308 + * Render MainWP Tools SubPage.
2309 + *
2310 + * @uses \MainWP\Dashboard\MainWP_UI::render_screen_options()
2311 + */
2312 + public static function render_mainwp_tools() { // phpcs:ignore -- NOSONAR - complex.
2313 + if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
2314 + \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
2315 + return;
2316 + }
2317 + static::render_header( 'MainWPTools' );
2318 + ?>
2319 + <div id="mainwp-tools-settings" class="ui padded segment">
2320 + <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
2321 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-message' ) ) : ?>
2322 + <div class="ui info message">
2323 + <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-message"></i>
2324 + <?php
2325 + // translators: 1: Opening anchor tag. 2: Closing anchor tag.
2326 + 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://docs.mainwp.com/sites/management/mainwp-dashboard-settings#mainwp-dashboard-settings" target="_blank">', '</a> <i class="external alternate icon"></i>' );
2327 + ?>
2328 + </div>
2329 + <?php endif; ?>
2330 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-tools-info-custom-theme' ) ) : ?>
2331 + <div class="ui info message">
2332 + <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-tools-info-custom-theme"></i>
2333 + <div><?php esc_html_e( 'Here you can select a theme for your MainWP Dashboard.', 'mainwp' ); ?></div>
2334 + <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>
2335 + </div>
2336 + <?php endif; ?>
2337 + <?php
2338 + $show_saved_message = false;
2339 + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) {
2340 + $show_saved_message = true;
2341 + } elseif ( get_transient( 'mainwp_settings_saved' ) ) {
2342 + $show_saved_message = true;
2343 + delete_transient( 'mainwp_settings_saved' ); // Remove transient after showing message.
2344 + }
2345 + ?>
2346 + <?php if ( $show_saved_message ) : ?>
2347 + <div class="ui green message">
2348 + <i class="close icon"></i>
2349 + <?php esc_html_e( 'Settings have been saved successfully!', 'mainwp' ); ?>
2350 + </div>
2351 + <?php endif; ?>
2352 + <?php if ( isset( $_POST['mainwp_restore_info_messages'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) : ?>
2353 + <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Info messages have been restored successfully!', 'mainwp' ); ?></div>
2354 + <?php endif; ?>
2355 + <div class="ui form">
2356 + <form method="POST" action="">
2357 + <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
2358 + <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'MainWPTools' ) ); ?>" />
2359 +
2360 + <?php
2361 + /**
2362 + * Action: mainwp_tools_form_top
2363 + *
2364 + * Fires at the top of MainWP tools form.
2365 + *
2366 + * @since 4.1
2367 + */
2368 + do_action( 'mainwp_tools_form_top' );
2369 +
2370 + $show_qsw = apply_filters( 'mainwp_show_qsw', true );
2371 +
2372 + static::get_instance()->render_select_custom_themes();
2373 +
2374 + ?>
2375 + <?php if ( get_option( 'mainwp_not_start_encrypt_keys' ) ) { ?>
2376 + <div class="ui grid field">
2377 + <label class="six wide column middle aligned"><?php esc_html_e( 'OpenSSL Key Encryption', 'mainwp' ); ?></label>
2378 + <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">
2379 + <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' ); ?>" />
2380 + </div>
2381 + </div>
2382 + <?php } ?>
2383 + <div class="ui grid field">
2384 + <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashboard to establish a new connection', 'mainwp' ); ?></label>
2385 + <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">
2386 + <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' ); ?>" />
2387 + </div>
2388 + </div>
2389 + <div class="ui grid field">
2390 + <label class="six wide column middle aligned"><?php esc_html_e( 'Force your MainWP Dashboard to set a new pair of OpenSSL Keys', 'mainwp' ); ?></label>
2391 + <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">
2392 + <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>
2393 + </div>
2394 + </div>
2395 + <?php if ( $show_qsw ) { ?>
2396 + <div class="ui grid field">
2397 + <label class="six wide column middle aligned"><?php esc_html_e( 'Start the MainWP Quick Setup Wizard', 'mainwp' ); ?></label>
2398 + <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>
2399 + </div>
2400 + <?php } ?>
2401 + <div class="ui grid field">
2402 + <label class="six wide column middle aligned"><?php esc_html_e( 'Export child sites to CSV file', 'mainwp' ); ?></label>
2403 + <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>
2404 + </div>
2405 + <div class="ui grid field">
2406 + <label class="six wide column middle aligned"><?php esc_html_e( 'Import child sites', 'mainwp' ); ?></label>
2407 + <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>
2408 + </div>
2409 + <div class="ui grid field">
2410 + <label class="six wide column middle aligned"><?php esc_html_e( 'Disconnect all child sites', 'mainwp' ); ?></label>
2411 + <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">
2412 + <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>
2413 + </div>
2414 + </div>
2415 + <div class="ui grid field">
2416 + <label class="six wide column middle aligned"><?php esc_html_e( 'Delete add-ons API Activation data', 'mainwp' ); ?></label>
2417 + <div class="ten wide column" id="mainwp-clear-activation-data" data-content="<?php esc_attr_e( 'This does not affect extensions settings, it just removes API activation data.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
2418 + <a href="admin.php?page=MainWPTools&clearActivationData=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'clear_activation_data' ) ); ?>" onclick="mainwp_tool_confirm_to_process(this); return false;" class="ui button green basic"><?php esc_html_e( 'Delete Add-ons API Activation Data', 'mainwp' ); ?></a>
2419 + </div>
2420 + </div>
2421 + <div class="ui grid field">
2422 + <label class="six wide column middle aligned"><?php esc_html_e( 'Delete archived Network Activity data', 'mainwp' ); ?></label>
2423 + <div class="ten wide column" id="mainwp-clear-archived-sites-changes-data" data-content="<?php esc_attr_e( 'Delete archived sNetwork Activity data.', 'mainwp' ); ?>" data-variation="inverted" data-position="top left">
2424 + <a href="admin.php?page=MainWPTools&clearArchivedSitesChangesData=yes&_wpnonce=<?php echo esc_attr( wp_create_nonce( 'clear_archived_sites_changes' ) ); ?>" onclick="mainwp_tool_confirm_to_process(this); return false;" class="ui button green basic"><?php esc_html_e( 'Delete Archived Network Activity Data', 'mainwp' ); ?></a>
2425 + </div>
2426 + </div>
2427 + <div class="ui grid field">
2428 + <label class="six wide column middle aligned"><?php esc_html_e( 'Restore all info messages', 'mainwp' ); ?></label>
2429 + <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">
2430 + <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' ); ?>"/>
2431 + </div>
2432 + </div>
2433 +
2434 + <h3 class="ui dividing header">
2435 + <?php esc_html_e( 'Privacy & Third-Party Services Permissions', 'mainwp' ); ?>
2436 + <div class="sub header"><?php esc_html_e( 'These tools are implemented using JavaScript and are subject to their respective privacy policies. You can choose which services to enable below, and update preferences at any time.', 'mainwp' ); ?></div>
2437 + </h3>
2438 +
2439 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-tools">
2440 + <label class="six wide column middle aligned">
2441 + <?php
2442 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_enable_guided_tours', (int) get_option( 'mainwp_enable_guided_tours', 0 ) );
2443 + esc_html_e( 'Usetiful (Interactive Guides & Tips)', 'mainwp' );
2444 + ?>
2445 + <span class="ui blue mini label"><?php esc_html_e( 'BETA', 'mainwp' ); ?></span>
2446 + </label>
2447 + <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">
2448 + <div class="ui toggle checkbox">
2449 + <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"' : ''; ?> />
2450 + <label><?php esc_html_e( 'Enable guided tours, tooltips, and onboarding assistance to help you navigate MainWP more efficiently.', 'mainwp' ); ?></label>
2451 + </div>
2452 + </div>
2453 + </div>
2454 +
2455 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-tools">
2456 + <label class="six wide column middle aligned">
2457 + <?php
2458 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_enable_guided_chatbase', (int) get_option( 'mainwp_enable_guided_chatbase', 0 ) );
2459 + esc_html_e( 'Chatbase (AI-Powered Chat Support)', 'mainwp' );
2460 + ?>
2461 + <span class="ui blue mini label"><?php esc_html_e( 'BETA', 'mainwp' ); ?></span>
2462 + </label>
2463 + <div class="ten wide column " data-tooltip="<?php esc_attr_e( 'Check this option to enable, or uncheck to disable MainWP AI drive support.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
2464 + <div class="ui toggle checkbox">
2465 + <input type="checkbox" class="settings-field-value-change-handler" name="mainwp-guided-chatbase-option" id="mainwp-guided-chatbase-option" <?php echo 1 === (int) get_option( 'mainwp_enable_guided_chatbase', 0 ) ? 'checked="true"' : ''; ?> />
2466 + <label><?php esc_html_e( 'Get AI-driven support within the MainWP Dashboard for quick answers to common questions.', 'mainwp' ); ?></label>
2467 + </div>
2468 + </div>
2469 + </div>
2470 +
2471 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-tools">
2472 + <label class="six wide column middle aligned">
2473 + <?php
2474 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_enable_guided_video', (int) get_option( 'mainwp_enable_guided_video', 0 ) );
2475 + esc_html_e( 'Youtube Embeds (Video Tutorials)', 'mainwp' );
2476 + ?>
2477 + </label>
2478 + <div class="ten wide column " data-tooltip="<?php esc_attr_e( 'Check this option to enable, or uncheck to disable MainWP video tutorials.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
2479 + <div class="ui toggle checkbox">
2480 + <input type="checkbox" class="settings-field-value-change-handler" name="mainwp-guided-video-option" id="mainwp-guided-video-option" <?php echo 1 === (int) get_option( 'mainwp_enable_guided_video', 0 ) ? 'checked="true"' : ''; ?> />
2481 + <label><?php esc_html_e( 'Enable embedded YouTube video tutorials within MainWP for step-by-step guidance.', 'mainwp' ); ?></label>
2482 + </div>
2483 + </div>
2484 + </div>
2485 + <?php
2486 + /**
2487 + * Action: mainwp_tools_form_bottom
2488 + *
2489 + * Fires at the bottom of mainwp tools form.
2490 + *
2491 + * @since 4.1
2492 + */
2493 + do_action( 'mainwp_tools_form_bottom' );
2494 + $el_id_sbm_btn_1 = 'submit';
2495 + ?>
2496 + <div class="ui divider"></div>
2497 + <input type="submit" name="submit" id="<?php echo esc_attr( $el_id_sbm_btn_1 ); ?>" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
2498 + </form>
2499 + </div>
2500 + </div>
2501 + <script type="text/javascript">
2502 + jQuery( '#mainwp-disconnect-sites-tool' ).popup();
2503 + jQuery( '#mainwp-clear-activation-data' ).popup();
2504 + </script>
2505 + <?php
2506 + static::render_footer( 'MainWPTools' );
2507 + MainWP_Connect_Helper::render_renew_connections_modal();
2508 + }
2509 +
2510 + /**
2511 + * Method is_basic_auth_dashboard_enabled.
2512 + *
2513 + * @return bool true|false.
2514 + */
2515 + public static function is_basic_auth_dashboard_enabled() { // phpcs:ignore -- NOSONAR - complex.
2516 + $response = wp_remote_get( get_site_url() . '/wp-json' );
2517 + $code = wp_remote_retrieve_response_code( $response );
2518 + if ( 404 === (int) $code || 401 === (int) $code ) {
2519 + return true;
2520 + }
2521 + return false;
2522 + }
2523 +
2524 +
2525 + /**
2526 + * Render MainWP themes selection.
2527 + */
2528 + public function render_select_custom_themes() { // phpcs:ignore -- NOSONAR - complex.
2529 + $custom_theme = $this->get_current_user_theme();
2530 + if ( false === $custom_theme ) {
2531 + // to compatible with Custom Dashboard extension settings.
2532 + $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
2533 + if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
2534 + $compat_theme = $compat_settings['theme'];
2535 + }
2536 + if ( null !== $compat_theme ) {
2537 + $custom_theme = $compat_theme;
2538 + }
2539 + }
2540 + $themes_files = static::get_instance()->get_custom_themes_files();
2541 + if ( empty( $themes_files ) ) {
2542 + $themes_files = array();
2543 + }
2544 + ?>
2545 + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-tools" default-indi-value="default">
2546 + <label class="six wide column middle aligned">
2547 + <?php
2548 + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_selected_theme', $custom_theme );
2549 + esc_html_e( 'Select MainWP Dashboard theme', 'mainwp' );
2550 + ?>
2551 + </label>
2552 + <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">
2553 + <select name="mainwp_settings_custom_theme" id="mainwp_settings_custom_theme" class="ui dropdown selection settings-field-value-change-handler">
2554 + <option value="default" <?php echo ( 'default' === $custom_theme || empty( $custom_theme ) ) ? 'selected' : ''; ?>><?php esc_html_e( 'Light', 'mainwp' ); ?></option>
2555 + <option value="default-dark" <?php echo ( 'default-dark' === $custom_theme || empty( $custom_theme ) ) ? 'selected' : ''; ?>><?php esc_html_e( 'Dark', 'mainwp' ); ?></option>
2556 + <?php if ( 'default-2024' === $custom_theme ) { ?>
2557 + <option value="default-2024" <?php echo ( 'default-2024' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Default 2024', 'mainwp' ); ?></option>
2558 + <?php } ?>
2559 + <?php if ( 'dark' === $custom_theme ) { ?>
2560 + <option value="dark" <?php echo ( 'dark' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Dark 2024', 'mainwp' ); ?></option>
2561 + <?php } ?>
2562 + <?php if ( 'classic' === $custom_theme ) { ?>
2563 + <option value="classic" <?php echo ( 'classic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Classic (Legacy)', 'mainwp' ); ?></option>
2564 + <?php } ?>
2565 + <?php if ( 'wpadmin' === $custom_theme ) { ?>
2566 + <option value="wpadmin" <?php echo ( 'wpadmin' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'WP Admin (Legacy)', 'mainwp' ); ?></option>
2567 + <?php } ?>
2568 + <?php if ( 'minimalistic' === $custom_theme ) { ?>
2569 + <option value="minimalistic" <?php echo ( 'minimalistic' === $custom_theme ) ? 'selected' : ''; ?>><?php esc_html_e( 'Minimalistic (Legacy)', 'mainwp' ); ?></option>
2570 + <?php } ?>
2571 + <?php
2572 + foreach ( $themes_files as $file_name => $theme ) {
2573 + $theme = ucfirst( $theme );
2574 + $_select = '';
2575 + if ( $custom_theme === $file_name ) {
2576 + $_select = 'selected';
2577 + }
2578 + echo '<option value="' . esc_attr( $file_name ) . '" ' . esc_attr( $_select ) . '>' . esc_html( $theme ) . '</option>';
2579 + }
2580 + ?>
2581 + </select>
2582 + </div>
2583 + </div>
2584 + <?php
2585 + }
2586 +
2587 + /**
2588 + * Get custom themes files.
2589 + */
2590 + public function get_custom_themes_files() {
2591 + // get themes files.
2592 + $dirs = $this->get_custom_theme_folder();
2593 + $scan_dir = $dirs[0];
2594 + $handle = opendir( $scan_dir );
2595 + $themes = array();
2596 + if ( $handle ) {
2597 + $filename = readdir( $handle );
2598 + while ( false !== $filename ) {
2599 + $correct_file = true;
2600 + if ( '.' === substr( $filename, 0, 1 ) || 'index.php' === $filename || '.css' !== substr( $filename, - 4 ) ) {
2601 + $correct_file = false;
2602 + }
2603 + if ( $correct_file ) {
2604 + $theme = basename( $filename, '.css' );
2605 + $theme = str_replace( '-theme', '', $theme );
2606 + $themes[ $filename ] = trim( $theme );
2607 + }
2608 + $filename = readdir( $handle ); // to while loop.
2609 + }
2610 + closedir( $handle );
2611 + }
2612 + return $themes;
2613 + }
2614 +
2615 + /**
2616 + * Get selected MainWP theme name.
2617 + */
2618 + public function get_selected_theme() {
2619 + $selected_theme = false;
2620 +
2621 + $custom_theme = $this->get_current_user_theme();
2622 +
2623 + if ( false === $custom_theme ) {
2624 + // to compatible with Custom Dashboard extension settings.
2625 + $compat_settings = get_option( 'mainwp_custom_dashboard_settings' );
2626 + if ( is_array( $compat_settings ) && isset( $compat_settings['theme'] ) ) {
2627 + $compat_theme = $compat_settings['theme'];
2628 + }
2629 +
2630 + if ( null !== $compat_theme ) {
2631 + $custom_theme = $compat_theme;
2632 + }
2633 + }
2634 +
2635 + if ( ! empty( $custom_theme ) ) {
2636 + if ( 'default' === $custom_theme || 'default-dark' === $custom_theme || 'default-2024' === $custom_theme || 'dark' === $custom_theme || 'wpadmin' === $custom_theme || 'minimalistic' === $custom_theme ) {
2637 + return $custom_theme;
2638 + }
2639 + $dirs = $this->get_custom_theme_folder();
2640 + $theme_dir = $dirs[0];
2641 + $file = $theme_dir . $custom_theme;
2642 + if ( file_exists( $file ) && '.css' === substr( $file, - 4 ) ) {
2643 + $selected_theme = $custom_theme;
2644 + }
2645 + }
2646 + return $selected_theme;
2647 + }
2648 +
2649 +
2650 + /**
2651 + * Get custom MainWP theme folder.
2652 + */
2653 + public function get_custom_theme_folder() {
2654 + $dirs = MainWP_System_Utility::get_mainwp_dir();
2655 + global $wp_filesystem;
2656 + if ( is_array( $dirs ) && ! $wp_filesystem->exists( $dirs[0] . 'themes' ) && $wp_filesystem->exists( $dirs[0] . 'custom-dashboard' ) ) {
2657 + // re-name the custom-dashboard folder to compatible.
2658 + $wp_filesystem->move( $dirs[0] . 'custom-dashboard', $dirs[0] . 'themes' );
2659 + }
2660 + return MainWP_System_Utility::get_mainwp_dir_allow_access( 'themes' );
2661 + }
2662 +
2663 +
2664 + /**
2665 + * Get current user's selected theme.
2666 + */
2667 + public function get_current_user_theme() {
2668 + $custom_theme = get_user_option( 'mainwp_selected_theme' );
2669 + if ( empty( $custom_theme ) ) {
2670 + $custom_theme = get_option( 'mainwp_selected_theme', 'default' );
2671 + }
2672 + return $custom_theme;
2673 + }
2674 +
2675 + /**
2676 + * Export Child Sites and save as .csv file.
2677 + *
2678 + * @uses \MainWP\Dashboard\MainWP_DB::query()
2679 + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
2680 + * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
2681 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
2682 + * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
2683 + */
2684 + public static function export_sites() {
2685 + if ( isset( $_GET['doExportSites'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'export_sites' ) ) {
2686 +
2687 + $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( true );
2688 + $websites = MainWP_DB::instance()->query( $sql );
2689 +
2690 + if ( ! $websites ) {
2691 + die( 'Not found sites' );
2692 + }
2693 +
2694 + $keys = array( 'name', 'url', 'adminname', 'adminpasswd', 'wpgroups', 'uniqueId', 'http_user', 'http_pass', 'verify_certificate', 'ssl_version' );
2695 + $allowedHeaders = array( 'site name', 'url', 'admin name', 'admin password', 'tag', 'security id', 'http username', 'http password', 'verify certificate', 'ssl version' );
2696 + $csv = "#\r";
2697 + $csv .= '# Your password is never stored by your Dashboard and never sent to MainWP.com. Once this initial connection is complete, your MainWP Dashboard generates a secure Public and Private key pair (2048 bits) using OpenSSL, allowing future connections without needing your password again. For added security, you can even change this admin password once connected, just be sure not to delete the admin account, as this would disrupt the connection.' . "\r";
2698 + $csv .= "#\r";
2699 + $csv .= implode( ',', $allowedHeaders ) . "\r";
2700 + MainWP_DB::data_seek( $websites, 0 );
2701 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
2702 + if ( empty( $website ) ) {
2703 + continue;
2704 + }
2705 + $row = MainWP_Utility::map_site( $website, $keys, false );
2706 + // MWP-1548: decrypt http_user / http_pass before they hit
2707 + // the CSV. The export file is meant for cross-install
2708 + // transfer (admin re-imports on another dashboard); a
2709 + // file_key envelope from this install would be unreadable
2710 + // there. Plaintext on disk preserves today's portability
2711 + // contract -- the export was already plaintext pre-fix,
2712 + // and this hop neither widens nor narrows that exposure.
2713 + if ( isset( $row['http_user'] ) ) {
2714 + $row['http_user'] = MainWP_Credential_Storage::decrypt_credential( $row['http_user'] );
2715 + }
2716 + if ( isset( $row['http_pass'] ) ) {
2717 + $row['http_pass'] = MainWP_Credential_Storage::decrypt_credential( $row['http_pass'] );
2718 + }
2719 +
2720 + $row = array_map(
2721 + static function ( $value ) {
2722 + return str_replace( '"', '""', (string) $value );
2723 + },
2724 + $row
2725 + );
2726 +
2727 + $csv .= '"' . implode( '","', $row ) . '"' . "\r";
2728 + }
2729 +
2730 + header( 'Content-Type: text/csv; charset=utf-8' );
2731 + header( 'Content-Disposition: attachment; filename=export-sites.csv' );
2732 + echo $csv; // phpcs:ignore WordPress.Security.EscapeOutput
2733 + exit();
2734 + }
2735 + }
2736 +
2737 + /**
2738 + * Render MainWP Email Settings SubPage.
2739 + *
2740 + * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_notification_types()
2741 + * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_edit_settings()
2742 + * @uses \MainWP\Dashboard\MainWP_Notification_Settings::emails_general_settings_handle()
2743 + * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_all_settings()
2744 + * @uses \MainWP\Dashboard\MainWP_Notification_Template::handle_template_file_action()
2745 + */
2746 + public static function render_email_settings() {
2747 + $notification_emails = MainWP_Notification_Settings::get_notification_types();
2748 + static::render_header( 'Emails' );
2749 + $edit_email = isset( $_GET['edit-email'] ) ? sanitize_text_field( wp_unslash( $_GET['edit-email'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2750 + if ( ! empty( $edit_email ) && isset( $notification_emails[ $edit_email ] ) ) {
2751 + $updated_templ = MainWP_Notification_Template::instance()->handle_template_file_action();
2752 + MainWP_Notification_Settings::instance()->render_edit_settings( $edit_email, $updated_templ );
2753 + } else {
2754 + $updated = MainWP_Notification_Settings::emails_general_settings_handle();
2755 + MainWP_Notification_Settings::instance()->render_all_settings( $updated );
2756 + }
2757 + static::render_footer( 'Emails' );
2758 + }
2759 +
2760 + /**
2761 + * Method mainwp_help_content()
2762 + *
2763 + * Creates the MainWP Help Documentation List for the help component in the sidebar.
2764 + */
2765 + public static function mainwp_help_content() {
2766 + if ( isset( $_GET['page'] ) && ( 'Settings' === $_GET['page'] || 'SettingsAdvanced' === $_GET['page'] || 'MainWPTools' === $_GET['page'] || 'MonitoringSettings' === $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2767 + ?>
2768 + <p><?php esc_html_e( 'If you need help with your MainWP Dashboard settings, please review following help documents', 'mainwp' ); ?></p>
2769 + <div class="ui list">
2770 + <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/sites/management/mainwp-dashboard-settings#mainwp-dashboard-settings" target="_blank">MainWP Dashboard Settings</a></div>
2771 + </div>
2772 + <?php
2773 + /**
2774 + * Action: mainwp_settings_help_item
2775 + *
2776 + * Fires at the bottom of the help articles list in the Help sidebar on the Settings page.
2777 + *
2778 + * Suggested HTML markup:
2779 + *
2780 + * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2781 + *
2782 + * @since 5.2
2783 + */
2784 + do_action( 'mainwp_settings_help_item' );
2785 +
2786 + }
2787 + }
2788 +
2789 + /**
2790 + * Method render_monitoring()
2791 + *
2792 + * Render Monitoring Settings.
2793 + *
2794 + * @uses \MainWP\Dashboard\MainWP_Monitoring_View::render_settings()
2795 + */
2796 + public static function render_monitoring() {
2797 + if ( ! \mainwp_current_user_can( 'dashboard', 'manage_dashboard_settings' ) ) {
2798 + \mainwp_do_not_have_permissions( esc_html__( 'manage dashboard settings', 'mainwp' ) );
2799 + return;
2800 + }
2801 + static::render_header( 'Monitoring' );
2802 + ?>
2803 + <div id="mainwp-monitoring-settings" class="ui padded segment">
2804 + <?php if ( isset( $_GET['message'] ) && 'saved' === sanitize_text_field( wp_unslash( $_GET['message'] ) ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
2805 + <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'Monitoring settings have been saved successfully!', 'mainwp' ); ?></div>
2806 + <?php endif; ?>
2807 + <div class="ui form">
2808 + <form method="POST" action="">
2809 + <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
2810 + <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'MonitoringSettings' ) ); ?>" />
2811 + <?php
2812 + /**
2813 + * Action: mainwp_monitoring_settings_form_top
2814 + *
2815 + * Fires at the top of monitoring settings form.
2816 + *
2817 + * @since 4.1
2818 + */
2819 + do_action( 'mainwp_monitoring_settings_form_top' );
2820 + ?>
2821 + <?php MainWP_Monitoring_View::render_settings(); ?>
2822 + <?php
2823 + /**
2824 + * Action: mainwp_monitoring_form_bottom
2825 + *
2826 + * Fires at the bottom of mainwp monitoring form.
2827 + *
2828 + * @since 4.1
2829 + */
2830 + do_action( 'mainwp_monitoring_settings_form_bottom' );
2831 + ?>
2832 + <div class="ui divider"></div>
2833 + <input type="submit" name="submit" id="submit-monitoring" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
2834 + </form>
2835 + </div>
2836 + </div>
2837 + <?php
2838 + static::render_footer( 'Monitoring' );
2839 + }
1659 2840 }