PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
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
mainwp / class / class-mainwp-manage-sites-view.php

class-mainwp-manage-sites-view.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.1, at class/class-mainwp-manage-sites-view.php

2,645 lines 157.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Manage Sites View.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Manage_Sites_View
17 *
18 * @package MainWP\Dashboard
19 */
20 class MainWP_Manage_Sites_View { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
21
22 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
23 /**
24 * Method init_menu()
25 *
26 * Initiate Sites sub menu.
27 *
28 * @return add_submenu_page()
29 *
30 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::get_class_name()
31 */
32 public static function init_menu() {
33 return add_submenu_page(
34 'mainwp_tab',
35 __( 'Sites', 'mainwp' ),
36 '<span id="mainwp-Sites">' . esc_html__( 'Sites', 'mainwp' ) . '</span>',
37 'read',
38 'managesites',
39 array( MainWP_Manage_Sites::get_class_name(), 'render_manage_sites' )
40 );
41 }
42
43 /**
44 * Method init_subpages_menu()
45 *
46 * @param array $subPages Sub pages array.
47 *
48 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
49 */
50 public static function init_subpages_menu( &$subPages ) { // phpcs:ignore -- NOSONAR - complex.
51 ?>
52 <div id="menu-mainwp-Sites" class="mainwp-submenu-wrapper">
53 <div class="wp-submenu sub-open" style="">
54 <div class="mainwp_boxout">
55 <div class="mainwp_boxoutin"></div>
56 <a href="<?php echo esc_url( admin_url( MainWP_Unhooks_Helper::add_unhooks_params( 'admin.php?page=managesites' ) ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Manage Sites', 'mainwp' ); ?></a>
57 <?php if ( \mainwp_current_user_can( 'dashboard', 'add_sites' ) ) { ?>
58 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'managesites_add_new' ) ) { ?>
59 <a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&do=new' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Add New', 'mainwp' ); ?></a>
60 <?php } ?>
61 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'managesites_import' ) ) { ?>
62 <a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&do=bulknew' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Import Sites', 'mainwp' ); ?></a>
63 <?php } ?>
64 <?php } ?>
65 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MonitoringSites' ) ) { ?>
66 <a href="<?php echo esc_url( admin_url( 'admin.php?page=MonitoringSites' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Monitoring', 'mainwp' ); ?></a>
67 <?php } ?>
68 <?php
69 if ( isset( $subPages ) && is_array( $subPages ) ) {
70 foreach ( $subPages as $subPage ) {
71 if ( ! isset( $subPage['menu_hidden'] ) || ( isset( $subPage['menu_hidden'] ) && true !== $subPage['menu_hidden'] ) ) {
72 $sub_slug = isset( $subPage['slug'] ) ? $subPage['slug'] : '';
73 $sub_title = isset( $subPage['title'] ) ? $subPage['title'] : '';
74 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageSites' . $sub_slug ) ) {
75 continue;
76 }
77 ?>
78 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ManageSites' . $sub_slug ) ); ?>" class="mainwp-submenu"><?php echo esc_html( $sub_title ); ?></a>
79 <?php
80 }
81 }
82 }
83 ?>
84 </div>
85 </div>
86 </div>
87 <?php
88 }
89
90 /**
91 * Method init_left_menu()
92 *
93 * Initiate left Sites menu.
94 *
95 * @param array $subPages Sub pages array.
96 *
97 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
98 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
99 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
100 */
101 public static function init_left_menu( $subPages = array() ) {
102
103 MainWP_Menu::add_left_menu(
104 array(
105 'title' => esc_html__( 'Sites', 'mainwp' ),
106 'parent_key' => 'mainwp_tab',
107 'slug' => 'managesites',
108 'href' => MainWP_Unhooks_Helper::add_unhooks_params( 'admin.php?page=managesites' ),
109 'icon' => '<i class="globe icon"></i>',
110 ),
111 0
112 );
113
114 $items_menu = array(
115 array(
116 'title' => esc_html__( 'Manage Sites', 'mainwp' ),
117 'parent_key' => 'managesites',
118 'slug' => 'managesites',
119 'href' => MainWP_Unhooks_Helper::add_unhooks_params( 'admin.php?page=managesites' ),
120 'right' => '',
121 'leftsub_order_level2' => 1,
122 'id' => 'managesites-root',
123 ),
124 array(
125 'title' => esc_html__( 'Add New', 'mainwp' ),
126 'parent_key' => 'managesites',
127 'href' => 'admin.php?page=managesites&do=new',
128 'slug' => 'managesites',
129 'right' => 'add_sites',
130 'item_slug' => 'managesites_add_new',
131 'id' => 'managesites-addnew',
132 'leftsub_order_level2' => 2,
133 ),
134 );
135
136 MainWP_Menu::init_subpages_left_menu( $subPages, $items_menu, 'managesites', 'ManageSites' );
137
138 foreach ( $items_menu as $item ) {
139 if ( isset( $item['item_slug'] ) ) {
140 if ( MainWP_Menu::is_disable_menu_item( 3, $item['item_slug'] ) ) {
141 continue;
142 }
143 } elseif ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
144 continue;
145 }
146 MainWP_Menu::add_left_menu( $item, 2 );
147 }
148 }
149
150 /**
151 * Method render_header()
152 *
153 * Build Sites page header.
154 *
155 * @param string $shownPage Current Page.
156 * @param array $subPages Sites subpages.
157 *
158 * @uses \MainWP\Dashboard\MainWP_Connect::get_favico_url()
159 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
160 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
161 * @uses \MainWP\Dashboard\MainWP_UI::render_second_top_header()
162 */
163 public static function render_header( $shownPage = '', $subPages = array() ) { // phpcs:ignore -- NOSONAR - complex.
164
165 if ( '' === $shownPage || 'managesites' === $shownPage ) {
166 $shownPage = 'ManageSites';
167 }
168
169 $site_id = 0;
170 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
171 if ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) {
172 $site_id = intval( $_GET['id'] );
173 } elseif ( isset( $_GET['backupid'] ) && ! empty( $_GET['backupid'] ) ) {
174 $site_id = intval( $_GET['backupid'] );
175 } elseif ( isset( $_GET['updateid'] ) && ! empty( $_GET['updateid'] ) ) {
176 $site_id = intval( $_GET['updateid'] );
177 } elseif ( isset( $_GET['dashboard'] ) && ! empty( $_GET['dashboard'] ) ) {
178 $site_id = intval( $_GET['dashboard'] );
179 } elseif ( isset( $_GET['scanid'] ) && ! empty( $_GET['scanid'] ) ) {
180 $site_id = intval( $_GET['scanid'] );
181 } elseif ( isset( $_GET['emailsettingsid'] ) && ! empty( $_GET['emailsettingsid'] ) ) {
182 $site_id = intval( $_GET['emailsettingsid'] );
183 } elseif ( isset( $_GET['cacheControlId'] ) && ! empty( $_GET['cacheControlId'] ) ) {
184 $site_id = intval( $_GET['cacheControlId'] );
185 } elseif ( ! empty( $_GET['monitor_wpid'] ) ) {
186 $site_id = intval( $_GET['monitor_wpid'] );
187 }
188 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
189
190 $managesites_pages = array(
191 'ManageSites' => array(
192 'href' => MainWP_Unhooks_Helper::add_unhooks_params( 'admin.php?page=managesites' ),
193 'title' => esc_html__( 'Manage Sites', 'mainwp' ),
194 'access' => true,
195 ),
196 'AddNew' => array(
197 'href' => 'admin.php?page=managesites&do=new',
198 'title' => esc_html__( 'Add New', 'mainwp' ),
199 'access' => \mainwp_current_user_can( 'dashboard', 'add_sites' ),
200 ),
201 'BulkAddNew' => array(
202 'href' => 'admin.php?page=managesites&do=bulknew',
203 'title' => esc_html__( 'Import Sites', 'mainwp' ),
204 'access' => \mainwp_current_user_can( 'dashboard', 'add_sites' ),
205 ),
206 'MonitoringSites' => array(
207 'href' => 'admin.php?page=MonitoringSites',
208 'title' => esc_html__( 'Monitoring', 'mainwp' ),
209 'access' => true,
210 ),
211 );
212
213 $total_info = MainWP_Manage_Sites_Update_View::get_total_info( $site_id );
214 $total_updates = $total_info['total_upgrades'];
215 $after_title = empty( $total_updates ) ? '' : '<div class="ui tiny green label" timestamp="' . time() . '">' . absint( $total_updates ) . '</div>';
216
217 $site_pages = array(
218 'ManageSitesDashboard' => array(
219 'href' => 'admin.php?page=managesites&dashboard=' . $site_id,
220 'title' => esc_html__( 'Overview', 'mainwp' ),
221 'access' => \mainwp_current_user_can( 'dashboard', 'access_individual_dashboard' ),
222 ),
223 'ManageSitesEdit' => array(
224 'href' => 'admin.php?page=managesites&id=' . $site_id,
225 'title' => esc_html__( 'Settings', 'mainwp' ),
226 'access' => \mainwp_current_user_can( 'dashboard', 'edit_sites' ),
227 ),
228 'ManageSitesUpdates' => array(
229 'href' => 'admin.php?page=managesites&updateid=' . $site_id,
230 'title' => esc_html__( 'Updates', 'mainwp' ),
231 'access' => \mainwp_current_user_can( 'dashboard', 'access_individual_dashboard' ),
232 'after_title' => $after_title,
233 ),
234 'ManageSitesBackups' => array(
235 'href' => 'admin.php?page=managesites&backupid=' . $site_id,
236 'title' => esc_html__( 'Backups', 'mainwp' ),
237 'access' => \mainwp_current_user_can( 'dashboard', 'execute_backups' ),
238 ),
239 'SecurityScan' => array(
240 'href' => 'admin.php?page=managesites&scanid=' . $site_id,
241 'title' => esc_html__( 'Site Hardening', 'mainwp' ),
242 'access' => true,
243 ),
244 );
245
246 /**
247 * MainWP Use External Primary backup Method global.
248 *
249 * @global string
250 */
251 global $mainwpUseExternalPrimaryBackupsMethod;
252
253 if ( ! empty( $mainwpUseExternalPrimaryBackupsMethod ) ) {
254 unset( $site_pages['ManageSitesBackups'] );
255 } elseif ( ! get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
256 if ( isset( $site_pages['ManageSitesBackups'] ) ) {
257 unset( $site_pages['ManageSitesBackups'] );
258 }
259 }
260
261 $pagetitle = esc_html__( 'Sites', 'mainwp' );
262
263 if ( ! empty( $site_id ) ) {
264 $website = MainWP_DB::instance()->get_website_by_id( $site_id );
265 if ( $website ) {
266 $reconnect = '';
267 if ( $site_id && $website && '' !== $website->sync_errors ) {
268 $reconnect = '<a href="#" class="mainwp-updates-overview-reconnect-site item" adminuser="' . esc_attr( $website->adminname ) . '" siteid="' . intval( $site_id ) . '"><i class="sync alternate icon"></i> Reconnect</a>';
269 }
270 $wp_admin_href = MainWP_Site_Open::get_open_site_url( $site_id, false, false );
271 $dropdown = $reconnect . '
272 <a class="item mainwp-remove-site-button" site-id="' . intval( $site_id ) . '" id="mainwp-remove-site-button" href="#"><i class="trash grey icon"></i> Remove Site</a>
273 <a id="mainwp-go-wp-admin-button" target="_blank" href="' . $wp_admin_href . '" class="item open_newwindow_wpadmin"><i class="sign in grey icon"></i> Go to WP Admin</a>
274 ';
275 $site_icon = '';
276 if ( 1 === (int) get_option( 'mainwp_use_favicon', 1 ) ) {
277 $favi_url = MainWP_Connect::get_favico_url( $website );
278 $site_icon = MainWP_Manage_Sites::get_instance()->get_site_icon_display( $website->cust_site_icon_info, $favi_url );
279 }
280 $pagetitle = $site_icon . '<div class="content"><a href="' . esc_url( MainWP_Site_Open::get_open_site_url( $website->id, '', false ) ) . '" target="_blank" class="open_newwindow_wpadmin" rel="noopener noreferrer" style="font-weight:normal!important;"><i class="sign in grey icon" style="font-weight:normal!important;"></i></a><div class="ui pointing dropdown"><div class="text">' . esc_html( $website->name ) . '</div><i class="dropdown icon"></i><div class="menu">' . $dropdown . '</div></div><div class="sub header"><a href="' . esc_url( $website->url ) . '" target="_blank" style="font-size:10px" class="ui grey text" rel="noopener noreferrer">' . esc_html( MainWP_Utility::get_nice_url( $website->url ) ) . '</a></div></div>';
281 $site_pages['JumpToWPAdmin'] = array(
282 'href' => $wp_admin_href,
283 'title' => esc_html__( 'Go to WP Admin', 'mainwp' ),
284 'access' => true,
285 'class' => 'open_newwindow_wpadmin',
286 'target' => '_blank',
287 'rel' => 'noopener noreferrer',
288 );
289 }
290 }
291
292 $params = array(
293 'title' => $pagetitle,
294 );
295
296 MainWP_UI::render_top_header( $params );
297
298 $manage_sites = false;
299 if ( 'ManageSites' === $shownPage || 'MonitoringSites' === $shownPage ) {
300 $manage_sites = true;
301 }
302
303 static::render_managesites_header( $site_pages, $managesites_pages, $subPages, $site_id, $shownPage );
304
305 if ( $manage_sites ) {
306 $count = MainWP_DB::instance()->get_websites_count( null, false );
307 if ( ! empty( $count ) ) {
308 $which = strtolower( $shownPage );
309 MainWP_UI::render_second_top_header( $which );
310 }
311 }
312
313 if ( ! empty( $site_id ) ) {
314 MainWP_UI::render_modal_reconnect();
315 }
316 }
317
318 /**
319 * Method render_footer()
320 *
321 * Close the page container.
322 */
323 public static function render_footer() {
324 echo '</div>';
325 }
326
327 /**
328 * Method render_managesites_header()
329 *
330 * Render manage sites header.
331 *
332 * @param array $site_pages site pages.
333 * @param array $managesites_pages manage site pages.
334 * @param array $subPages sub pages.
335 * @param int $site_id Site id.
336 * @param string $shownPage Current Page.
337 *
338 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
339 * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation()
340 */
341 private static function render_managesites_header( $site_pages, $managesites_pages, $subPages, $site_id, $shownPage ) { //phpcs:ignore -- NOSONAR - complex method.
342
343 $renderItems = array();
344 if ( isset( $managesites_pages[ $shownPage ] ) ) {
345 foreach ( $managesites_pages as $page => $value ) {
346 if ( MainWP_Menu::is_disable_menu_item( 3, $page ) ) {
347 continue;
348 }
349
350 $item = $value;
351 $item['active'] = ( $page === $shownPage ) ? true : false;
352 $renderItems[] = $item;
353 }
354 } elseif ( $site_id ) {
355 foreach ( $site_pages as $page => $value ) {
356 if ( MainWP_Menu::is_disable_menu_item( 3, $page ) ) {
357 continue;
358 }
359 $item = $value;
360 $item['active'] = ( $page === $shownPage ) ? true : false;
361 $renderItems[] = $item;
362 }
363 }
364
365 if ( isset( $subPages ) && is_array( $subPages ) ) {
366 foreach ( $subPages as $subPage ) {
367 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageSites' . $subPage['slug'] ) ) {
368 continue;
369 }
370
371 if ( isset( $subPage['sitetab'] ) && true === $subPage['sitetab'] && empty( $site_id ) ) {
372 continue;
373 }
374 $item = array();
375 $item['title'] = isset( $subPage['title'] ) ? $subPage['title'] : '';
376 $sub_slug = isset( $subPage['slug'] ) ? $subPage['slug'] : '';
377
378 if ( ! empty( $subPage['href'] ) ) {
379 $item['href'] = $subPage['href'];
380 } else {
381 $item['href'] = 'admin.php?page=ManageSites' . $sub_slug . ( $site_id ? '&id=' . esc_attr( $site_id ) : '' );
382 }
383 $item['active'] = ( $sub_slug === $shownPage ) ? true : false;
384 $renderItems[] = $item;
385 }
386 }
387 $renderItems = apply_filters( 'mainwp_manage_sites_navigation_items', $renderItems, $site_id, $shownPage );
388 MainWP_UI::render_page_navigation( $renderItems );
389 }
390
391 /**
392 * Method render_import_sites()
393 *
394 * Render import sites dialog.
395 *
396 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system()
397 * @uses \MainWP\Dashboard\MainWP_Utility::starts_with()
398 */
399 public static function render_import_sites() { // phpcs:ignore -- NOSONAR - complex.
400 ?>
401 <div id="mainwp-importing-sites" class="ui active dimmer">
402 <div class="ui double text loader"><?php esc_html_e( 'Importing...', 'mainwp' ); ?></div>
403 </div>
404 <div class="ui message" id="mainwp-import-sites-status-message">
405 <?php echo '<i class="notched circle loading icon"></i> ' . esc_html__( 'Importing...', 'mainwp' ); ?>
406 </div>
407 <?php
408 $errors = array();
409 //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended
410 if ( isset( $_FILES['mainwp_managesites_file_bulkupload']['error'] ) && UPLOAD_ERR_OK === $_FILES['mainwp_managesites_file_bulkupload']['error'] && check_admin_referer( 'mainwp-admin-nonce' ) ) {
411 if ( isset( $_FILES['mainwp_managesites_file_bulkupload']['tmp_name'] ) && is_uploaded_file( $_FILES['mainwp_managesites_file_bulkupload']['tmp_name'] ) ) {
412 $tmp_path = $_FILES['mainwp_managesites_file_bulkupload']['tmp_name'];
413
414 $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system();
415 //phpcs:enable
416 /**
417 * WordPress files system object.
418 *
419 * @global object
420 */
421 global $wp_filesystem;
422
423 $lines = array();
424 if ( $hasWPFileSystem && ! empty( $wp_filesystem ) ) {
425 $content = $wp_filesystem->get_contents( $tmp_path );
426 if ( ! empty( $content ) ) {
427 // to compatible with EOL on OSs.
428 $content = str_replace( "\r\n", "\r", $content );
429 $content = str_replace( "\n", "\r", $content );
430 $lines = explode( "\r", $content );
431 }
432 } else {
433 ?>
434 <div class="error below-h2">
435 <p><strong><?php esc_html_e( 'Error', 'mainwp' ); ?></strong>: <?php esc_html_e( 'Unable to initialize the WordPress filesystem. Please try again.', 'mainwp' ); ?></p>
436 </div>
437 <?php
438 return;
439 }
440
441 $default_values = array(
442 'name' => '',
443 'url' => '',
444 'adminname' => '',
445 'adminpwd' => '',
446 'wpgroups' => '',
447 'uniqueId' => '',
448 'http_user' => '',
449 'http_pass' => '',
450 'verify_certificate' => 1,
451 'ssl_version' => 'auto',
452 );
453
454 if ( is_array( $lines ) && ( ! empty( $lines ) ) ) {
455 $row = 0;
456 $header_line = null;
457
458 foreach ( $lines as $originalLine ) {
459
460 $line = trim( $originalLine );
461
462 if ( MainWP_Utility::starts_with( $line, '#' ) ) {
463 continue;
464 }
465
466 $items = str_getcsv( $line, ',' );
467
468 if ( ( null === $header_line ) && ! empty( $_POST['mainwp_managesites_chk_header_first'] ) ) {
469 $header_line = sanitize_text_field( $line ) . "\r";
470 continue;
471 }
472
473 if ( 10 > count( $items ) ) {
474 continue;
475 }
476
477 $x = 0;
478 foreach ( $default_values as $field => $val ) {
479 $value = isset( $items[ $x ] ) ? $items[ $x ] : $val;
480
481 if ( 'verify_certificate' === $field ) {
482 if ( 'T' === $value ) {
483 $value = '1';
484 } elseif ( 'Y' === $value ) {
485 $value = '0';
486 }
487 }
488
489 $import_data[ $field ] = sanitize_text_field( wp_unslash( $value ) );
490 ++$x;
491 }
492 $encoded = wp_json_encode( $import_data );
493 ?>
494 <input type="hidden" id="mainwp_managesites_import_csv_line_<?php echo esc_attr( $row + 1 ); ?>" value="" encoded-data="<?php echo esc_attr( $encoded ); ?>" original="<?php echo esc_attr( sanitize_text_field( $originalLine ) ); ?>" />
495 <?php
496 ++$row;
497 }
498 $header_line = trim( $header_line );
499 ?>
500 <input type="hidden" id="mainwp_managesites_do_import" value="1"/>
501 <input type="hidden" id="mainwp_managesites_total_import" value="<?php echo esc_attr( $row ); ?>"/>
502 <div class="mainwp_managesites_import_listing" id="mainwp_managesites_import_logging">
503 <span class="log ui medium text"><?php echo esc_html( $header_line ) . '<br/>'; ?></span>
504 </div>
505 <div class="mainwp_managesites_import_listing" id="mainwp_managesites_import_fail_logging" style="display: none;">
506 <?php
507 echo esc_html( $header_line );
508 ?>
509 </div>
510
511 <?php
512 } else {
513 $errors[] = esc_html__( 'Invalid data. Please, review the import file.', 'mainwp' ) . '<br />';
514 }
515 } else {
516 $errors[] = esc_html__( 'Upload failed. Please, try again.', 'mainwp' ) . '<br />';
517 }
518 } elseif ( ! empty( $_POST['mainwp_managesites_import'] ) && check_admin_referer( 'mainwp-admin-nonce' ) ) {
519 // Set site data by POST value.
520 $sites_data = ! empty( $_POST['mainwp_managesites_import'] ) ? wp_unslash( $_POST['mainwp_managesites_import'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
521 if ( ! empty( $sites_data ) ) {
522 $import_data = array(); // Create default import data.
523 // Map data sites data to import_data.
524 foreach ( $sites_data as $site ) {
525 // Break site if site_url and admin_name empty.
526 if ( empty( $site['site_url'] ) && empty( $site['admin_name'] ) ) {
527 continue;
528 }
529 // Map POST data to import data.
530 $import_data[] = array(
531 'name' => ! empty( $site['site_name'] ) ? sanitize_text_field( wp_unslash( $site['site_name'] ) ) : '',
532 'url' => ! empty( $site['site_url'] ) ? sanitize_text_field( wp_unslash( $site['site_url'] ) ) : '',
533 'adminname' => ! empty( $site['admin_name'] ) ? sanitize_text_field( wp_unslash( $site['admin_name'] ) ) : '',
534 'adminpwd' => ! empty( $site['admin_password'] ) ? wp_unslash( $site['admin_password'] ) : '',
535 'wpgroups' => ! empty( $site['tag'] ) ? sanitize_text_field( wp_unslash( $site['tag'] ) ) : '',
536 'uniqueId' => ! empty( $site['security_id'] ) ? sanitize_text_field( wp_unslash( $site['security_id'] ) ) : '',
537 'http_user' => ! empty( $site['http_username'] ) ? sanitize_text_field( wp_unslash( $site['http_username'] ) ) : '',
538 'http_pass' => ! empty( $site['http_password'] ) ? wp_unslash( $site['http_password'] ) : '',
539 'verify_certificate' => isset( $site['verify_certificate'] ) ? intval( $site['verify_certificate'] ) : 1,
540 'ssl_version' => ! empty( $site['ssl_version'] ) ? sanitize_text_field( wp_unslash( $site['ssl_version'] ) ) : 'auto',
541 );
542
543 }
544 // Import website if import data is not empty.
545 if ( ! empty( $import_data ) ) {
546 $header_line = trim( 'Site Name, Url, Admin Name, Tag,Security ID,HTTP Username,HTTP Password,Verify Certificate,SSL Version' ); // Set Header Line.
547 // Map import data to input html.
548 foreach ( $import_data as $key_import => $val_import ) {
549 $line = trim( implode( ',', $val_import ) )
550 ?>
551 <input type="hidden" id="mainwp_managesites_import_csv_line_<?php echo esc_attr( $key_import + 1 ); ?>" value="" encoded-data="<?php echo esc_attr( wp_json_encode( $val_import ) ); ?>" original="<?php echo esc_attr( $line ); ?>" />
552 <?php
553 }
554 $hd_id1 = 'mainwp_managesites_do_import';
555 $hd_id2 = 'mainwp_managesites_total_import';
556 $list_id = 'mainwp_managesites_import_logging';
557 $fail_list_id = 'mainwp_managesites_import_fail_logging';
558 ?>
559 <input type="hidden" id="mainwp_managesites_do_managesites_import" value="1"/>
560 <input type="hidden" id="<?php echo esc_attr( $hd_id1 ); ?>" value="1"/>
561 <input type="hidden" id="<?php echo esc_attr( $hd_id2 ); ?>" value="<?php echo esc_attr( count( $import_data ) ); ?>"/>
562
563 <div class="mainwp_managesites_import_listing" id="<?php echo esc_attr( $list_id ); ?>">
564 <span class="log ui small text">
565 <?php echo esc_html( $header_line ) . '<br/>'; ?>
566 </span>
567 </div>
568 <div class="mainwp_managesites_import_listing" id="<?php echo esc_attr( $fail_list_id ); ?>" style="display: none;">
569 <?php echo esc_html( $header_line ); ?>
570 </div>
571 <?php
572 } else {
573 $errors[] = esc_html__( 'An error occurred. Please, try again.', 'mainwp' ) . '<br />';
574 }
575 } else {
576 $errors[] = esc_html__( 'Import failed. Please, try again.', 'mainwp' ) . '<br />';
577 }
578 } else {
579 $errors[] = esc_html__( 'Import failed. Please, try again.', 'mainwp' ) . '<br />';
580 }
581
582 if ( ! empty( $errors ) ) {
583 ?>
584 <div class="error below-h2">
585 <?php
586 foreach ( $errors as $error ) {
587 ?>
588 <p><strong><?php esc_html_e( 'Error', 'mainwp' ); ?></strong>: <?php echo esc_html( $error ); ?></p>
589 <?php } ?>
590 </div>
591 <?php
592 }
593 }
594
595 /**
596 * Method render_sync_exts_settings()
597 *
598 * Render sync extension settings.
599 *
600 * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions()
601 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor()
602 */
603 public static function render_sync_exts_settings() { // phpcs:ignore -- NOSONAR - complex.
604 $sync_extensions_options = apply_filters_deprecated( 'mainwp-sync-extensions-options', array( array() ), '4.0.7.2', 'mainwp_sync_extensions_options' ); // @deprecated Use 'mainwp_sync_extensions_options' instead. NOSONAR - not IP.
605 $sync_extensions_options = apply_filters( 'mainwp_sync_extensions_options', $sync_extensions_options );
606
607 $working_extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor();
608 if ( ! empty( $working_extensions ) && ! empty( $sync_extensions_options ) ) {
609 ?>
610
611 <h3 class="ui dividing header">
612 <?php esc_html_e( 'Add-ons Settings Synchronization', 'mainwp' ); ?>
613 <div class="sub header"><?php esc_html_e( 'Select the plugins you want to install and if you want to apply the Add-ons default settings to this Child site.', 'mainwp' ); ?></div>
614 </h3>
615
616 <?php
617 $loader = '<i class="ui active inline loader tiny" style="display: none"></i> <span class="status"></span>';
618 foreach ( $working_extensions as $slug => $data ) {
619 $dir_slug = dirname( $slug );
620
621 if ( ! isset( $sync_extensions_options[ $dir_slug ] ) ) {
622 continue;
623 }
624
625 $sync_info = isset( $sync_extensions_options[ $dir_slug ] ) ? $sync_extensions_options[ $dir_slug ] : array();
626 $ext_name = MainWP_Extensions_Handler::polish_string_name( $data['name'] );
627 $ext_name = esc_html( $ext_name );
628
629 $html = '<div class="ui grid field">';
630 $html .= '<div class="sync-ext-row" slug="' . $dir_slug . '" ext_name = "' . esc_attr( $ext_name ) . '"status="queue">';
631 $html .= '<h4>' . $ext_name . '</h4>';
632 if ( isset( $sync_info['plugin_slug'] ) && ! empty( $sync_info['plugin_slug'] ) ) {
633 $html .= '<div class="sync-install-plugin" slug="' . esc_attr( dirname( $sync_info['plugin_slug'] ) ) . '" plugin_name="' . esc_attr( $sync_info['plugin_name'] ) . '">';
634 /* translators: 1: Plugin name. */
635 $html .= '<div class="ui checkbox"><input type="checkbox" class="chk-sync-install-plugin" /> <label>' . esc_html( sprintf( esc_html__( 'Install %1$s plugin', 'mainwp' ), esc_html( $sync_info['plugin_name'] ) ) ) . '</label></div> ';
636 $html .= $loader;
637 $html .= '</div>';
638 if ( ! isset( $sync_info['no_setting'] ) || empty( $sync_info['no_setting'] ) ) {
639 $html .= '<div class="sync-options options-row">';
640 $html .= '<div class="ui checkbox"><input type="checkbox" /><label> ';
641 /* translators: 1: Plugin name, 2: Opening anchor tag, 3: Closing anchor tag. */
642 $html .= sprintf( esc_html__( 'Apply %1$s %2$ssettings%3$s', 'mainwp' ), esc_html( $sync_info['plugin_name'] ), '<a href="admin.php?page=' . $data['page'] . '">', '</a>' );
643 $html .= '</label>';
644 $html .= '</div> ';
645 $html .= $loader;
646 $html .= '</div>';
647 }
648 if ( ! empty( $sync_info['action_after_install'] ) ) {
649 $html .= '<div class="sync-options options-row">';
650 $html .= '<div class="ui checkbox"><input type="checkbox" /><label> ';
651 $html .= esc_html( $sync_info['action_after_install'] );
652 $html .= '</label>';
653 $html .= '</div> ';
654 $html .= $loader;
655 $html .= '</div>';
656 }
657 } else {
658 $html .= '<div class="sync-global-options options-row">';
659 /* translators: 1: Extension name. */
660 $html .= '<div class="ui checkbox"><input type="checkbox" /> <label>' . esc_html( sprintf( esc_html__( 'Apply global %1$s options', 'mainwp' ), trim( $ext_name ) ) ) . '</label></div> ';
661 $html .= '<i class="ui active inline loader tiny" style="display: none"></i> <span class="status"></span>';
662 $html .= '</div>';
663 }
664 $html .= '</div>';
665 $html .= '</div>';
666
667 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput
668 }
669 }
670 }
671
672 /**
673 * Method render_dashboard()
674 *
675 * Render individual Child Site Operations page.
676 *
677 * @param mixed $website Child Site.
678 *
679 * @return string Sites Operations Page.
680 *
681 * @uses \MainWP\Dashboard\MainWP_Overview::render_dashboard_body()
682 */
683 public static function render_dashboard( &$website ) {
684 if ( ! \mainwp_current_user_can( 'dashboard', 'access_individual_dashboard' ) ) {
685 \mainwp_do_not_have_permissions( esc_html__( 'individual dashboard', 'mainwp' ) );
686 return;
687 }
688 ?>
689 <div>
690 <?php
691 if ( -1 === (int) $website->mainwpdir ) {
692 echo '<div class="ui yellow message"><span class="mainwp_conflict" siteid="' . intval( $website->id ) . '"><strong>Configuration issue detected</strong>: MainWP has no write privileges to the uploads directory. Because of this some of the functionality might not work.</span></div>';
693 }
694
695 /**
696 * Screen layout columns global.
697 *
698 * @global string
699 */
700 global $screen_layout_columns;
701
702 MainWP_Overview::render_dashboard_body( array( $website ) );
703 ?>
704 </div>
705 <?php
706 }
707
708 /**
709 * Method render_header_tabs()
710 *
711 * Render Sites sub page header tabs.
712 *
713 * @param mixed $active_tab Currently active tab.
714 * @param mixed $active_text Currently active drop down text.
715 * @param mixed $show_language_updates Whether or not to show translations.
716 */
717 public static function render_header_tabs( $active_tab, $active_text, $show_language_updates ) {
718 ?>
719 <div class="mainwp-actions-bar">
720 <div class="ui grid">
721 <div class="equal width row">
722 <div class="middle aligned column">
723 <div class="inline field">
724 <div class="ui selection mini dropdown select-individual-updates">
725 <div class="text"><?php echo esc_html( $active_text ); ?></div>
726 <i class="dropdown icon"></i>
727 <div class="menu">
728 <div class="<?php echo 'wordpress' === $active_tab ? 'active' : ''; ?> item" data-tab="wordpress" data-value="wordpress"><?php esc_html_e( 'WordPress Updates', 'mainwp' ); ?></div>
729 <div class="<?php echo 'plugins' === $active_tab ? 'active' : ''; ?> item" data-tab="plugins" data-value="plugins"><?php esc_html_e( 'Plugin Updates', 'mainwp' ); ?></div>
730 <div class="<?php echo 'themes' === $active_tab ? 'active' : ''; ?> item" data-tab="themes" data-value="themes"><?php esc_html_e( 'Theme Updates', 'mainwp' ); ?></div>
731 <?php if ( $show_language_updates ) { ?>
732 <div class="<?php echo 'trans' === $active_tab ? 'active' : ''; ?> item" data-tab="translations" data-value="translations"><?php esc_html_e( 'Translation Updates', 'mainwp' ); ?></div>
733 <?php } ?>
734 <?php if ( is_plugin_active( 'mainwp-database-updater-extension/mainwp-database-updater-extension.php' ) ) { ?>
735 <div class="item" data-tab="dbupdates" data-value="dbupdates"><?php esc_html_e( 'Database Updates', 'mainwp' ); ?></div>
736 <?php } ?>
737 <div class="<?php echo 'abandoned-plugins' === $active_tab ? 'active' : ''; ?> item" data-tab="abandoned-plugins" data-value="abandoned-plugins"><?php esc_html_e( 'Abandoned Plugins', 'mainwp' ); ?></div>
738 <div class="<?php echo 'abandoned-themes' === $active_tab ? 'active' : ''; ?> item" data-tab="abandoned-themes" data-value="abandoned-themes"><?php esc_html_e( 'Abandoned Themes', 'mainwp' ); ?></div>
739 </div>
740 </div>
741 </div>
742 </div>
743 <div class="middle aligned column">
744 <?php
745 /**
746 * Action: mainwp_widget_updates_actions_top
747 *
748 * Updates actions top content.
749 *
750 * @since 5.5
751 */
752 do_action( 'mainwp_widget_updates_actions_top', $active_tab );
753 ?>
754 </div>
755 <div class="middle aligned right aligned column select-buttons-individual-updates">
756 <?php echo '<a href="javascript:void(0)" data-tooltip="' . esc_html__( 'Update Selected Plugins.', 'mainwp' ) . '" onClick="updatesoverview_plugins_global_upgrade_all( false, true ); return false;" class="ui mini green basic button plugins ' . ( 'plugins' === $active_tab ? '' : 'hidden' ) . '" data-inverted="" data-position="top right">' . esc_html__( 'Update Selected', 'mainwp' ) . '</a>'; ?>
757 <?php echo '<a href="javascript:void(0)" onClick="updatesoverview_themes_global_upgrade_all( false, true );return false;" class="ui mini green basic button themes ' . ( 'themes' === $active_tab ? '' : 'hidden' ) . '" data-tooltip="' . esc_html__( 'Update Selected Themes.', 'mainwp' ) . '" data-inverted="" data-position="top right">' . esc_html__( 'Update Selected', 'mainwp' ) . '</a>'; ?>
758 </div>
759 </div>
760 </div>
761 </div>
762 <?php
763 }
764
765 /**
766 * Method render_scan_site()
767 *
768 * Render Site Hardening sub page.
769 *
770 * @param mixed $website Child Site.
771 *
772 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
773 */
774 public static function render_scan_site( &$website ) {
775 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_security_issues' ) ) {
776 \mainwp_do_not_have_permissions( esc_html__( 'security scan', 'mainwp' ) );
777 return;
778 }
779 ?>
780 <div class="mainwp-actions-bar">
781 <div class="ui one column grid">
782 <div class="column">
783 <input type="button" id="securityIssues_refresh" class="ui mini green button" value="<?php esc_html_e( 'Scan Site', 'mainwp' ); ?>"/>
784 </div>
785 </div>
786 </div>
787 <div class="ui padded segment">
788 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-manage-security-info-message' ) ) { ?>
789 <div class="ui info message">
790 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-manage-security-info-message"></i>
791 <?php esc_html_e( 'Ensure your sites are secure and up to date with automated security and update checks.', 'mainwp' ); // NOSONAR - noopener - open safe. ?>
792 </div>
793 <?php } ?>
794 <?php
795 // Render security check issues.
796 //phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
797 $websiteid = isset( $_GET['scanid'] ) ? intval( $_GET['scanid'] ) : null;
798 //phpcs:enable WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
799
800 $website = MainWP_DB::instance()->get_website_by_id( $websiteid );
801 if ( empty( $website ) ) {
802 return;
803 }
804 if ( \mainwp_current_user_can( 'dashboard', 'manage_security_issues' ) ) {
805 do_action_deprecated( 'mainwp-securityissues-sites', array( $website ), '4.0.7.2', 'mainwp_securityissues_sites' ); // @deprecated Use 'mainwp_securityissues_sites' instead. NOSONAR - not IP.
806
807 /**
808 * Action: mainwp_securityissues_sites
809 *
810 * Fires on a child site Hardening page at top.
811 *
812 * @hooked MainWP basic hardening features.
813 *
814 * @param object $website Object containing child site info.
815 *
816 * @since Unknown
817 */
818 do_action( 'mainwp_securityissues_sites', $website );
819 }
820 ?>
821
822 <?php
823 // Hook in MainWP Sucuri Extension.
824 if ( \mainwp_current_user_can( 'extension', 'mainwp-sucuri-extension' ) && is_plugin_active( 'mainwp-sucuri-extension/mainwp-sucuri-extension.php' ) ) {
825 do_action_deprecated( 'mainwp-sucuriscan-sites', array( $website ), '4.0.7.2', 'mainwp_sucuriscan_sites' ); // @deprecated Use 'mainwp_sucuriscan_sites' instead. NOSONAR - not IP.
826
827 /**
828 * Action: mainwp_sucuriscan_sites
829 *
830 * Fires on a child site Hardening page.
831 *
832 * @hooked MainWP Sucuri Extension data.
833 *
834 * @param object $website Object containing child site info.
835 *
836 * @since Unknown
837 */
838 do_action( 'mainwp_sucuriscan_sites', $website );
839 }
840 ?>
841
842 <?php
843 // Hook in MainWP Wordfence Extension.
844 if ( \mainwp_current_user_can( 'extension', 'mainwp-wordfence-extension' ) && is_plugin_active( 'mainwp-wordfence-extension/mainwp-wordfence-extension.php' ) ) {
845 do_action_deprecated( 'mainwp-wordfence-sites', array( $website ), '4.0.7.2', 'mainwp_wordfence_sites' ); // @deprecated Use 'mainwp_wordfence_sites' instead. NOSONAR - not IP.
846
847 /**
848 * Action: mainwp_wordfence_sites
849 *
850 * Fires on a child site Hardening page.
851 *
852 * @hooked MainWP Wordfence Extension data.
853 *
854 * @param object $website Object containing child site info.
855 *
856 * @since Unknown
857 */
858 do_action( 'mainwp_wordfence_sites', $website );
859 }
860 ?>
861 </div>
862
863 <?php
864 }
865
866 /**
867 * Method render_edit_site()
868 *
869 * Render individual Child Site Edit sub page.
870 *
871 * @param mixed $websiteid Child Site ID.
872 * @param mixed $updated Site settings updated check.
873 *
874 * @return string Edit Child Site sub page.
875 *
876 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_groups_for_current_user()
877 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_groups_by_website_id()
878 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
879 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
880 * @uses \MainWP\Dashboard\MainWP_Utility::starts_with()
881 * @uses \MainWP\Dashboard\MainWP_Utility::remove_http_prefix()
882 */
883 public static function render_edit_site( $websiteid, $updated ) { // phpcs:ignore -- NOSONAR - complex.
884 if ( ! \mainwp_current_user_can( 'dashboard', 'edit_sites' ) ) {
885 \mainwp_do_not_have_permissions( esc_html__( 'edit sites', 'mainwp' ) );
886 return;
887 }
888
889 $website = MainWP_DB::instance()->get_website_by_id( $websiteid, false, array( 'monitoring_notification_emails', 'settings_notification_emails', 'ignored_trans_updates' ) );
890 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
891 $website = null;
892 }
893
894 if ( empty( $website ) ) {
895 return;
896 }
897
898 $groups = MainWP_DB_Common::instance()->get_groups_for_current_user();
899
900 if ( ! is_array( $groups ) ) {
901 $groups = array();
902 }
903
904 $website_url = MainWP_Utility::remove_http_www_prefix( $website->url, true );
905
906 $text_use_global = esc_html__( 'Use global setting', 'mainwp' );
907 $style_checked = 'checked="true"';
908 ?>
909 <div class="ui padded segment mainwp-edit-site-<?php echo intval( $website->id ); ?>" id="mainwp-edit-site">
910 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-edit-site-info-message' ) ) { ?>
911 <div class="ui info message">
912 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-edit-site-info-message"></i>
913 <?php /* translators: 1: Site name, 2: Site URL with anchor tag, 3: Opening anchor tag for documentation link, 4: Closing anchor tag. */ printf( esc_html__( 'Edit the %1$s (%2$s) child site settings. For additional help, please check this %3$shelp documentation%4$s.', 'mainwp' ), esc_html( stripslashes( $website->name ) ), '<a href="' . esc_url( $website->url ) . '" target="_blank">' . esc_url( $website->url ) . '</a>', '<a href="https://docs.mainwp.com/sites/management/manage-child-sites#edit-child-site-settings" target="_blank">', '</a> <i class="external alternate icon"></i>' ); // phpcs:ignore WordPress.Security.EscapeOutput -- NOSONAR - noopener - open safe. ?>
914 </div>
915 <?php } ?>
916 <?php
917 MainWP_Client_Handler::show_notice_existed_contact_emails();
918 ?>
919 <div id="mainwp-message-zone" class="ui message" style="display:none;"></div>
920 <?php if ( $updated ) { ?>
921 <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Child site settings saved successfully.', 'mainwp' ); ?></div>
922 <?php } ?>
923 <form method="POST" action="" id="mainwp-edit-single-site-form" enctype="multipart/form-data" class="ui form">
924 <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
925 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'UpdateWebsite' . $website->id ) ); ?>" />
926
927 <div class="ui basic accordion mainwp-blank-accordion mainwp-sidebar-accordion" id="mainwp-edit-site-general-settings-accordion">
928 <h2 class="ui dividing header active title">
929 <i class="right dropdown icon"></i>
930 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-edit-site-general' ); ?>
931 <?php esc_html_e( 'General Settings', 'mainwp' ); ?>
932 <div class="sub header"><?php esc_html_e( 'Basic site details, organization, and update behavior.', 'mainwp' ); ?></div>
933 </h2>
934 <div class="content active">
935 <h4 class="ui dividing tiny header"><?php esc_html_e( 'Site Identity', 'mainwp' ); ?></h4>
936 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general" default-indi-value="">
937 <label class="six wide column middle aligned">
938 <?php
939 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $website->url );
940 ?>
941 <?php esc_html_e( 'Site URL', 'mainwp' ); ?> <span class="ui small red text">(<?php esc_html_e( 'Required', 'mainwp' ); ?>)</span></label>
942 <div class="ui six wide column">
943 <div class="ui left action input">
944 <select class="ui compact selection dropdown" id="mainwp_managesites_edit_siteurl_protocol" name="mainwp_managesites_edit_siteurl_protocol">
945 <option <?php echo MainWP_Utility::starts_with( $website->url, 'http:' ) ? 'selected' : ''; ?> value="http">http://</option>
946 <option <?php echo MainWP_Utility::starts_with( $website->url, 'https:' ) ? 'selected' : ''; ?> value="https">https://</option>
947 </select>
948 <div class="ui compact selection dropdown" id="mainwp-edit-site-edit-url-www">
949 <input type="hidden" name="mainwp_managesites_edit_wpurl_with_www" value="<?php echo false !== stripos( $website->url, '/www.' ) ? 'www' : 'none-www'; ?>">
950 <i class="dropdown icon"></i>
951 <div class="default text"><?php esc_html_e( 'www', 'mainwp' ); ?></div>
952 <div class="menu">
953 <div class="item" data-value="www"><?php esc_html_e( 'www', 'mainwp' ); ?></div>
954 <div class="item" data-value="none-www"><del><?php esc_html_e( 'www', 'mainwp' ); ?></del></div>
955 </div>
956 </div>
957 <input type="text" id="mainwp_managesites_edit_siteurl" class="settings-field-value-change-handler" disabled="disabled" name="mainwp_managesites_edit_siteurl" value="<?php echo esc_html( $website_url ); ?>" />
958 </div>
959 </div>
960 <div class="ui four wide middle aligned column">
961 <input type="button" name="mainwp_managesites_edit_test" id="mainwp_managesites_edit_test" class="ui button basic green" value="<?php esc_attr_e( 'Test Connection', 'mainwp' ); ?>"/>
962 </div>
963 </div>
964 <?php
965 $reported_siteurl = isset( $website->siteurl ) ? $website->siteurl : '';
966 $url_mismatch_cat = MainWP_Site_Url_Corrector::classify( $website->url, $reported_siteurl );
967 $url_correct_lock = MainWP_Site_Url_Corrector::is_locked( $website );
968 if ( MainWP_Site_Url_Corrector::is_scheme_www_category( $url_mismatch_cat ) ) :
969 $detected_scheme = wp_parse_url( $reported_siteurl, PHP_URL_SCHEME );
970 $detected_host = wp_parse_url( $reported_siteurl, PHP_URL_HOST );
971 $detected_www = is_string( $detected_host ) && 0 === stripos( $detected_host, 'www.' ) ? 'www' : 'none-www';
972 ?>
973 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
974 <label class="six wide column middle aligned"></label>
975 <div class="ui six wide column middle aligned">
976 <i class="yellow exclamation triangle icon"></i> <?php esc_html_e( 'The child site reports its address as:', 'mainwp' ); ?> <strong><?php echo esc_url( $reported_siteurl ); ?></strong>
977 </div>
978 <div class="ui four wide middle aligned column">
979 <input type="button" id="mainwp_managesites_edit_use_detected" class="ui button basic" data-scheme="<?php echo esc_attr( $detected_scheme ); ?>" data-www="<?php echo esc_attr( $detected_www ); ?>" value="<?php esc_attr_e( 'Use detected', 'mainwp' ); ?>" data-tooltip="<?php esc_attr_e( 'Sets the protocol and www selectors above to match the address the child site reports. Review and click Save Settings to apply.', 'mainwp' ); ?>" data-inverted="" data-position="top right"/>
980 </div>
981 </div>
982 <?php endif; ?>
983 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general" default-indi-value="0">
984 <label class="six wide column middle aligned">
985 <?php
986 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $url_correct_lock ? 1 : '' );
987 esc_html_e( 'Lock site URL', 'mainwp' );
988 ?>
989 </label>
990 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, MainWP will never automatically correct or reroute this site URL. This lock is set automatically when you save a URL that differs from the address the child site reports.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
991 <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_managesites_edit_url_lock" id="mainwp_managesites_edit_url_lock" <?php echo $url_correct_lock ? 'checked="true"' : ''; ?> /><label><?php esc_html_e( 'Default: Disabled', 'mainwp' ); ?></label>
992 </div>
993 </div>
994 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
995 <label class="six wide column middle aligned">
996 <?php
997 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $website->name );
998 ?>
999 <?php esc_html_e( 'Site title', 'mainwp' ); ?></label>
1000 <div class="ui six wide column">
1001 <div class="ui left labeled input">
1002 <input type="text" class="settings-field-value-change-handler" id="mainwp_managesites_edit_sitename" name="mainwp_managesites_edit_sitename" value="<?php echo esc_attr( stripslashes( $website->name ) ); ?>" />
1003 </div>
1004 </div>
1005 </div>
1006 <?php
1007 $adminname = $website->adminname;
1008 ?>
1009 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1010 <label class="six wide column middle aligned">
1011 <?php
1012 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $adminname );
1013 ?>
1014 <?php esc_html_e( 'Administrator username', 'mainwp' ); ?> <span class="ui small red text">(<?php esc_html_e( 'Required', 'mainwp' ); ?>)</span></label>
1015 <div class="ui six wide column">
1016 <div class="ui left labeled input">
1017 <input type="text" id="mainwp_managesites_edit_siteadmin" class="settings-field-value-change-handler" name="mainwp_managesites_edit_siteadmin" value="<?php echo esc_attr( $adminname ); ?>" />
1018 </div>
1019 </div>
1020 </div>
1021 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1022 <label class="six wide column middle aligned">
1023 <?php
1024 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $website->uniqueId );
1025 ?>
1026
1027 <?php esc_html_e( 'Unique security ID', 'mainwp' ); ?></label>
1028 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'If in use, enter the website Unique ID.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1029 <div class="ui left labeled input">
1030 <input type="text" id="mainwp_managesites_edit_uniqueId" class="settings-field-value-change-handler" name="mainwp_managesites_edit_uniqueId" value="<?php echo esc_attr( $website->uniqueId ); ?>" />
1031 </div>
1032 </div>
1033 </div>
1034
1035 <h4 class="ui dividing tiny header"><?php esc_html_e( 'Organization', 'mainwp' ); ?></h4>
1036
1037 <?php
1038 $uploaded_site_icon = MainWP_Manage_Sites::get_instance()->get_cust_site_icon( $website->cust_site_icon_info, 'uploaded' );
1039 $selected_site_icon = MainWP_Manage_Sites::get_instance()->get_cust_site_icon( $website->cust_site_icon_info, 'selected' );
1040 $selected_site_color = MainWP_Manage_Sites::get_instance()->get_cust_site_icon( $website->cust_site_icon_info, 'color' );
1041
1042 $uploaded_icon_src = '';
1043
1044 // default.
1045 if ( empty( $selected_site_color ) ) {
1046 $selected_site_color = '#34424D';
1047 }
1048
1049 if ( empty( $selected_site_icon ) ) {
1050 $selected_site_icon = 'wordpress'; //phpcs:ignore -- WP icon default.
1051 }
1052
1053 if ( ! empty( $uploaded_site_icon ) ) {
1054 $dirs = MainWP_System_Utility::get_mainwp_dir( 'site-icons', true );
1055 $icon_base = $dirs[1];
1056 $cust_prod_icon_file = $uploaded_site_icon;
1057 $uploaded_icon_src = $icon_base . $cust_prod_icon_file;
1058 }
1059
1060 $default_icons = MainWP_UI::get_default_icons();
1061 $delnonce = MainWP_System_Utility::get_custom_nonce( 'site', esc_attr( $uploaded_site_icon ) );
1062
1063 ?>
1064 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cost-add-edit">
1065 <label class="six wide column middle aligned">
1066 <?php
1067 $indi_val = ! empty( $uploaded_site_icon ) ? 1 : 0;
1068 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1069 esc_html_e( 'Upload site icon', 'mainwp' );
1070 ?>
1071 </label>
1072 <input type="hidden" name="mainwp_managesites_edit_site_uploaded_icon_hidden" class="settings-field-value-change-handler" id="mainwp_managesites_edit_site_uploaded_icon_hidden" value="<?php echo esc_attr( $uploaded_site_icon ); ?>">
1073 <div class="three wide middle aligned column" >
1074 <span class="ui circular bordered image">
1075 <?php if ( ! empty( $uploaded_site_icon ) ) { ?>
1076 <?php echo MainWP_Manage_Sites::get_instance()->get_cust_site_icon( $website->cust_site_icon_info, 'display_edit' ); //phpcs:ignore --ok. ?>
1077 <?php } else { ?>
1078 <div style="display:inline-block;" id="mainw_managesites_add_edit_site_upload_custom_icon"></div> <?php // used for icon holder. ?>
1079 <?php } ?>
1080 </span>
1081 <div class="ui basic button mainwp-managesites-edit-site-icon-customable"
1082 iconItemId="<?php echo intval( $website->id ); ?>"
1083 iconFileSlug="<?php echo esc_attr( $uploaded_site_icon ); ?>"
1084 del-icon-nonce="<?php echo esc_attr( $delnonce ); ?>"
1085 icon-src="<?php echo esc_attr( $uploaded_icon_src ); ?>">
1086 <i class="image icon"></i> <?php echo ! empty( $uploaded_site_icon ) ? esc_html__( 'Change Image', 'mainwp' ) : esc_html__( 'Upload Image', 'mainwp' ); ?>
1087 </div>
1088 </div>
1089 </div>
1090
1091 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general" default-indi-value="wordpress">
1092 <label class="six wide column middle aligned">
1093 <?php
1094 $indi_val = 'wordpress' !== $selected_site_icon ? 1 : 0; //phpcs:ignore -- WP icon.
1095 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1096 esc_html_e( 'Select icon', 'mainwp' );
1097 ?>
1098 </label>
1099 <input type="hidden" name="mainwp_managesites_edit_site_selected_icon_hidden" class="settings-field-value-change-handler" id="mainwp_managesites_edit_site_selected_icon_hidden" value="<?php echo esc_attr( $selected_site_icon ); ?>">
1100 <div class="six wide column" data-tooltip="<?php esc_attr_e( 'Select an icon if not using original site icon.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1101 <div class="ui left action input mainwp-dropdown-color-picker-field">
1102 <div class="ui five column selection search dropdown not-auto-init" id="mainwp_manage_add_edit_site_icon_select">
1103 <div class="text">
1104 <span style="color:<?php echo esc_attr( $selected_site_color ); ?>" ><?php echo ! empty( $selected_site_icon ) ? '<i class="' . esc_attr( $selected_site_icon ) . ' icon"></i>' : ''; ?></span>
1105 </div>
1106 <i class="dropdown icon"></i>
1107 <div class="menu">
1108 <?php foreach ( $default_icons as $icon ) : ?>
1109 <?php echo '<div class="item" style="color:' . esc_attr( $selected_site_color ) . '" data-value="' . esc_attr( $icon ) . '"><i class="' . esc_attr( $icon ) . ' icon"></i></div>'; ?>
1110 <?php endforeach; ?>
1111 </div>
1112 </div>
1113 <input type="color" data-tooltip="Color will update on save" data-position="top center" data-inverted="" name="mainwp_managesites_edit_site_color" class="mainwp-color-picker-input" id="mainwp_managesites_edit_site_color" value="<?php echo esc_attr( $selected_site_color ); ?>" />
1114 </div>
1115 </div>
1116 <div class="one wide column"></div>
1117 </div>
1118
1119 <?php
1120 $groupsSite = MainWP_DB_Common::instance()->get_groups_by_website_id( $website->id );
1121 $init_groups = '';
1122 if ( is_array( $groupsSite ) ) {
1123 foreach ( $groupsSite as $gpsSite ) {
1124 $init_groups .= ( isset( $groups[ $gpsSite->id ] ) && $groups[ $gpsSite->id ] ) ? ',' . $gpsSite->id : '';
1125 }
1126 }
1127 $init_groups = ltrim( $init_groups, ',' );
1128 ?>
1129 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1130 <label class="six wide column middle aligned">
1131 <?php
1132 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $init_groups );
1133 ?>
1134 <?php esc_html_e( 'Tags', 'mainwp' ); ?></label>
1135 <div class="ten wide column">
1136 <div class="ui multiple selection dropdown" init-value="<?php echo esc_attr( $init_groups ); ?>">
1137 <input name="mainwp_managesites_edit_addgroups" value="" class="settings-field-value-change-handler" type="hidden">
1138 <i class="dropdown icon"></i>
1139 <div class="default text"><?php echo '' === $init_groups ? esc_html__( 'No Tags added yet.', 'mainwp' ) : ''; ?></div>
1140 <div class="menu">
1141 <?php foreach ( $groups as $group ) { ?>
1142 <div class="item" data-value="<?php echo intval( $group->id ); ?>"><?php echo esc_html( $group->name ); ?></div>
1143 <?php } ?>
1144 </div>
1145 </div>
1146 </div>
1147 </div>
1148 <?php
1149 if ( \mainwp_current_user_can( 'dashboard', 'manage_clients' ) ) {
1150 $clients = MainWP_DB_Client::instance()->get_wp_client_by( 'all' );
1151 ?>
1152 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1153 <label class="six wide column middle aligned">
1154 <?php
1155 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_client_id', (int) $website->client_id );
1156 esc_html_e( 'Client', 'mainwp' );
1157 ?>
1158 </label>
1159 <div class="ui six wide column">
1160 <div class="ui search selection dropdown">
1161 <input type="hidden" name="mainwp_managesites_edit_client_id" class="settings-field-value-change-handler" value="<?php echo intval( $website->client_id ); ?>">
1162 <i class="dropdown icon"></i>
1163 <div class="default text"><?php esc_html_e( 'Select Client', 'mainwp' ); ?></div>
1164 <div class="menu">
1165 <div class="item" data-value="0"><?php esc_html_e( 'No Client', 'mainwp' ); ?></div>
1166 <?php
1167 foreach ( $clients as $client ) {
1168 ?>
1169 <div class="item" data-value="<?php echo intval( $client->client_id ); ?>">
1170 <?php echo esc_html( $client->name ); ?>
1171 </div>
1172 <?php
1173 }
1174 ?>
1175 </div>
1176 </div>
1177 <a href="javascript:void(0)" class="ui basic grey button edit-site-new-client-button"><?php esc_html_e( 'Create New Client', 'mainwp' ); ?></a>
1178 </div>
1179 </div>
1180 <?php } ?>
1181
1182 <h4 class="ui dividing tiny header"><?php esc_html_e( 'Update and Maintenance', 'mainwp' ); ?></h4>
1183 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general" default-indi-value="2">
1184 <label class="six wide column middle aligned">
1185 <?php
1186 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_backup_before_upgrade', (int) $website->backup_before_upgrade );
1187 esc_html_e( 'Require backup before update', 'mainwp' );
1188 ?>
1189 </label>
1190 <div class="ui six wide column">
1191 <select class="ui dropdown settings-field-value-change-handler" id="mainwp_backup_before_upgrade" name="mainwp_backup_before_upgrade">
1192 <option <?php echo 1 === (int) $website->backup_before_upgrade ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'Yes', 'mainwp' ); ?></option>
1193 <option <?php echo 0 === (int) $website->backup_before_upgrade ? 'selected' : ''; ?> value="0"><?php esc_html_e( 'No', 'mainwp' ); ?></option>
1194 <option <?php echo 2 === (int) $website->backup_before_upgrade ? 'selected' : ''; ?> value="2"><?php echo $text_use_global; //phpcs:ignore --ok. ?></option>
1195 </select>
1196 </div>
1197 </div>
1198 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1199 <label class="six wide column middle aligned">
1200 <?php
1201 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_automatic_update', (int) $website->automatic_update );
1202 esc_html_e( 'Auto update WP Core', 'mainwp' );
1203 ?>
1204 </label>
1205 <div class="one wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want MainWP to automatically update WP Core on this website.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1206 <input type="checkbox" name="mainwp_automaticDailyUpdate" class="settings-field-value-change-handler" id="mainwp_automaticDailyUpdate" <?php echo 1 === (int) $website->automatic_update ? $style_checked : ''; //phpcs:ignore -- ok. ?>><label for="mainwp_automaticDailyUpdate"></label>
1207 </div>
1208 </div>
1209 <?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) { ?>
1210 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1211 <label class="six wide column middle aligned">
1212 <?php
1213 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_is_ignoreCoreUpdates', (int) $website->is_ignoreCoreUpdates );
1214 esc_html_e( 'Ignore core updates', 'mainwp' );
1215 ?>
1216 </label>
1217 <div class="one wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to ignore WP Core updates on this website.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1218 <input type="checkbox" name="mainwp_is_ignoreCoreUpdates" class="settings-field-value-change-handler" id="mainwp_is_ignoreCoreUpdates" <?php echo 1 === (int) $website->is_ignoreCoreUpdates ? $style_checked : ''; //phpcs:ignore -- ok. ?>><label for="mainwp_is_ignoreCoreUpdates"></label>
1219 </div>
1220 </div>
1221 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1222 <label class="six wide column middle aligned">
1223 <?php
1224 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_is_ignorePluginUpdates', (int) $website->is_ignorePluginUpdates );
1225 esc_html_e( 'Ignore plugin updates', 'mainwp' );
1226 ?>
1227 </label>
1228 <div class="one wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to ignore plugin updates on this website.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1229 <input type="checkbox" name="mainwp_is_ignorePluginUpdates" class="settings-field-value-change-handler" id="mainwp_is_ignorePluginUpdates" <?php echo 1 === (int) $website->is_ignorePluginUpdates ? $style_checked : ''; //phpcs:ignore -- ok. ?>><label for="mainwp_is_ignorePluginUpdates"></label>
1230 </div>
1231 </div>
1232 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1233 <label class="six wide column middle aligned">
1234 <?php
1235 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_is_ignoreThemeUpdates', (int) $website->is_ignoreThemeUpdates );
1236 esc_html_e( 'Ignore theme updates', 'mainwp' );
1237 ?>
1238 </label>
1239 <div class="one wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to ignore theme updates on this website.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1240 <input type="checkbox" name="mainwp_is_ignoreThemeUpdates" class="settings-field-value-change-handler" id="mainwp_is_ignoreThemeUpdates" <?php echo 1 === (int) $website->is_ignoreThemeUpdates ? $style_checked : ''; //phpcs:ignore -- ok. ?>><label for="mainwp_is_ignoreThemeUpdates"></label>
1241 </div>
1242 </div>
1243 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1244 <label class="six wide column middle aligned">
1245 <?php
1246 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_is_ignore_trans_updates', (int) $website->ignored_trans_updates );
1247 esc_html_e( 'Ignore translation updates', 'mainwp' );
1248 ?>
1249 </label>
1250 <div class="one wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable if you want to ignore translation updates on this website.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1251 <input type="checkbox" name="mainwp_is_ignore_trans_updates" class="settings-field-value-change-handler" id="mainwp_is_ignore_trans_updates" <?php echo 1 === (int) $website->ignored_trans_updates ? $style_checked : ''; //phpcs:ignore -- ok. ?>><label for="mainwp_is_ignore_trans_updates"></label>
1252 </div>
1253 </div>
1254 <?php } ?>
1255
1256 <h4 class="ui dividing tiny header"><?php esc_html_e( 'Site Status', 'mainwp' ); ?></h4>
1257 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-general">
1258 <label class="six wide column middle aligned">
1259 <?php
1260 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_suspended_site', (int) $website->suspended );
1261 esc_html_e( 'Suspend Site', 'mainwp' );
1262 ?>
1263 </label>
1264 <div class="one wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Suspends MainWP actions for this site (updates, maintenance tasks) without disconnecting it.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1265 <input type="checkbox" name="mainwp_suspended_site" class="settings-field-value-change-handler" id="mainwp_suspended_site" <?php echo 1 === (int) $website->suspended ? $style_checked : ''; //phpcs:ignore -- ok. ?>><label for="mainwp_suspended_site"></label>
1266 </div>
1267 </div>
1268 <div class="ui grid field">
1269 <label class="six wide column middle aligned"><?php esc_html_e( 'Connected on', 'mainwp' ); ?></label>
1270 <div class="three wide column" data-tooltip="<?php esc_attr_e( 'Set the date your site was added to your MainWP Dashboard.', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1271 <div class="ui left labeled input">
1272 <div class="ui calendar mainwp_datepicker" >
1273 <div class="ui input left icon">
1274 <i class="calendar icon"></i>
1275 <input type="text" autocomplete="off" name="mainwp_managesites_edit_dt_added" placeholder="<?php esc_attr_e( 'Date', 'mainwp' ); ?>" id="mainwp_managesites_edit_dt_added" value="<?php echo ! empty( $website->added_timestamp ) ? esc_attr( date( 'Y-m-d', $website->added_timestamp ) ) : ''; // phpcs:ignore -- local time works. ?>"/>
1276 </div>
1277 </div>
1278 </div>
1279 </div>
1280 </div>
1281 </div>
1282 </div>
1283
1284 <div class="ui basic accordion mainwp-blank-accordion mainwp-sidebar-accordion" id="mainwp-edit-site-advanced-settings-accordion">
1285 <h2 class="ui dividing header title">
1286 <i class="right dropdown icon"></i>
1287 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-edit-site-advanced' ); ?>
1288 <?php esc_html_e( 'Advanced Settings (Optional)', 'mainwp' ); ?>
1289 <div class="sub header"><?php esc_html_e( 'Fine-tune behavior and control edge-case options.', 'mainwp' ); ?></div>
1290 </h2>
1291 <div class="content">
1292 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="2">
1293 <label class="six wide column middle aligned">
1294 <?php
1295 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_verify_certificate', (int) $website->verify_certificate );
1296 esc_html_e( 'Verify certificate', 'mainwp' );
1297 ?>
1298 </label>
1299 <div class="three wide column">
1300 <select class="ui dropdown settings-field-value-change-handler" id="mainwp_managesites_edit_verifycertificate" name="mainwp_managesites_edit_verifycertificate">
1301 <option <?php echo 1 === (int) $website->verify_certificate ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'Yes', 'mainwp' ); ?></option>
1302 <option <?php echo 0 === (int) $website->verify_certificate ? 'selected' : ''; ?> value="0"><?php esc_html_e( 'No', 'mainwp' ); ?></option>
1303 <option <?php echo 2 === (int) $website->verify_certificate ? 'selected' : ''; ?> value="2"><?php echo $text_use_global; //phpcs:ignore --ok. ?></option>
1304 </select>
1305 </div>
1306 </div>
1307 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-advanced">
1308 <label class="six wide column middle aligned">
1309 <?php
1310 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_ssl_version', (int) $website->ssl_version );
1311 esc_html_e( 'SSL version', 'mainwp' );
1312 ?>
1313 </label>
1314 <div class="three wide column" data-tooltip="<?php esc_attr_e( 'If you are not sure, select "Auto Detect".', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1315 <select class="ui dropdown settings-field-value-change-handler" id="mainwp_managesites_edit_ssl_version" name="mainwp_managesites_edit_ssl_version">
1316 <option <?php echo 0 === (int) $website->ssl_version ? 'selected' : ''; ?> value="0"><?php esc_html_e( 'Auto detect', 'mainwp' ); ?></option>
1317 <option <?php echo 6 === (int) $website->ssl_version ? 'selected' : ''; ?> value="6"><?php esc_html_e( 'TLS v1.2', 'mainwp' ); ?></option>
1318 <option <?php echo 1 === (int) $website->ssl_version ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'TLS v1.x', 'mainwp' ); ?></option>
1319 <option <?php echo 2 === (int) $website->ssl_version ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'SSL v2', 'mainwp' ); ?></option>
1320 <option <?php echo 3 === (int) $website->ssl_version ? 'selected' : ''; ?> value="3"><?php esc_html_e( 'SSL v3', 'mainwp' ); ?></option>
1321 <option <?php echo 4 === (int) $website->ssl_version ? 'selected' : ''; ?> value="4"><?php esc_html_e( 'TLS v1.0', 'mainwp' ); ?></option>
1322 <option <?php echo 5 === (int) $website->ssl_version ? 'selected' : ''; ?> value="5"><?php esc_html_e( 'TLS v1.1', 'mainwp' ); ?></option>
1323 </select>
1324 </div>
1325 </div>
1326 <?php
1327 if ( empty( $website->verify_method ) ) {
1328 $verify_conn_method = 3;
1329 } else {
1330 $verify_conn_method = (int) $website->verify_method;
1331 }
1332 ?>
1333 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-advanced" default-indi-value="1">
1334 <label class="six wide column middle aligned">
1335 <?php
1336 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_verify_method', (int) $verify_conn_method );
1337 esc_html_e( 'Verify connection method', 'mainwp' );
1338 ?>
1339 </label>
1340 <div class="three wide column" data-tooltip="<?php esc_attr_e( 'If you are not sure, select "Default".', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1341 <select class="ui dropdown settings-field-value-change-handler"id="mainwp_managesites_edit_verify_connection_method" name="mainwp_managesites_edit_verify_connection_method">
1342 <option <?php echo 1 === (int) $verify_conn_method ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'OpenSSL (default)', 'mainwp' ); ?></option>
1343 <option <?php echo 2 === (int) $verify_conn_method ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'PHPSECLIB (fallback)', 'mainwp' ); ?></option>
1344 <option <?php echo 3 === (int) $verify_conn_method ? 'selected' : ''; ?> value="3"><?php echo $text_use_global; //phpcs:ignore --ok. ?></option>
1345 </select>
1346 </div>
1347 </div>
1348 <?php
1349 $sign_note = MainWP_Connect_Lib::get_connection_algo_settings_note();
1350 $sign_algs = MainWP_System_Utility::get_open_ssl_sign_algos();
1351 if ( empty( $website->signature_algo ) ) {
1352 $site_sign_algo = 9999;
1353 } else {
1354 $site_sign_algo = (int) $website->signature_algo;
1355 }
1356 ?>
1357 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-advanced mainwp-hide-elemenent-sign-algo" default-indi-value="9999" <?php echo ( 2 === $verify_conn_method ) ? 'style="display:none;"' : ''; ?> >
1358 <label class="six wide column middle aligned">
1359 <?php
1360 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_signature_algo', (int) $site_sign_algo );
1361 esc_html_e( 'OpenSSL signature algorithm', 'mainwp' );
1362 ?>
1363 </label>
1364 <div class="three wide column" data-tooltip="<?php esc_attr_e( 'If you are not sure, select "Default".', 'mainwp' ); ?>" data-inverted="" data-position="right center">
1365 <select class="ui dropdown settings-field-value-change-handler" id="mainwp_managesites_edit_openssl_alg" name="mainwp_managesites_edit_openssl_alg">
1366 <?php
1367 foreach ( $sign_algs as $val => $text ) {
1368 ?>
1369 <option <?php echo ( $val === $site_sign_algo ) ? 'selected' : ''; ?> value="<?php echo esc_attr( $val ); ?>"><?php echo esc_html( $text ); ?></option>
1370 <?php
1371 }
1372 ?>
1373 <option <?php echo ( 9999 === $site_sign_algo ) ? 'selected' : ''; ?> value="9999"><?php echo $text_use_global; //phpcs:ignore --ok. ?></option>
1374 </select>
1375 <div class="ui yellow message mainwp-hide-elemenent-sign-algo-note" <?php echo ( 1 === $site_sign_algo ) ? '' : 'style="display:none;"'; ?>><?php echo esc_html( $sign_note ); ?></div>
1376 </div>
1377 </div>
1378
1379 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-advanced" default-indi-value="2">
1380 <label class="six wide column middle aligned">
1381 <?php
1382 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_force_use_ipv4', (int) $website->force_use_ipv4 );
1383 esc_html_e( 'Force IPv4', 'mainwp' );
1384 ?>
1385 </label>
1386 <div class="three wide column">
1387 <select class="ui dropdown settings-field-value-change-handler" id="mainwp_managesites_edit_forceuseipv4" name="mainwp_managesites_edit_forceuseipv4">
1388 <option <?php echo ( 1 === (int) $website->force_use_ipv4 ) ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'Yes', 'mainwp' ); ?></option>
1389 <option <?php echo ( 0 === (int) $website->force_use_ipv4 ) ? 'selected' : ''; ?> value="0"><?php esc_html_e( 'No', 'mainwp' ); ?></option>
1390 <option <?php echo ( 2 === (int) $website->force_use_ipv4 ) ? 'selected' : ''; ?> value="2"><?php echo $text_use_global; //phpcs:ignore --ok. ?></option>
1391 </select>
1392 </div>
1393 </div>
1394 <input style="display:none" type="text" name="fakeusernameremembered"/>
1395 <input style="display:none" type="password" name="fakepasswordremembered"/>
1396 <?php
1397 // MWP-1548: http_user is encrypted at rest; decrypt for the
1398 // visible username field. The "is set" indicator and the
1399 // change-detection handler still need a truthy/falsy hint
1400 // so we expose plaintext to those calls. http_pass uses the
1401 // sentinel render (below) so the live password never enters
1402 // the DOM, regardless of what's stored.
1403 $http_user_plain = MainWP_Credential_Storage::decrypt_credential( $website->http_user );
1404 $http_pass_set = ! empty( $website->http_pass );
1405 ?>
1406 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-advanced">
1407 <label class="six wide column middle aligned">
1408 <?php
1409 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_http_user', $http_user_plain );
1410 esc_html_e( 'HTTP Username', 'mainwp' );
1411 ?>
1412 </label>
1413 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'If the child site is HTTP Basic Auth protected, enter the HTTP username here.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1414 <div class="ui left labeled input">
1415 <input type="text" class="settings-field-value-change-handler" id="mainwp_managesites_edit_http_user" name="mainwp_managesites_edit_http_user" value="<?php echo empty( $http_user_plain ) ? '' : esc_attr( $http_user_plain ); ?>" autocomplete="off" />
1416 </div>
1417 </div>
1418 </div>
1419 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-advanced">
1420 <label class="six wide column middle aligned">
1421 <?php
1422 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_http_pass', $http_pass_set ? '1' : '' );
1423 esc_html_e( 'HTTP Password', 'mainwp' );
1424 ?>
1425 </label>
1426 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'If the child site is HTTP Basic Auth protected, enter the HTTP password here.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1427 <div class="ui left labeled input">
1428 <input type="password" id="mainwp_managesites_edit_http_pass" class="settings-field-value-change-handler" name="mainwp_managesites_edit_http_pass" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( $http_pass_set ) ); ?>" autocomplete="new-password" />
1429 </div>
1430 </div>
1431 </div>
1432 </div>
1433 </div>
1434
1435 <div class="ui basic accordion mainwp-blank-accordion mainwp-sidebar-accordion" id="mainwp-edit-site-health-monitoring-accordion">
1436 <h2 class="ui dividing header title">
1437 <i class="right dropdown icon"></i>
1438 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-edit-site-health' ); ?>
1439 <?php esc_html_e( 'Sites Health Monitoring (Optional)', 'mainwp' ); ?>
1440 <div class="sub header"><?php esc_html_e( 'Configure checks and alerts to stay on top of site health.', 'mainwp' ); ?></div>
1441 </h2>
1442 <div class="content">
1443 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-health" default-indi-value="1">
1444 <label class="six wide column middle aligned">
1445 <?php
1446 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_disable_health_check', (int) $website->disable_health_check );
1447 esc_html_e( 'Enable Child Site Health monitoring', 'mainwp' );
1448 ?>
1449 </label>
1450 <div class="one wide column ui toggle checkbox mainwp-checkbox-showhide-elements" hide-parent="health-monitoring">
1451 <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_managesites_edit_disableSiteHealthMonitoring" id="mainwp_managesites_edit_disableSiteHealthMonitoring" <?php echo 0 === (int) $website->disable_health_check ? $style_checked : ''; //phpcs:ignore -- ok. ?>><label for="mainwp_managesites_edit_disableSiteHealthMonitoring"></label>
1452 </div>
1453 </div>
1454 <?php
1455 $healthThreshold = $website->health_threshold;
1456 $indi_val = 0 !== (int) $healthThreshold ? 1 : 0;
1457 $hide_style = 'style="display:none;"';
1458 ?>
1459 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-health" default-indi-value="0" <?php echo 1 === (int) $website->disable_health_check ? $hide_style : ''; //phpcs:ignore -- ok.?> hide-element="health-monitoring">
1460 <label class="six wide column middle aligned">
1461 <?php
1462 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', (int) $indi_val );
1463 esc_html_e( 'Site health threshold (optional)', 'mainwp' );
1464 ?>
1465 </label>
1466 <div class="three wide column">
1467 <select name="mainwp_managesites_edit_healthThreshold" id="mainwp_managesites_edit_healthThreshold" class="ui dropdown settings-field-value-change-handler">
1468 <option value="80" <?php echo 80 === (int) $healthThreshold ? 'selected' : ''; ?>><?php esc_html_e( 'Should be improved', 'mainwp' ); ?></option>
1469 <option value="100" <?php echo 100 === (int) $healthThreshold ? 'selected' : ''; ?>><?php esc_html_e( 'Good', 'mainwp' ); ?></option>
1470 <option value="0" <?php echo 0 === (int) $healthThreshold ? 'selected' : ''; ?>><?php echo $text_use_global; //phpcs:ignore --ok. ?></option>
1471 </select>
1472 </div>
1473 </div>
1474 </div>
1475 </div>
1476 <?php
1477 MainWP_Uptime_Monitoring_Edit::instance()->render_monitor_settings( $website->id, true );
1478
1479 MainWP_Manage_Sites::render_email_settings( $website );
1480
1481 MainWP_Manage_Backups::render_individual_settings( $website );
1482
1483 do_action_deprecated( 'mainwp-manage-sites-edit', array( $website ), '4.0.7.2', 'mainwp_manage_sites_edit' ); // @deprecated Use 'mainwp_manage_sites_edit' instead. NOSONAR - not IP.
1484 do_action_deprecated( 'mainwp-extension-sites-edit', array( $website ), '4.0.7.2', 'mainwp_manage_sites_edit' ); // @deprecated Use 'mainwp_manage_sites_edit' instead. NOSONAR - not IP.
1485
1486 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
1487 do_action( 'mainwp_manage_sites_edit', $website );
1488 do_action( 'mainwp_extension_sites_edit_tablerow', $website );
1489 ?>
1490 <div class="ui divider"></div>
1491 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1492 <input type="button" name="submit_remove_website" id="mainwp-managesites-remove-site" class="ui button red big floated right" value="<?php esc_attr_e( 'Remove Site', 'mainwp' ); ?>"/>
1493 </form>
1494 </div>
1495 <div class="ui modal" id="mainwp-test-connection-modal">
1496 <i class="close icon"></i>
1497 <div class="header"><?php esc_html_e( 'Connection Test', 'mainwp' ); ?></div>
1498 <div class="content">
1499 <div class="ui active dimmer">
1500 <div class="ui text loader"><?php esc_html_e( 'Testing connection...', 'mainwp' ); ?></div>
1501 </div>
1502 <div id="mainwp-test-connection-result" class="ui segment" style="display:none">
1503 <h2 class="ui center aligned icon header">
1504 <i class=" icon"></i>
1505 <div class="content">
1506 <span></span>
1507 <div class="sub header"></div>
1508 </div>
1509 </h2>
1510 </div>
1511 </div>
1512 </div>
1513
1514 <script type="text/javascript">
1515 jQuery( document ).ready( function () {
1516 // to fix issue not loaded calendar js library
1517 if (jQuery('.ui.calendar').length > 0) {
1518 if (mainwpParams.use_wp_datepicker == 1) {
1519 jQuery('#mainwp-edit-site .ui.calendar input[type=text]').datepicker({ dateFormat: "yy-mm-dd" });
1520 } else {
1521 mainwp_init_ui_calendar( '#mainwp-edit-site .ui.calendar' );
1522 }
1523 }
1524
1525 jQuery( '#mainwp_manage_add_edit_site_icon_select' ).dropdown( {
1526 onChange: function( val ) {
1527 jQuery( '#mainwp_managesites_edit_site_selected_icon_hidden' ).val(val);
1528 jQuery( '#mainwp_managesites_edit_site_selected_icon_hidden' ).trigger('change');
1529 }
1530 } );
1531
1532 jQuery(document).on('click', '.mainwp-managesites-edit-site-icon-customable', function () {
1533 let iconObj = jQuery(this);
1534 jQuery('#mainwp_delete_image_field').hide();
1535 jQuery('#mainwp-upload-custom-icon-modal').modal('setting', 'closable', false).modal('show');
1536 jQuery('#update_custom_icon_btn').removeAttr('disabled');
1537 jQuery('#update_custom_icon_btn').attr('uploading-icon', 'site');
1538 jQuery('#mainwp_delete_image_field').find('#mainwp_delete_image_chk').attr('iconItemId', iconObj.attr('iconItemId') ); // @see used by mainwp_upload_custom_types_icon().
1539 jQuery('#mainwp_delete_image_field').find('#mainwp_delete_image_chk').attr('iconFileSlug', iconObj.attr('iconFileSlug') ); // @see used by mainwp_upload_custom_types_icon().
1540
1541 if (iconObj.attr('icon-src') != '') {
1542 jQuery('#mainwp_delete_image_field').find('.ui.image').attr('src', iconObj.attr('icon-src'));
1543 jQuery('#mainwp_delete_image_field').show();
1544 }
1545
1546 jQuery(document).on('click', '#update_custom_icon_btn', function () {
1547 let deleteIcon = jQuery('#mainwp_delete_image_chk').is(':checked');
1548 let iconItemId = iconObj.attr('iconItemId');
1549 let iconFileSlug = iconObj.attr('iconFileSlug'); // to support delete file when iconItemId = 0.
1550 // upload/delete icon action.
1551 mainwp_upload_custom_types_icon(iconObj, 'mainwp_managesites_add_edit_site_upload_site_icon', iconItemId, iconFileSlug, deleteIcon, function(response){
1552 if (jQuery('#mainwp_managesites_edit_site_uploaded_icon_hidden').length > 0) {
1553 if (typeof response.iconfile !== undefined) {
1554 jQuery('#mainwp_managesites_edit_site_uploaded_icon_hidden').val(response.iconfile);
1555 } else {
1556 jQuery('#mainwp_managesites_edit_site_uploaded_icon_hidden').val('');
1557 }
1558 jQuery('#mainwp_managesites_edit_site_uploaded_icon_hidden').trigger('change');
1559 }
1560 let deleteIcon = jQuery('#mainwp_delete_image_chk').is(':checked'); // to delete.
1561 if(deleteIcon){
1562 jQuery('#mainw_managesites_add_edit_site_upload_custom_icon').hide();
1563 } else if (jQuery('#mainw_managesites_add_edit_site_upload_custom_icon').length > 0) {
1564 if (typeof response.iconfile !== undefined) {
1565 let icon_img = typeof response.iconimg !== undefined ? response.iconimg : '';
1566 let icon_src = typeof response.iconsrc !== undefined ? response.iconsrc : '';
1567 iconObj.attr('icon-src', icon_src);
1568 iconObj.attr('iconFileSlug', response.iconfile); // to support delete file when iconItemId = 0.
1569 iconObj.attr('del-icon-nonce', response.iconnonce);
1570 jQuery('#mainwp_delete_image_field').find('.ui.image').attr('src', icon_src);
1571 jQuery('#mainw_managesites_add_edit_site_upload_custom_icon').html(icon_img).show();
1572 }
1573 }
1574 setTimeout(function () {
1575 jQuery('#mainwp-upload-custom-icon-modal').modal('hide')
1576 }, 1000);
1577 });
1578 return false;
1579 });
1580 });
1581
1582 } );
1583 </script>
1584 <?php
1585 MainWP_Client::render_add_client_modal();
1586 MainWP_UI::render_modal_upload_icon();
1587 }
1588
1589 /**
1590 * Render single site Email notification settings.
1591 *
1592 * Credits.
1593 *
1594 * Plugin-Name: WooCommerce.
1595 * Plugin URI: https://woocommerce.com/.
1596 * Author: Automattic.
1597 * Author URI: https://woocommerce.com.
1598 * License: GPLv3 or later.
1599 *
1600 * @param object $website Object containng the website info.
1601 * @param string $type Email type.
1602 * @param bool $updated_templ True if page loaded after update, false if not.
1603 *
1604 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_notification_types()
1605 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_default_emails_fields()
1606 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_settings_desc()
1607 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::render_update_template_message()
1608 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_name_by_notification_type()
1609 * @uses \MainWP\Dashboard\MainWP_Notification_Template::is_overrided_template()
1610 */
1611 public static function render_site_edit_email_settings( $website, $type, $updated_templ ) {
1612 $emails_settings = array();
1613 if ( ! empty( $website->settings_notification_emails ) ) {
1614 $emails_settings = json_decode( $website->settings_notification_emails, true );
1615 }
1616 if ( ! is_array( $emails_settings ) ) {
1617 $emails_settings = array();
1618 }
1619
1620 $default = MainWP_Notification_Settings::get_default_emails_fields( $type );
1621 $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
1622 $options = array_merge( $default, $options );
1623
1624 $title = MainWP_Notification_Settings::get_notification_types( $type );
1625 $siteid = $website->id;
1626
1627 $email_description = MainWP_Notification_Settings::get_settings_desc( $type );
1628 $text_recipients = esc_html__( 'Recipient(s)', 'mainwp' );
1629 $style_checked = 'checked="true"';
1630 ?>
1631 <div class="ui segment">
1632 <?php MainWP_Notification_Settings::render_update_template_message( $updated_templ ); ?>
1633 <form method="POST" action="admin.php?page=managesites&id=<?php echo intval( $siteid ); ?>&emailsettingsid=<?php echo intval( $siteid ); ?>" class="ui form">
1634 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'UpdateWebsiteEmailSettings' . $siteid ) ); ?>" />
1635 <input type="hidden" name="mainwp_managesites_setting_emails_type" value="<?php echo esc_html( $type ); ?>" />
1636 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-email-tokens-info-message' ) ) { ?>
1637 <div class="ui info message">
1638 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-manage-updates-message"></i>
1639 <?php echo '<a href="https://mainwp.com/extension/boilerplate/" target="_blank">Boilerplate</a> <i class="external alternate icon"></i> and <a href="https://mainwp.com/extension/pro-reports/" target="_blank">Reports</a> <i class="external alternate icon"></i> extensions tokens are supported in the email settings and templates if Extensions are in use.'; // NOSONAR - noopener - open safe. ?>
1640 </div>
1641 <?php } ?>
1642 <h3 class="ui header"><?php echo esc_html( $title ); ?></h3>
1643 <div class="sub header"><?php echo esc_html( $email_description ); ?></h3></div>
1644 <div class="ui divider"></div>
1645 <?php
1646 $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'disable', false );
1647 ?>
1648 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
1649 <label class="six wide column middle aligned">
1650 <?php
1651 MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'disable', (int) $options['disable'], false );
1652 esc_html_e( 'Enable', 'mainwp' );
1653 ?>
1654 </label>
1655 <div class="six wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'Enable this email notification.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1656 <input type="checkbox" class="settings-field-value-change-handler" inverted-value="1" name="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][disable]" id="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][disable]" <?php echo ( 0 === $options['disable'] ) ? $style_checked : ''; //phpcs:ignore -- ok. ?>/>
1657 </div>
1658 </div>
1659 <?php
1660 $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'recipients', false );
1661 ?>
1662 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
1663 <label class="six wide column middle aligned">
1664 <?php
1665 MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'recipients', $options['recipients'], false );
1666 echo $text_recipients; //phpcs:ignore -- ok.
1667 ?>
1668 </label>
1669 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'You can add multiple emails by separating them with comma.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1670 <input type="text" class="settings-field-value-change-handler" name="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][recipients]" id="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][recipients]" value="<?php echo esc_html( $options['recipients'] ); ?>"/>
1671 </div>
1672 </div>
1673 <?php
1674 $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'subject', false );
1675 ?>
1676 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
1677 <label class="six wide column middle aligned">
1678 <?php
1679 MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'subject', $options['subject'], false );
1680 esc_html_e( 'Subject', 'mainwp' );
1681 ?>
1682 </label>
1683 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the email subject.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1684 <input type="text" class="settings-field-value-change-handler" name="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][subject]" id="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][subject]" value="<?php echo esc_html( $options['subject'] ); ?>"/>
1685 </div>
1686 </div>
1687 <?php
1688 $def_val = MainWP_Settings_Indicator::get_defaults_email_settings_value( $type, 'heading', false );
1689 ?>
1690 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="<?php echo esc_attr( $def_val ); ?>" >
1691 <label class="six wide column middle aligned">
1692 <?php
1693 MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'heading', $options['heading'], false );
1694 esc_html_e( 'Email heading', 'mainwp' );
1695 ?>
1696 </label>
1697 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the email heading.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1698 <input type="text" class="settings-field-value-change-handler" name="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][heading]" id="mainwp_managesites_edit_settingEmails[<?php echo esc_html( $type ); ?>][heading]" value="<?php echo esc_html( $options['heading'] ); ?>"/>
1699 </div>
1700 </div>
1701 <div class="ui grid field settings-field-indicator-wrapper" >
1702 <label class="six wide column middle aligned">
1703 <?php
1704 $templ = MainWP_Notification_Template::get_template_name_by_notification_type( $type );
1705 $overrided = MainWP_Notification_Template::instance()->is_overrided_template( $type );
1706 MainWP_Settings_Indicator::render_not_default_email_settings_indicator( $type, 'overrided', (int) $overrided, false );
1707 esc_html_e( 'HTML template', 'mainwp' );
1708 ?>
1709 </label>
1710 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1711 <?php
1712 echo $overrided ? esc_html__( 'This template has been overridden and can be found in:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . '</code>' : esc_html__( 'To override and edit this email template copy:', 'mainwp' ) . ' <code>mainwp/templates/' . esc_html( $templ ) . '</code> ' . esc_html__( 'to the folder:', 'mainwp' ) . ' <code>wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . '</code>';
1713 ?>
1714 <input type="hidden" class="settings-field-value-change-handler" value="<?php echo intval( $overrided ); ?>">
1715 </div>
1716 </div>
1717 <div class="ui grid field" >
1718 <label class="six wide column middle aligned"></label>
1719 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Manage the email HTML template.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1720 <?php if ( $overrided ) { ?>
1721 <a href="<?php echo esc_url( wp_nonce_url( 'admin.php?page=managesites&id=' . intval( $siteid ) . '&emailsettingsid=' . intval( $siteid ) . '&edit-email=' . esc_attr( $type ), 'delete-email-template' ) ); ?>" onclick="mainwp_confirm('<?php echo esc_js( 'Are you sure you want to delete this template file?', 'mainwp' ); ?>', function(){ window.location = jQuery('a#email-delete-template').attr('href');}); return false;" id="email-delete-template" class="ui button"><?php esc_html_e( 'Return to Default Template', 'mainwp' ); ?></a>
1722 <?php
1723 } else {
1724 ?>
1725 <a href="<?php echo esc_url( wp_nonce_url( 'admin.php?page=managesites&id=' . intval( $siteid ) . '&emailsettingsid=' . intval( $siteid ) . '&edit-email=' . esc_attr( $type ), 'copy-email-template' ) ); ?>" class="ui button"><?php esc_html_e( 'Copy file to uploads', 'mainwp' ); ?></a>
1726 <?php } ?>
1727 <?php if ( $overrided ) { ?>
1728 <a href="javascript:void(0)" class="ui button" onclick="mainwp_view_template('<?php echo esc_js( $type ); ?>'); return false;"><?php esc_html_e( 'Edit Template', 'mainwp' ); ?></a>
1729 <?php
1730 } else {
1731 ?>
1732 <a href="javascript:void(0)" class="ui button" onclick="mainwp_view_template('<?php echo esc_js( $type ); ?>'); return false;"><?php esc_html_e( 'View Template', 'mainwp' ); ?></a>
1733 <?php } ?>
1734 </div>
1735 </div>
1736 <div class="ui divider"></div>
1737 <a href="admin.php?page=managesites&id=<?php echo (int) ( $siteid ); ?>&emailsettingsid=<?php echo intval( $siteid ); ?>" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
1738 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
1739 </form>
1740 </div>
1741 </div>
1742 <?php static::render_edit_template( $type, $siteid ); ?>
1743 <?php
1744 }
1745
1746 /**
1747 * Render the email notification edit form.
1748 *
1749 * Credits.
1750 *
1751 * Plugin-Name: WooCommerce.
1752 * Plugin URI: https://woocommerce.com/.
1753 * Author: Automattic.
1754 * Author URI: https://woocommerce.com.
1755 * License: GPLv3 or later.
1756 *
1757 * @param string $type Email type.
1758 * @param bool $siteid Child site ID.
1759 *
1760 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_template_name_by_notification_type()
1761 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_default_templates_dir()
1762 * @uses \MainWP\Dashboard\MainWP_Notification_Template::get_custom_templates_dir()
1763 */
1764 public static function render_edit_template( $type, $siteid = false ) {
1765
1766 $template = MainWP_Notification_Template::get_template_name_by_notification_type( $type );
1767 $default_dir = MainWP_Notification_Template::instance()->get_default_templates_dir();
1768 $custom_dir = MainWP_Notification_Template::instance()->get_custom_templates_dir();
1769
1770 $custom_file = $custom_dir . $template;
1771 $default_file = $default_dir . $template;
1772 $template_file = apply_filters( 'mainwp_default_template_locate', $default_file, $template, $default_dir, $type, $siteid );
1773
1774 if ( $siteid ) {
1775 $localion = 'admin.php?page=managesites&id=' . (int) $siteid . '&emailsettingsid=' . $siteid . '&edit-email=' . $type;
1776 } else {
1777 $localion = 'admin.php?page=SettingsEmail&edit-email=' . $type;
1778 }
1779
1780 $editable = false;
1781 ?>
1782 <div class="ui large modal" id="mainwp-edit-email-template-modal">
1783 <i class="close icon"></i>
1784 <div class="header"><?php esc_html_e( 'Edit Email Template', 'mainwp' ); ?></div>
1785 <div class="scrolling content">
1786 <form method="POST" id="email-template-form" action="<?php echo esc_html( $localion ); ?>" class="ui form">
1787 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'save-email-template' ) ); ?>" />
1788 <div class="template <?php echo esc_attr( $type ); ?>">
1789 <?php if ( file_exists( $custom_file ) ) { ?>
1790 <div class="editor">
1791 <textarea class="code" cols="80" rows="20"
1792 <?php
1793 $is_writable = MainWP_System_Utility::is_writable( $custom_file );
1794 if ( ! $is_writable ) {
1795 ?>
1796 readonly="readonly" disabled="disabled"
1797 <?php
1798 } else {
1799 $editable = true;
1800 ?>
1801 name="edit_<?php echo esc_attr( $type ) . '_code'; ?>"
1802 <?php
1803 }
1804 ?>
1805 ><?php echo esc_html( file_get_contents( $custom_file ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- required to achieven desired results. Pull requests are welcome. ?></textarea>
1806 </div>
1807 <?php
1808 } elseif ( file_exists( $template_file ) ) {
1809 ?>
1810 <div class="editor">
1811 <textarea class="code" readonly="readonly" disabled="disabled" cols="25" rows="20"><?php echo esc_html( file_get_contents( $template_file ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- required to achieven desired results. Pull requests are welcome. ?></textarea>
1812 </div>
1813 <?php
1814 } else {
1815 ?>
1816 <p><?php esc_html_e( 'File was not found.', 'mainwp' ); ?></p>
1817 <?php } ?>
1818 </div>
1819 </form>
1820 </div>
1821 <div class="actions">
1822 <?php if ( $editable ) { ?>
1823 <input type="submit" form="email-template-form" class="ui green button" value="<?php esc_attr_e( 'Save Changes', 'mainwp' ); ?>"/>
1824 <?php } ?>
1825 </div>
1826 </div>
1827 </div>
1828 <script type="text/javascript">
1829 jQuery( document ).ready( function () {
1830 mainwp_view_template = function( templ ) {
1831 jQuery( "#mainwp-edit-email-template-modal" ).modal( {
1832 closable: false,
1833 onHide: function() {
1834 location.reload( true );
1835 }
1836 } ).modal( 'show' );
1837 }
1838 } );
1839 </script>
1840 <?php
1841 }
1842
1843 /**
1844 * Render all email settings options.
1845 *
1846 * @param object $website Object containing the website info.
1847 * @param bool $updated True if page loaded after update, false if not.
1848 *
1849 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_notification_types()
1850 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_default_emails_fields()
1851 * @uses \MainWP\Dashboard\MainWP_Notification_Settings::get_settings_desc()
1852 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_notification_email()
1853 */
1854 public static function render_edit_site_email_settings( $website, $updated ) {
1855 $emails_settings = array();
1856 if ( ! empty( $website->settings_notification_emails ) ) {
1857 $emails_settings = json_decode( $website->settings_notification_emails, true );
1858 }
1859
1860 if ( ! is_array( $emails_settings ) ) {
1861 $emails_settings = array();
1862 }
1863
1864 $email_description = '';
1865 $notification_emails = MainWP_Notification_Settings::get_notification_types();
1866 $text_recipients = esc_html__( 'Recipient(s)', 'mainwp' );
1867
1868 ?>
1869
1870 <div class="ui basic accordion mainwp-blank-accordion mainwp-sidebar-accordion" id="mainwp-edit-site-email-settings-accordion">
1871 <h2 class="ui dividing header title">
1872 <i class="right dropdown icon"></i>
1873 <?php esc_html_e( 'Email Settings', 'mainwp' ); ?>
1874 <div class="sub header"><?php esc_html_e( 'Set up email notifications with per-site options, extra recipients, and template controls.', 'mainwp' ); ?></div>
1875 </h2>
1876 <div class="content">
1877
1878 <?php if ( $updated ) { ?>
1879 <div class="ui message green"><i class="close icon"></i> <?php esc_html_e( 'Email settings saved successfully.', 'mainwp' ); ?></div>
1880 <?php } ?>
1881 <div class="ui info message">
1882 <?php esc_html_e( 'Email notifications sent from MainWP Dashboard about this child site are listed below. Click on an email to configure it.', 'mainwp' ); ?>
1883 </div>
1884 <table class="ui unstackable table" id="mainwp-emails-settings-table">
1885 <thead>
1886 <tr>
1887 <th scope="col" class="collapsing"><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
1888 <th scope="col" data-priority="1"><?php esc_html_e( 'Email', 'mainwp' ); ?></th>
1889 <th scope="col" ><?php esc_html_e( 'Description', 'mainwp' ); ?></th>
1890 <th scope="col" ><?php echo $text_recipients; //phpcs:ignore -- ok. ?></th>
1891 <th scope="col" class="no-sort collapsing" data-priority="2" style="text-align:right">&nbsp;</th>
1892 </tr>
1893 </thead>
1894 <tbody>
1895 <?php foreach ( $notification_emails as $type => $name ) { ?>
1896 <?php
1897 $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array();
1898 $default = MainWP_Notification_Settings::get_default_emails_fields( $type );
1899 $options = array_merge( $default, $options );
1900 $email_description = MainWP_Notification_Settings::get_settings_desc( $type );
1901 ?>
1902 <tr>
1903 <td><?php echo ( ! $options['disable'] ) ? '<span data-tooltip="Enabled." data-position="right center" data-inverted=""><i class="circular green check inverted icon"></i></span>' : '<span data-tooltip="Disabled." data-position="right center" data-inverted=""><i class="circular x icon inverted disabled"></i></span>'; ?></td>
1904 <td><a href="admin.php?page=managesites&id=<?php echo intval( $website->id ); ?>&emailsettingsid=<?php echo intval( $website->id ); ?>&edit-email=<?php echo esc_html( rawurlencode( $type ) ); ?>" data-tooltip="<?php esc_html_e( 'Click to configure the email settings.', 'mainwp' ); ?>" data-position="right center" data-inverted=""><?php echo esc_html( $name ); ?></a></td>
1905 <td><?php echo esc_html( $email_description ); ?></td>
1906 <td><?php echo esc_html( $options['recipients'] ); ?></td>
1907 <td style="text-align:right"><a href="admin.php?page=managesites&id=<?php echo intval( $website->id ); ?>&emailsettingsid=<?php echo intval( $website->id ); ?>&edit-email=<?php echo esc_html( rawurlencode( $type ) ); ?>" data-tooltip="<?php esc_html_e( 'Click to configure the email settings.', 'mainwp' ); ?>" data-position="left center" data-inverted="" class="ui green mini button"><?php esc_html_e( 'Manage', 'mainwp' ); ?></a></td>
1908 </tr>
1909 <?php } ?>
1910 </tbody>
1911 </table>
1912 <?php
1913 /**
1914 * Action: mainwp_manage_sites_email_settings
1915 *
1916 * Fires on the Email Settigns page at bottom.
1917 *
1918 * @param object $website Object containing the website info.
1919 *
1920 * @since 4.1
1921 */
1922 do_action( 'mainwp_manage_sites_email_settings', $website );
1923 ?>
1924 <?php if ( ! empty( $website->monitoring_notification_emails ) ) : ?>
1925 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-site-uptime" default-indi-value="" hide-element="monitoring">
1926 <label class="six wide column middle aligned">
1927 <?php
1928 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_site_monitoring_notification_emails', $website->monitoring_notification_emails );
1929 esc_html_e( 'Additional notification emails (comma-separated)', 'mainwp' );
1930 ?>
1931 <span class="ui yellow small label" data-tooltip="<?php esc_attr_e( 'Deprecated. Customize recipients using the email settings above. This option will be removed in a future update.', 'mainwp' ); ?>" data-position="top left" data-inverted=""><?php esc_html_e( 'Legacy', 'mainwp' ); ?></span>
1932 </label>
1933 <div class="six wide column">
1934 <div class="ui left labeled input">
1935 <input type="text" class="settings-field-value-change-handler" id="mainwp_managesites_edit_monitoringNotificationEmails" name="mainwp_managesites_edit_monitoringNotificationEmails" value="<?php echo ! empty( $website->monitoring_notification_emails ) ? esc_attr( $website->monitoring_notification_emails ) : ''; ?>"/>
1936 </div>
1937 </div>
1938 </div>
1939 <?php endif; ?>
1940 </div>
1941 </div>
1942 <script type="text/javascript">
1943 let responsive = true;
1944 if( jQuery( window ).width() > 1140 ) {
1945 responsive = false;
1946 }
1947 jQuery( document ).ready( function() {
1948 jQuery( '#mainwp-emails-settings-table' ).DataTable( {
1949 "stateSave": true,
1950 "searching": false,
1951 "paging": false,
1952 "ordering": true,
1953 "columnDefs": [ { "orderable": false, "targets": [ 4 ] } ],
1954 "order": [ [ 1, "asc" ] ],
1955 "responsive": responsive,
1956 } );
1957 } );
1958 </script>
1959 <?php
1960 }
1961
1962 /**
1963 * Method m_reconnect_site()
1964 *
1965 * Reconnect child site.
1966 *
1967 * @param object $website The website object.
1968 * @param bool $sync_first True try to sync before reconnect.
1969 * @param array $params others params.
1970 *
1971 * @return boolean true|false.
1972 * @throws \MainWP_Exception Exception On errors.
1973 *
1974 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1975 * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1976 * @uses \MainWP\Dashboard\MainWP_Exception
1977 * @uses \MainWP\Dashboard\MainWP_Sync::sync_information_array()
1978 * @uses \MainWP\Dashboard\MainWP_Sync::sync_site()
1979 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_openssl_conf()
1980 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1981 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
1982 */
1983 public static function m_reconnect_site( $website, $sync_first = true, $params = array() ) { //phpcs:ignore -- NOSONAR - complex method.
1984 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
1985 $success = false;
1986 $_error = '';
1987 $error_code = '';
1988 try {
1989 if ( $sync_first ) {
1990 $success = MainWP_Sync::sync_site( $website, true );
1991 if ( ! $success && ! MainWP_Connect_Lib::is_use_fallback_sec_lib( $website ) ) { // fix sign algo in case not use phpseclib.
1992 // to compatible.
1993 $alg = is_object( $website ) && property_exists( $website, 'signature_algo' ) && ! empty( $website->signature_algo ) ? $website->signature_algo : false;
1994 if ( empty( $alg ) && is_object( $website ) ) {
1995 MainWP_DB::instance()->update_website_option( $website, 'signature_algo', 9999 ); // use global.
1996 $website = MainWP_DB::instance()->get_website_by_id( $website->id );
1997 if ( class_exists( __NAMESPACE__ . '\MainWP_Stack_Helper' ) ) {
1998 MainWP_Stack_Helper::stack_push( 'sync_before_reconnect' );
1999 }
2000 $success = MainWP_Sync::sync_site( $website, true );
2001 }
2002 }
2003 }
2004
2005 if ( ! $success ) {
2006 if ( MainWP_Connect_Lib::is_use_fallback_sec_lib( $website ) ) {
2007 $details = MainWP_Connect_Lib::instance()->create_connect_keys();
2008 if ( is_array( $details ) ) {
2009 $pubkey = $details['pub'];
2010 $privkey = $details['priv'];
2011 } else {
2012 $privkey = '-1';
2013 $pubkey = '-1';
2014 }
2015 } elseif ( function_exists( 'openssl_pkey_new' ) ) {
2016 $conf = array( 'private_key_bits' => 2048 );
2017 $conf_loc = MainWP_System_Utility::get_openssl_conf();
2018 if ( ! empty( $conf_loc ) ) {
2019 $conf['config'] = $conf_loc;
2020 }
2021 $res = openssl_pkey_new( $conf );
2022 @openssl_pkey_export( $res, $privkey, null, $conf ); // phpcs:ignore -- prevent warning.
2023 $details = openssl_pkey_get_details( $res );
2024 $pubkey = $details['key'];
2025 } else {
2026 $privkey = '-1';
2027 $pubkey = '-1';
2028 }
2029
2030 $verify_reg = MainWP_DB::instance()->get_website_option( $website, 'register_verify_key', '' );
2031
2032 $register_data = array(
2033 'pubkey' => $pubkey,
2034 'server' => get_admin_url(),
2035 'uniqueId' => $website->uniqueId,
2036 'regverify' => $verify_reg,
2037 );
2038
2039 $recon_user = '';
2040 $recon_userpwd = '';
2041
2042 if ( is_array( $params ) && ! empty( $params['wpadmin'] ) && ! empty( $params['adminpwd'] ) ) {
2043 $recon_user = ! empty( $params['wpadmin'] ) ? $params['wpadmin'] : '';
2044 $recon_userpwd = ! empty( $params['adminpwd'] ) ? $params['adminpwd'] : '';
2045 }
2046
2047 if ( ! empty( $recon_user ) && ! empty( $recon_userpwd ) ) {
2048 $register_data['user'] = $recon_user;
2049 $register_data['userpwd'] = $recon_userpwd;
2050 }
2051
2052 // MWP-1548: decrypt at the boundary for the reconnect/register call.
2053 $information = MainWP_Connect::fetch_url_not_authed(
2054 $website->url,
2055 $website->adminname,
2056 'register',
2057 $register_data,
2058 true,
2059 $website->verify_certificate,
2060 MainWP_Credential_Storage::decrypt_credential( $website->http_user ),
2061 MainWP_Credential_Storage::decrypt_credential( $website->http_pass ),
2062 $website->ssl_version
2063 );
2064
2065 if ( isset( $information['error'] ) && '' !== $information['error'] ) {
2066 $err = urldecode( $information['error'] );
2067 $_error = MainWP_Utility::esc_content( $err );
2068 $error_code = isset( $information['error_code'] ) ? sanitize_text_field( wp_unslash( $information['error_code'] ) ) : '';
2069 } elseif ( isset( $information['register'] ) && 'OK' === $information['register'] ) {
2070
2071 $en_pk_data = MainWP_Encrypt_Data_Lib::instance()->encrypt_privkey( $privkey, $website->id, true );
2072 $en_privkey = isset( $en_pk_data['en_data'] ) ? $en_pk_data['en_data'] : '';
2073
2074 $site_values = array(
2075 'pubkey' => base64_encode( $pubkey ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode() used for backwards compatibility.
2076 'privkey' => base64_encode( $en_privkey ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode() used for backwards compatibility.
2077 'uniqueId' => ( isset( $information['uniqueId'] ) ? $information['uniqueId'] : '' ),
2078 );
2079
2080 if ( ! empty( $recon_user ) && ! empty( $recon_userpwd ) && ( $website->adminname !== $recon_user ) ) {
2081 $site_values['adminname'] = $recon_user;
2082 }
2083
2084 MainWP_DB::instance()->update_website_values(
2085 $website->id,
2086 $site_values
2087 );
2088
2089 if ( ! empty( $information['regverify'] ) ) {
2090 MainWP_DB::instance()->update_website_option( $website, 'register_verify_key', $information['regverify'] );
2091 }
2092 if ( class_exists( __NAMESPACE__ . '\MainWP_Stack_Helper' ) ) {
2093 MainWP_Stack_Helper::stack_push( 'sync_reconnect' );
2094 }
2095 MainWP_Sync::sync_information_array( $website, $information );
2096 $success = true;
2097 } else {
2098 $_error = esc_html__( 'Undefined error!', 'mainwp' );
2099 }
2100 }
2101 } catch ( MainWP_Exception $e ) {
2102 if ( 'HTTPERROR' === $e->getMessage() ) {
2103 $_error = 'HTTP error' . ( null !== $e->get_message_extra() ? ' - ' . $e->get_message_extra() : '' );
2104 } elseif ( 'NOMAINWP' === $e->getMessage() ) {
2105 $_error = MainWP_Error_Helper::get_error_not_detected_connect(); // phpcs:ignore WordPress.Security.EscapeOutput
2106 }
2107 }
2108
2109 /**
2110 * Fires immediately after reconnect website.
2111 *
2112 * @since 4.5.1.1
2113 *
2114 * @param object $website website data.
2115 */
2116 do_action( 'mainwp_site_reconnected', $website, $success, $_error );
2117
2118 if ( $success ) {
2119 return true;
2120 }
2121
2122 if ( ! empty( $_error ) ) {
2123 throw new MainWP_Exception( $_error, '', $error_code ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
2124 }
2125 } else {
2126 throw new MainWP_Exception( esc_html__( 'This operation is not allowed!', 'mainwp' ) );
2127 }
2128
2129 return false;
2130 }
2131
2132 /**
2133 * Method add_site()
2134 *
2135 * Add Child Site.
2136 *
2137 * @param mixed $website Child Site.
2138 * @param array $output Output values.
2139 *
2140 * @return self add_wp_site()
2141 */
2142 public static function add_site( $website = false, &$output = array() ) { //phpcs:ignore -- NOSONAR - complexity.
2143 //phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2144 $params['url'] = isset( $_POST['managesites_add_wpurl'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_wpurl'] ) ) : '';
2145 $params['name'] = isset( $_POST['managesites_add_wpname'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_wpname'] ) ) : '';
2146 $params['wpadmin'] = isset( $_POST['managesites_add_wpadmin'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_wpadmin'] ) ) : '';
2147 $params['adminpwd'] = isset( $_POST['managesites_add_adminpwd'] ) ? wp_unslash( $_POST['managesites_add_adminpwd'] ) : ''; //phpcs:ignore -- NOSONAR - requires urlencoded passwd, do not sanitize for specical chars.
2148 $params['unique_id'] = isset( $_POST['managesites_add_uniqueId'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_uniqueId'] ) ) : '';
2149 $params['ssl_verify'] = empty( $_POST['verify_certificate'] ) ? false : intval( $_POST['verify_certificate'] );
2150 $params['ssl_version'] = empty( $_POST['ssl_version'] ) ? false : intval( $_POST['ssl_version'] );
2151 $params['force_use_ipv4'] = apply_filters( 'mainwp_manage_sites_force_use_ipv4', null, $params['url'] );
2152 $params['http_user'] = isset( $_POST['managesites_add_http_user'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_http_user'] ) ) : '';
2153 $params['http_pass'] = isset( $_POST['managesites_add_http_pass'] ) ? wp_unslash( $_POST['managesites_add_http_pass'] ) : '';
2154 $params['groupids'] = isset( $_POST['groupids'] ) && ! empty( $_POST['groupids'] ) ? explode( ',', sanitize_text_field( wp_unslash( $_POST['groupids'] ) ) ) : array();
2155 $params['groupnames_import'] = isset( $_POST['groupnames_import'] ) ? sanitize_text_field( wp_unslash( $_POST['groupnames_import'] ) ) : '';
2156 $params['clientid'] = isset( $_POST['clientid'] ) && ! empty( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
2157 $params['uploaded_site_icon'] = isset( $_POST['uploaded_icon'] ) && ! empty( $_POST['uploaded_icon'] ) ? sanitize_text_field( wp_unslash( $_POST['uploaded_icon'] ) ) : '';
2158 $params['selected_site_icon'] = isset( $_POST['selected_icon'] ) && ! empty( $_POST['selected_icon'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_icon'] ) ) : '';
2159 $params['cust_icon_color'] = isset( $_POST['cust_color'] ) && ! empty( $_POST['cust_color'] ) ? sanitize_hex_color( wp_unslash( $_POST['cust_color'] ) ) : '';
2160
2161 if ( isset( $_POST['qsw_page'] ) ) {
2162 $params['qsw_page'] = sanitize_text_field( wp_unslash( $_POST['qsw_page'] ) );
2163 }
2164 //phpcs:enable
2165
2166 return static::add_wp_site( $website, $params, $output );
2167 }
2168
2169 /**
2170 * Correct the entered URL against the child-reported address at
2171 * registration time.
2172 *
2173 * Delegates to MainWP_Site_Url_Corrector::correct_entered_url(): adopts
2174 * the reported www variant and http -> https scheme upgrades, never
2175 * downgrades https -> http and never crosses domains.
2176 *
2177 * @param string $entered_url Entered child site URL.
2178 * @param string $reported_url Child-reported site URL.
2179 *
2180 * @return string Corrected URL or the original entered URL.
2181 */
2182 private static function maybe_correct_www_variant_url( $entered_url, $reported_url ) {
2183 if ( ! is_string( $entered_url ) || ! is_string( $reported_url ) ) {
2184 return $entered_url;
2185 }
2186
2187 $corrected = MainWP_Site_Url_Corrector::correct_entered_url( $entered_url, $reported_url );
2188
2189 if ( $corrected !== $entered_url ) {
2190 $entered_scheme = wp_parse_url( trim( $entered_url ), PHP_URL_SCHEME );
2191 $corrected_scheme = wp_parse_url( $corrected, PHP_URL_SCHEME );
2192 if ( $entered_scheme !== $corrected_scheme ) {
2193 // The registration handshake ran over the ENTERED scheme, so an
2194 // adopted https upgrade is unverified; probe it before saving and
2195 // fall back to a www-only correction when https does not answer.
2196 $probe = MainWP_Connect::try_visit( $corrected, true );
2197 if ( ! is_array( $probe ) || ! empty( $probe['error'] ) || 200 !== (int) $probe['httpCode'] ) {
2198 $corrected = MainWP_Site_Url_Corrector::correct_entered_url( $entered_url, $reported_url, false );
2199 }
2200 }
2201 }
2202
2203 return $corrected;
2204 }
2205
2206 /**
2207 * Try to fetch the child site favicon immediately after a successful add.
2208 *
2209 * @param int $site_id Child site ID.
2210 * @param array $params Child site add parameters.
2211 */
2212 private static function maybe_fetch_initial_site_favicon( $site_id, $params ) {
2213 if ( empty( $site_id ) ) {
2214 return;
2215 }
2216
2217 $uploaded_site_icon = isset( $params['uploaded_site_icon'] ) ? $params['uploaded_site_icon'] : '';
2218 $selected_site_icon = isset( $params['selected_site_icon'] ) ? $params['selected_site_icon'] : '';
2219
2220 if ( ! empty( $uploaded_site_icon ) || ! empty( $selected_site_icon ) ) {
2221 return;
2222 }
2223
2224 $result = MainWP_Sync::get_wp_icon( $site_id );
2225 if ( isset( $result['error'] ) && ! empty( $result['error'] ) ) {
2226 MainWP_Logger::instance()->debug( 'Initial favicon fetch failed :: ' . esc_html( $result['error'] ) );
2227 }
2228 }
2229
2230 /**
2231 * Medthod add_wp_site()
2232 *
2233 * Add new Child Site.
2234 *
2235 * @param mixed $website Child Site.
2236 * @param array $params Array of new Child Site to add.
2237 * @param array $output Output values.
2238 *
2239 * @return array $message, $error, $id
2240 *
2241 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
2242 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_group_by_name()
2243 * @uses \MainWP\Dashboard\MainWP_DB::add_website()
2244 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
2245 * @uses \MainWP\Dashboard\MainWP_Exception
2246 * @uses \MainWP\Dashboard\MainWP_Sync::get_wp_icon()
2247 * @uses \MainWP\Dashboard\MainWP_Sync::sync_information_array()
2248 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_openssl_conf()
2249 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
2250 */
2251 public static function add_wp_site( $website, $params = array(), &$output = array() ) { //phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
2252 $error = '';
2253 $message = '';
2254 $id = 0;
2255 $existed_id = 0;
2256
2257 $error_category = 'unknown';
2258 $error_code = '';
2259 $connection_step = '';
2260
2261 if ( $website ) {
2262 $error = esc_html__( 'The site is already connected to your MainWP Dashboard', 'mainwp' );
2263 if ( is_array( $website ) && ! empty( $website[0] ) && is_object( $website[0] ) ) {
2264 $existed_id = $website[0]->id;
2265 } elseif ( is_object( $website ) && property_exists( $website, 'id' ) ) {
2266 $existed_id = $website->id;
2267 }
2268 $error_category = 'already_connected';
2269 } else {
2270 try {
2271
2272 /**
2273 * Filter to skip generating connection keys when adding a site in PHPUnit tests.
2274 *
2275 * This filter fires before connection keys are generated, allowing tests to
2276 * bypass RSA key generation when testing site-add functionality.
2277 *
2278 * SECURITY WARNING - TEST ONLY:
2279 * This filter ONLY fires when ALL of the following conditions are met:
2280 * 1. MAINWP_TESTING_MODE constant is defined and true.
2281 * 2. A PHPUnit test harness constant is present (WP_TESTS_DOMAIN,
2282 * PHPUNIT_COMPOSER_INSTALL, or WP_TESTS_DIR).
2283 *
2284 * These checks prevent malicious code from defining MAINWP_TESTING_MODE
2285 * in production to bypass connection key generation.
2286 *
2287 * IMPORTANT: MAINWP_TESTING_MODE must ONLY be defined in the PHPUnit bootstrap
2288 * file (tests/bootstrap.php). Defining it in production code, wp-config.php,
2289 * or plugin files would create a security vulnerability by allowing connection
2290 * key generation to be bypassed.
2291 *
2292 * @since 6.2.1
2293 *
2294 * @param bool $skip_keys Whether to skip connection key generation.
2295 * @param object $website Website object being added.
2296 * @param array $params Site connection parameters.
2297 *
2298 * @return bool True to skip connection key generation, false to generate keys normally.
2299 */
2300 $is_phpunit_env = defined( 'WP_TESTS_DOMAIN' ) || defined( 'PHPUNIT_COMPOSER_INSTALL' ) || ( defined( 'WP_TESTS_DIR' ) && WP_TESTS_DIR );
2301
2302 $skip_keys = false;
2303
2304 if ( defined( 'MAINWP_TESTING_MODE' ) && MAINWP_TESTING_MODE && $is_phpunit_env ) {
2305 $skip_keys = apply_filters( 'mainwp_add_site_skip_key_generation', false, $website, $params );
2306 }
2307
2308 if ( ! $skip_keys && MainWP_Connect_Lib::is_use_fallback_sec_lib( $website ) ) {
2309 $details = MainWP_Connect_Lib::instance()->create_connect_keys();
2310 if ( is_array( $details ) ) {
2311 $pubkey = $details['pub'];
2312 $privkey = $details['priv'];
2313 } else {
2314 $privkey = '-1';
2315 $pubkey = '-1';
2316 }
2317 } elseif ( ! $skip_keys && function_exists( 'openssl_pkey_new' ) ) {
2318 $conf = array( 'private_key_bits' => 2048 );
2319 $conf_loc = MainWP_System_Utility::get_openssl_conf();
2320 if ( ! empty( $conf_loc ) ) {
2321 $conf['config'] = $conf_loc;
2322 }
2323 $res = openssl_pkey_new( $conf );
2324 @openssl_pkey_export( $res, $privkey, null, $conf ); // phpcs:ignore -- prevent warning.
2325 $pubkey = openssl_pkey_get_details( $res );
2326 $pubkey = $pubkey['key'];
2327 } else {
2328 $privkey = '-1';
2329 $pubkey = '-1';
2330 }
2331
2332 $url = $params['url'];
2333
2334 $verifyCertificate = ( ! isset( $params['ssl_verify'] ) || empty( $params['ssl_verify'] ) ) ? false : true;
2335 $sslVersion = ! isset( $params['ssl_version'] ) || empty( $params['ssl_version'] ) ? 0 : $params['ssl_version'];
2336 $addUniqueId = isset( $params['unique_id'] ) ? $params['unique_id'] : '';
2337 $http_user = isset( $params['http_user'] ) ? $params['http_user'] : '';
2338 $http_pass = isset( $params['http_pass'] ) ? $params['http_pass'] : '';
2339 $force_use_ipv4 = isset( $params['force_use_ipv4'] ) ? $params['force_use_ipv4'] : null;
2340
2341 MainWP_Logger::instance()->debug( ' :: register site :: ' . $url );
2342
2343 $connection_step = 'handshake';
2344
2345 $information = MainWP_Connect::fetch_url_not_authed(
2346 $url,
2347 $params['wpadmin'],
2348 'register',
2349 array(
2350 'pubkey' => $pubkey,
2351 'server' => get_admin_url(),
2352 'uniqueId' => $addUniqueId,
2353 'userpwd' => isset( $params['adminpwd'] ) ? $params['adminpwd'] : '', // require urlencoded.
2354 ),
2355 false,
2356 $verifyCertificate,
2357 $http_user,
2358 $http_pass,
2359 $sslVersion,
2360 array( 'force_use_ipv4' => $force_use_ipv4 ),
2361 $output
2362 );
2363
2364 if ( isset( $information['error'] ) && '' !== $information['error'] ) {
2365 $error = MainWP_Utility::esc_content( $information['error'] );
2366 if ( is_array( $output ) ) {
2367 if ( ! empty( $output['error_category'] ) ) {
2368 $error_category = $output['error_category'];
2369 }
2370 if ( ! empty( $output['connection_step'] ) ) {
2371 $connection_step = $output['connection_step'];
2372 }
2373 if ( ! empty( $output['error_code'] ) ) {
2374 $error_code = $output['error_code'];
2375 }
2376 }
2377 } elseif ( isset( $information['register'] ) && 'OK' === $information['register'] ) {
2378 $reported_site_url = isset( $information['siteurl'] ) ? trim( wp_unslash( $information['siteurl'] ) ) : '';
2379
2380 $corrected_url = static::maybe_correct_www_variant_url( $params['url'], $reported_site_url );
2381 if ( $corrected_url !== $params['url'] ) {
2382 MainWP_Logger::instance()->debug( ' :: register site :: corrected www variant from ' . $params['url'] . ' to ' . $corrected_url );
2383 $params['url'] = $corrected_url;
2384 }
2385
2386 $connection_step = 'save_site';
2387 $groupids = array();
2388 $groupnames = array();
2389 $tmpArr = array();
2390 if ( isset( $params['groupids'] ) && is_array( $params['groupids'] ) ) {
2391 foreach ( $params['groupids'] as $group ) {
2392 if ( is_numeric( $group ) ) {
2393 $groupids[] = $group;
2394 } else {
2395 $group = trim( $group );
2396 if ( ! empty( $group ) ) {
2397 $tmpArr[] = $group;
2398 }
2399 }
2400 }
2401 foreach ( $tmpArr as $tmp ) {
2402 $getgroup = MainWP_DB_Common::instance()->get_group_by_name( trim( $tmp ) );
2403 if ( $getgroup ) {
2404 if ( ! in_array( $getgroup->id, $groupids, true ) ) {
2405 $groupids[] = $getgroup->id;
2406 }
2407 } else {
2408 $groupnames[] = trim( $tmp );
2409 }
2410 }
2411 }
2412
2413 if ( isset( $params['groupnames_import'] ) && '' !== $params['groupnames_import'] ) {
2414 $tmpArr = preg_split( '/[;,]/', $params['groupnames_import'] );
2415 foreach ( $tmpArr as $tmp ) {
2416 $group = MainWP_DB_Common::instance()->get_group_by_name( trim( $tmp ) );
2417 if ( $group ) {
2418 if ( ! in_array( $group->id, $groupids, true ) ) {
2419 $groupids[] = $group->id;
2420 }
2421 } else {
2422 $groupnames[] = trim( $tmp );
2423 }
2424 }
2425 }
2426
2427 if ( ! isset( $information['uniqueId'] ) || empty( $information['uniqueId'] ) ) {
2428 $addUniqueId = '';
2429 }
2430
2431 $http_user = isset( $params['http_user'] ) ? $params['http_user'] : '';
2432 $http_pass = isset( $params['http_pass'] ) ? $params['http_pass'] : '';
2433
2434 /**
2435 * Current user global.
2436 *
2437 * @global string
2438 */
2439 global $current_user;
2440
2441 $others = array(
2442 'groupids' => $groupids,
2443 'groupnames' => $groupnames,
2444 'verifyCertificate' => $verifyCertificate || false === $verifyCertificate ? 2 : 0, // 2 use global.
2445 'addUniqueId' => $addUniqueId,
2446 'http_user' => $http_user,
2447 'http_pass' => $http_pass,
2448 'sslVersion' => $sslVersion,
2449 // Steers the handshake above; passing it on is what gets it stored,
2450 // instead of the column waiting for the first edit of the site.
2451 'force_use_ipv4' => $force_use_ipv4,
2452 );
2453
2454 $id = MainWP_DB::instance()->add_website( $current_user->ID, $params['name'], $params['url'], $params['wpadmin'], base64_encode( $pubkey ), base64_encode( $privkey ), $others ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode() used for http encoding compatible.
2455
2456 if ( $id && isset( $params['clientid'] ) ) {
2457 MainWP_DB::instance()->update_website_values( $id, array( 'client_id' => intval( $params['clientid'] ) ) );
2458 }
2459
2460 if ( $id ) {
2461 $obj_site = (object) array( 'id' => $id );
2462 $uploaded_site_icon = isset( $params['uploaded_site_icon'] )
2463 ? $params['uploaded_site_icon']
2464 : '';
2465 $selected_site_icon = isset( $params['selected_site_icon'] )
2466 ? $params['selected_site_icon']
2467 : '';
2468 $cust_icon_color = isset( $params['cust_icon_color'] )
2469 ? $params['cust_icon_color']
2470 : '';
2471 MainWP_DB::instance()->update_website_option( $obj_site, 'added_timestamp', time() );
2472 MainWP_DB::instance()->update_website_option( $obj_site, 'signature_algo', 9999 ); // use global.
2473 $icon_info = 'uploaded:' . $uploaded_site_icon
2474 . ';selected:' . $selected_site_icon
2475 . ';color:' . $cust_icon_color;
2476 MainWP_DB::instance()->update_website_option( $obj_site, 'cust_site_icon_info', $icon_info );
2477 }
2478
2479 if ( isset( $params['qsw_page'] ) && $params['qsw_page'] ) {
2480 set_transient( 'mainwp_transient_just_connected_site_id', $id, HOUR_IN_SECONDS );
2481 /* translators: 1: Opening div tag, 2: Site name wrapped in strong tag, 3: Closing div tag, 4: Continue button anchor tag. */
2482 $message = sprintf( esc_html__( '%4$s%1$sCongratulations you have connected %2$s.%3$s After finishing the Quick Setup Wizard, you can add additional sites from the Add New Sites page. Proceeding to the next step in 3 seconds...', 'mainwp' ), '<div class="ui header">', '<strong>' . esc_html( $params['name'] ) . '</strong>', '</div>', '<a href="admin.php?page=mainwp-setup&step=monitoring" class="ui mini basic green right floated button">Continue</a>' );
2483 } else {
2484 /* translators: 1: Opening anchor tag for dashboard link, 2: Closing anchor tag, 3: Line break HTML tag. */
2485 $message = sprintf( esc_html__( 'Site successfully added - Visit the Site\'s %1$sDashboard%2$s now.%3$s', 'mainwp' ), '<a href="admin.php?page=managesites&dashboard=' . $id . '" style="text-decoration: none;" title="' . esc_html__( 'Dashboard', 'mainwp' ) . '">', '</a>', '<br/>' );
2486 }
2487
2488 $website = MainWP_DB::instance()->get_website_by_id( $id );
2489
2490 if ( $website ) { // to fix.
2491
2492 if ( ! empty( $information['regverify'] ) ) {
2493 MainWP_DB::instance()->update_website_option( $website, 'register_verify_key', $information['regverify'] );
2494 }
2495
2496 /**
2497 * Fires immediately after a new website is added.
2498 *
2499 * @since 4.5.1.1
2500 *
2501 * @param object $website website data.
2502 * @param array $information The array of information data .
2503 */
2504 do_action( 'mainwp_site_added', $website, $information );
2505
2506 /**
2507 * New site added
2508 *
2509 * Fires after adding a website to MainWP Dashboard.
2510 *
2511 * @param int $id Child site ID.
2512 *
2513 * @since 3.4
2514 */
2515 do_action( 'mainwp_added_new_site', $id, $website );
2516
2517 MainWP_Sync::sync_init_empty_values( $website );
2518
2519 $connection_step = 'post_add_sync';
2520
2521 MainWP_Sync::sync_information_array( $website, $information );
2522 self::maybe_fetch_initial_site_favicon( $id, $params );
2523 }
2524 } else {
2525 $error = sprintf( esc_html__( 'Undefined error occurred. Please try again. For additional help, contact the MainWP Support.', 'mainwp' ), '<a href="https://docs.mainwp.com/troubleshooting/potential-issues" target="_blank">', '</a> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe.
2526 }
2527 } catch ( MainWP_Exception $e ) {
2528 if ( 'HTTPERROR' === $e->getMessage() ) {
2529 $error = 'HTTP error' . ( null !== $e->get_message_extra() ? ' - ' . $e->get_message_extra() : '' );
2530 } elseif ( 'NOMAINWP' === $e->getMessage() ) {
2531 $error = MainWP_Error_Helper::get_error_not_detected_connect();
2532 } else {
2533 $error = $e->getMessage();
2534 }
2535 }
2536 }
2537
2538 $source_screen = 'manage_sites';
2539 $flow_type = ! empty( $_POST['bulk'] ) ? 'bulk' : 'single'; //phpcs:ignore -- NOSONAR -nonce ok.
2540 if ( ! empty( $_POST['qsw_page'] ) ) { //phpcs:ignore -- NOSONAR -nonce ok.
2541 $flow_type = 'wizard';
2542 $source_screen = 'onboarding_wizard';
2543 }
2544 if ( 'bulk' === $flow_type ) {
2545 $source_screen = 'quick_add_modal';
2546 }
2547
2548 $telem_info = array(
2549 'flow_type' => $flow_type,
2550 'source_screen' => $source_screen,
2551 );
2552
2553 if ( empty( $id ) ) {
2554 $telem_info['error_message'] = $error;
2555 $telem_info['error_category'] = $error_category;
2556 $telem_info['error_code'] = $error_code;
2557
2558 if ( ! empty( $connection_step ) ) {
2559 $telem_info['connection_step'] = $connection_step;
2560 }
2561 if ( is_array( $output ) && ! empty( $output['http_status'] ) ) {
2562 $telem_info['http_status'] = $output['http_status'];
2563 }
2564 }
2565
2566 do_action( 'mainwp_after_add_site', array( $message, $error, $id, $existed_id ), $website, $params, $output, $telem_info );
2567
2568 return array( $message, $error, $id, $existed_id );
2569 }
2570
2571 /**
2572 * Method update_wp_site()
2573 *
2574 * Update Child Site.
2575 *
2576 * @param mixed $params Udate parameters.
2577 *
2578 * @return int Child Site ID on success and return 0 on failure.
2579 * @throws \MainWP_Exception Error message.
2580 *
2581 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
2582 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
2583 */
2584 public static function update_wp_site( $params ) {
2585 if ( ! isset( $params['websiteid'] ) || ! MainWP_Utility::ctype_digit( $params['websiteid'] ) ) {
2586 return 0;
2587 }
2588
2589 if ( isset( $params['is_staging'] ) ) {
2590 unset( $params['is_staging'] );
2591 }
2592
2593 $website = MainWP_DB::instance()->get_website_by_id( $params['websiteid'] );
2594 if ( null === $website ) {
2595 return 0;
2596 }
2597
2598 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
2599 return 0;
2600 }
2601
2602 $data = array();
2603 $uniqueId = null;
2604
2605 if ( isset( $params['name'] ) && ! empty( $params['name'] ) ) {
2606 $data['name'] = htmlentities( $params['name'] );
2607 }
2608
2609 if ( isset( $params['wpadmin'] ) && ! empty( $params['wpadmin'] ) ) {
2610 $data['adminname'] = $params['wpadmin'];
2611 }
2612
2613 if ( isset( $params['unique_id'] ) ) {
2614 $data['uniqueId'] = $params['unique_id'];
2615 $uniqueId = $params['unique_id'];
2616 }
2617
2618 if ( empty( $data ) ) {
2619 return 0;
2620 }
2621
2622 MainWP_DB::instance()->update_website_values( $website->id, $data );
2623 if ( null !== $uniqueId ) {
2624 try {
2625 MainWP_Connect::fetch_url_authed( $website, 'update_values', array( 'uniqueId' => $uniqueId ) );
2626 } catch ( MainWP_Exception $e ) {
2627 // error update unique id.
2628 }
2629 }
2630
2631 /**
2632 * Action: mainwp_updated_site
2633 *
2634 * Fires after updatig the child site options.
2635 *
2636 * @param int $website->id Child site ID.
2637 * @param array $data Child site data.
2638 *
2639 * @since 3.5.1
2640 */
2641 do_action( 'mainwp_updated_site', $website->id, $data );
2642 return $website->id;
2643 }
2644 }
2645