PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / pages / page-mainwp-setup-wizard.php

page-mainwp-setup-wizard.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.3, at pages/page-mainwp-setup-wizard.php

1,173 lines 69.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Setup Wizard
4 *
5 * MainWP Quick Setup Wizard enables you to quickly set basic plugin settings
6 *
7 * @package MainWP/Setup_Wizard
8 */
9
10 namespace MainWP\Dashboard;
11
12 /**
13 * Copyright
14 * Plugin: WooCommerce
15 * Plugin URI: http://www.woothemes.com/woocommerce/
16 * Description: An e-commerce toolkit that helps you sell anything. Beautifully.
17 * Version: 2.4.4
18 * Author: WooThemes
19 * Author URI: http://woothemes.com
20 */
21
22 /**
23 * Class MainWP_Setup_Wizard
24 *
25 * @package MainWP\Dashboard
26 */
27 class MainWP_Setup_Wizard { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
28
29 /**
30 * Private variable to hold current quick setup wizard step.
31 *
32 * @var string Current QSW step.
33 */
34 private $step = '';
35
36 /**
37 * Private variable to hold quick setup wizard steps.
38 *
39 * @var array QSW steps.
40 */
41 private $steps = array();
42
43 /**
44 * MainWP_Setup_Wizard constructor.
45 *
46 * Run each time the class is called.
47 */
48 public function __construct() {
49 add_action( 'admin_menu', array( $this, 'admin_menus' ) );
50 add_action( 'admin_init', array( $this, 'admin_init' ), 999 );
51 }
52
53 /**
54 * Method get_instance().
55 */
56 public static function get_instance() {
57 return new self();
58 }
59
60 /**
61 * Method admin_menus()
62 *
63 * Add Quick Setup Wizard page.
64 */
65 public function admin_menus() {
66 add_dashboard_page( '', '', 'manage_options', 'mainwp-setup', '' );
67 }
68
69 /**
70 * Medthod admin_init()
71 *
72 * Initiate Quick Setup Wizard page.
73 */
74 public function admin_init() {
75 if ( empty( $_GET['page'] ) || 'mainwp-setup' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
76 return;
77 }
78 $this->steps = array(
79 'welcome' => array(
80 'name' => esc_html__( 'Welcome', 'mainwp' ),
81 'view' => array( $this, 'mwp_setup_welcome' ),
82 'handler' => '',
83 ),
84 'introduction' => array(
85 'name' => esc_html__( 'Introduction', 'mainwp' ),
86 'view' => array( $this, 'mwp_setup_introduction' ),
87 'handler' => array( $this, 'mwp_setup_introduction_save' ),
88 ),
89 'system_check' => array(
90 'name' => esc_html__( 'System', 'mainwp' ),
91 'view' => array( $this, 'mwp_setup_system_requirements' ),
92 'handler' => array( $this, 'mwp_setup_system_requirements_save' ),
93 ),
94 'connect_first_site' => array(
95 'name' => esc_html__( 'Connect', 'mainwp' ),
96 'view' => array( $this, 'mwp_setup_connect_first_site' ),
97 'handler' => array( $this, 'mwp_setup_connect_first_site_save' ),
98 ),
99 'add_client' => array(
100 'name' => esc_html__( 'Add Client', 'mainwp' ),
101 'view' => array( $this, 'mwp_setup_add_client' ),
102 'handler' => '',
103 ),
104 'monitoring' => array(
105 'name' => esc_html__( 'Monitoring', 'mainwp' ),
106 'view' => array( $this, 'mwp_setup_monitoring' ),
107 'handler' => array( $this, 'mwp_setup_monitoring_save' ),
108 ),
109 'next_steps' => array(
110 'name' => esc_html__( 'Finish', 'mainwp' ),
111 'view' => array( $this, 'mwp_setup_ready' ),
112 'handler' => '',
113 ),
114 );
115
116 $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
117
118 wp_enqueue_script( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.js', array( 'jquery' ), MAINWP_VERSION, false );
119 wp_localize_script( 'mainwp-setup', 'mainwpSetupLocalize', array( 'nonce' => wp_create_nonce( 'MainWPSetup' ) ) );
120 wp_enqueue_script( 'mainwp', MAINWP_PLUGIN_URL . 'assets/js/mainwp.js', array( 'jquery' ), MAINWP_VERSION, true );
121 wp_enqueue_script( 'mainwp-clients', MAINWP_PLUGIN_URL . 'assets/js/mainwp-clients.js', array(), MAINWP_VERSION, true );
122 wp_enqueue_script( 'mainwp-setup', MAINWP_PLUGIN_URL . 'assets/js/mainwp-setup.js', array( 'jquery', 'fomantic-ui' ), MAINWP_VERSION, true );
123 wp_enqueue_script( 'mainwp-import', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-import.js', array( 'jquery' ), MAINWP_VERSION, true );
124 wp_enqueue_script( 'mainwp-ui', MAINWP_PLUGIN_URL . 'assets/js/mainwp-ui.js', array(), MAINWP_VERSION, true );
125 wp_enqueue_style( 'mainwp', MAINWP_PLUGIN_URL . 'assets/css/mainwp.css', array(), MAINWP_VERSION );
126 wp_enqueue_style( 'mainwp-fonts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fonts.css', array(), MAINWP_VERSION );
127 wp_enqueue_style( 'fomantic', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.css', array(), MAINWP_VERSION );
128 wp_enqueue_style( 'mainwp-fomantic', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fomantic.css', array(), MAINWP_VERSION );
129
130 // load custom MainWP theme.
131 $selected_theme = MainWP_Settings::get_instance()->get_selected_theme();
132 if ( ! empty( $selected_theme ) ) {
133 if ( 'dark' === $selected_theme ) {
134 wp_enqueue_style( 'mainwp-custom-dashboard-extension-dark-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-dark-theme.css', array(), MAINWP_VERSION );
135 } elseif ( 'wpadmin' === $selected_theme ) {
136 wp_enqueue_style( 'mainwp-custom-dashboard-extension-wp-admin-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-wpadmin-theme.css', array(), MAINWP_VERSION );
137 } elseif ( 'minimalistic' === $selected_theme ) {
138 wp_enqueue_style( 'mainwp-custom-dashboard-extension-minimalistic-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-minimalistic-theme.css', array(), MAINWP_VERSION );
139 } elseif ( 'default' === $selected_theme ) {
140 wp_enqueue_style( 'mainwp-custom-dashboard-extension-default-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-default-theme.css', array(), MAINWP_VERSION );
141 } else {
142 $dirs = MainWP_Settings::get_instance()->get_custom_theme_folder();
143 $custom_theme_url = $dirs[1];
144 wp_enqueue_style( 'mainwp-custom-dashboard-theme', $custom_theme_url . $selected_theme, array(), MAINWP_VERSION );
145 }
146 }
147
148 if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
149 call_user_func( $this->steps[ $this->step ]['handler'] );
150 }
151
152 if ( MainWP_Utility::instance()->is_disabled_functions( 'error_log' ) || ! function_exists( '\error_log' ) ) {
153 error_reporting(0); // phpcs:ignore -- try to disabled the error_log somewhere in WP.
154 }
155
156 ob_start();
157 $this->setup_wizard_header();
158 $this->setup_wizard_steps();
159 $this->setup_wizard_content();
160 $this->setup_wizard_footer();
161 ?>
162 <?php
163 if ( get_option( 'mainwp_enable_guided_tours', 0 ) ) {
164 static::mainwp_usetiful_tours();
165 }
166 exit;
167 }
168
169 /**
170 * Method get_next_step_link()
171 *
172 * Get the link for the next step.
173 *
174 * @param string $step Next step link.
175 *
176 * @return string Link for next step.
177 */
178 public function get_next_step_link( $step = '' ) {
179 if ( ! empty( $step ) && isset( $step, $this->steps ) ) {
180 return esc_url_raw( remove_query_arg( array( 'noregister', 'message' ), add_query_arg( 'step', $step ) ) );
181 }
182 $keys = array_keys( $this->steps );
183 return esc_url_raw( remove_query_arg( array( 'noregister', 'message' ), add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] ) ) );
184 }
185
186 /**
187 * Method get_back_step_link()
188 *
189 * Get the link for the previouse step.
190 *
191 * @param string $step Previouse step link.
192 *
193 * @return string Link for previouse step.
194 */
195 public function get_back_step_link( $step = '' ) {
196 if ( ! empty( $step ) && isset( $step, $this->steps ) ) {
197 return esc_url_raw( remove_query_arg( array( 'noregister', 'message' ), add_query_arg( 'step', $step ) ) );
198 }
199 $keys = array_keys( $this->steps );
200 return esc_url_raw( remove_query_arg( array( 'noregister', 'message' ), add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) - 1 ] ) ) );
201 }
202
203 /**
204 * Method setup_wizard_header()
205 *
206 * Render Setup Wizard's header.
207 */
208 public function setup_wizard_header() {
209 $selected_theme = MainWP_Settings::get_instance()->get_selected_theme();
210 ?>
211 <!DOCTYPE html>
212 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?> class="mainwp-quick-setup">
213 <head>
214 <meta name="viewport" content="width=device-width" />
215 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
216 <title><?php esc_html_e( 'MainWP &rsaquo; Setup Wizard', 'mainwp' ); ?></title>
217 <?php wp_print_scripts( 'mainwp' ); ?>
218 <?php wp_print_scripts( 'mainwp-clients' ); ?>
219 <?php wp_print_scripts( 'mainwp-setup' ); ?>
220 <?php wp_print_scripts( 'fomantic' ); ?>
221 <?php wp_print_scripts( 'mainwp-ui' ); ?>
222 <?php wp_print_scripts( 'mainwp-import' ); ?>
223 <?php
224 // to fix warning.
225 /**
226 * Remove the deprecated `print_emoji_styles` handler.
227 * It avoids breaking style generation with a deprecation message.
228 */
229 $has_emoji_styles = has_action( 'admin_print_styles', 'print_emoji_styles' );
230 if ( $has_emoji_styles ) {
231 remove_action( 'admin_print_styles', 'print_emoji_styles' );
232 }
233 ?>
234 <?php do_action( 'admin_print_styles' ); ?>
235 <script type="text/javascript"> let ajaxurl = '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>';</script>
236 <script type="text/javascript">let mainwp_ajax_nonce = "<?php echo esc_js( wp_create_nonce( 'mainwp_ajax' ) ); ?>", mainwp_js_nonce = "<?php echo esc_js( wp_create_nonce( 'mainwp_nonce' ) ); ?>";</script>
237 </head>
238 <body class="mainwp-ui <?php echo ! empty( $selected_theme ) ? 'mainwp-custom-theme' : ''; ?> mainwp-ui-setup">
239 <div class="ui hidden divider"></div>
240 <div class="ui hidden divider"></div>
241 <div id="mainwp-quick-setup-wizard" class="ui padded container segment">
242 <?php
243 }
244
245 /**
246 * Method setup_wizard_footer()
247 *
248 * Render Setup Wizard's footer.
249 */
250 public function setup_wizard_footer() {
251 ?>
252 </div>
253 <div class="ui grid">
254 <div class="row">
255 <div class="center aligned column">
256 <a class="" href="<?php echo esc_url( admin_url( 'index.php' ) ); ?>"><?php esc_html_e( 'Quit MainWP Quick Setup Wizard and Go to WP Admin', 'mainwp' ); ?></a> | <a class="" href="<?php echo esc_url( admin_url( 'admin.php?page=mainwp_tab' ) ); ?>"><?php esc_html_e( 'Quit MainWP Quick Setup Wizard and Go to MainWP', 'mainwp' ); ?></a>
257 </div>
258 </div>
259 </div>
260 </body>
261 </html>
262 <?php
263 }
264
265 /**
266 * Method setup_wizard_steps()
267 *
268 * Render Setup Wizards Steps.
269 */
270 public function setup_wizard_steps() {
271 $ouput_steps = $this->steps;
272 ?>
273 <div id="mainwp-quick-setup-wizard-steps" class="ui ordered fluid steps" style="">
274 <?php foreach ( $ouput_steps as $step_key => $step ) { ?>
275 <?php
276 if ( isset( $step['hidden'] ) && $step['hidden'] ) {
277 continue;
278 }
279
280 if ( 'welcome' === $step_key ) {
281 continue;
282 }
283 ?>
284 <div class="step
285 <?php
286 if ( $step_key === $this->step ) {
287 echo 'active';
288 } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
289 echo 'completed';
290 }
291 ?>
292 ">
293 <div class="content">
294 <div class="title"><?php echo esc_html( $step['name'] ); ?></div>
295 </div>
296 </div>
297 <?php } ?>
298 </div>
299 <?php
300 }
301
302 /**
303 * Method setup_wizard_content()
304 *
305 * Render setup Wizard's current step view.
306 */
307 public function setup_wizard_content() {
308 echo '<div class="mainwp-quick-setup-wizard-steps-content" style="margin-top:3em;">';
309 call_user_func( $this->steps[ $this->step ]['view'] );
310 echo '</div>';
311 echo '<div class="ui clearing hidden divider"></div>';
312 }
313
314 /**
315 * Method mwp_setup_welcome()
316 *
317 * Renders the Welcome screen of the Quick Start Wizard
318 */
319 public function mwp_setup_welcome() {
320 delete_option( 'mainwp_run_quick_setup' );
321 $is_new = MainWP_Demo_Handle::get_instance()->is_new_instance();
322 $enabled_demo = apply_filters( 'mainwp_demo_mode_enabled', false );
323 $count_sites = MainWP_DB::instance()->get_websites_count();
324 ?>
325 <h1 class="ui header"><?php esc_html_e( 'Welcome to your MainWP Dashboard!', 'mainwp' ); ?></h1>
326 <div class="ui message" id="mainwp-message-zone" style="display:none"></div>
327 <div class="ui hidden divider"></div>
328 <h3><?php esc_html_e( 'Are you ready to get started adding your sites?', 'mainwp' ); ?></h3>
329 <a class="ui big green basic button" href="<?php echo esc_url( admin_url( 'admin.php?page=mainwp-setup&step=introduction' ) ); ?>"><?php esc_html_e( 'Start the MainWP Quick Setup Wizard', 'mainwp' ); ?></a>
330 <?php if ( empty( $count_sites ) ) : ?>
331 <div class="ui hidden divider"></div>
332 <h3><?php esc_html_e( 'Would you like to see Demo content first? ', 'mainwp' ); ?> - <?php printf( esc_html__( '%1$sWhat is this?%2$s', 'mainwp' ), '<a href="https://www.youtube.com/watch?v=fCHT47AKt7s" target="_blank">', '</a>' ); ?></h3>
333 <p><?php esc_attr_e( 'Explore MainWP\'s capabilities using our pre-loaded demo content.', 'mainwp' ); ?></p>
334 <p><?php esc_attr_e( 'It\'s the perfect way to experience the benefits and ease of use MainWP provides without connecting to any of your own sites.', 'mainwp' ); ?></p>
335 <p><?php esc_html_e( 'The demo content serves as placeholder data to give you a feel for the MainWP Dashboard. Please note that because no real websites are connected in this demo, some functionality will be restricted. Features that require a connection to actual websites will be disabled for the duration of the demo.', 'mainwp' ); ?></p>
336 <p><?php esc_attr_e( 'Click this button to import the Demo content to your MainWP Dashboard and enable the Demo mode.', 'mainwp' ); ?></p>
337 <p><span><button class="ui big green button mainwp-import-demo-data-button" page-import="qsw-import" <?php echo ! $is_new || $enabled_demo ? 'disabled="disabled"' : ''; ?>><?php esc_html_e( 'Enable Demo Mode With Guided Tours', 'mainwp' ); ?></button></span></p>
338 <div class="ui blue message">
339 <?php printf( esc_html__( 'Guided tours feature is implemented using Javascript provided by Usetiful and is subject to the %1$sUsetiful Privacy Policy%2$s.', 'mainwp' ), '<a href="https://www.usetiful.com/privacy-policy" target="_blank">', '</a>' ); ?>
340 </div>
341 <?php endif; ?>
342 <?php
343 MainWP_System_View::render_comfirm_modal();
344 }
345
346 /**
347 * Method mwp_setup_introduction()
348 *
349 * Renders the Introduction screen of the Quick Start Wizard
350 */
351 public function mwp_setup_introduction() {
352 ?>
353 <div class="ui message" id="mainwp-message-zone" style="display:none"></div>
354 <h1 class="ui header"><?php esc_html_e( 'MainWP Quick Setup Wizard', 'mainwp' ); ?></h1>
355 <div><?php esc_html_e( 'Thank you for choosing MainWP for managing your WordPress sites. This quick setup wizard will help you configure the basic settings. It\'s completely optional and shouldn\'t take longer than five minutes.', 'mainwp' ); ?></div>
356 <div class="ui hidden divider"></div>
357 <a href="https://kb.mainwp.com/docs/quick-setup-wizard-video/" target="_blank" class="ui big icon green button"><i class="youtube icon"></i> <?php esc_html_e( 'Walkthrough', 'mainwp' ); ?></a>
358 <div class="ui hidden divider"></div>
359 <p><?php esc_html_e( 'If you don\'t want to go through the setup wizard, you can skip and proceed to your MainWP Dashboard by clicking the "Not right now" button. If you change your mind, you can come back later by starting the Setup Wizard from the MainWP > Settings > MainWP Tools page!', 'mainwp' ); ?></p>
360 <div class="ui hidden divider"></div>
361 <form method="post" class="ui form">
362 <h1><?php esc_html_e( 'MainWP Guided Tours', 'mainwp' ); ?> <span class="ui blue mini label"><?php esc_html_e( 'BETA', 'mainwp' ); ?></span></h1>
363 <?php esc_html_e( 'MainWP guided tours are designed to provide information about all essential features on each MainWP Dashboard page.', 'mainwp' ); ?>
364 <div class="ui blue message">
365 <?php printf( esc_html__( 'This feature is implemented using Javascript provided by Usetiful and is subject to the %1$sUsetiful Privacy Policy%2$s.', 'mainwp' ), '<a href="https://www.usetiful.com/privacy-policy" target="_blank">', '</a>' ); ?>
366 </div>
367 <div class="ui form">
368 <div class="field">
369 <div class="ui hidden divider"></div>
370 <label><?php esc_html_e( 'Do you want to enable MainWP Guided Tours?', 'mainwp' ); ?></label>
371 <div class="ui hidden divider"></div>
372 <div class="ui toggle checkbox">
373 <input type="checkbox" name="mainwp-guided-tours-option" id="mainwp-guided-tours-option" checked="true">
374 <label for="mainwp-guided-tours-option"><?php esc_html_e( 'Select to enable the MainWP Guided Tours.', 'mainwp' ); ?><span class="ui left pointing green label"><?php esc_html_e( 'Highly recommended if new to MainWP!', 'mainwp' ); ?></span></label>
375 </div>
376 </div>
377 </div>
378 <div class="ui hidden divider"></div>
379 <p><?php esc_html_e( 'To go back to the WordPress Admin section, click the "Back to WP Admin" button.', 'mainwp' ); ?></p>
380 <div class="ui hidden divider"></div>
381 <div class="ui hidden divider"></div>
382 <div class="ui hidden divider"></div>
383 <input type="submit" class="ui big green right floated button" value="<?php esc_html_e( 'Let\'s Go!', 'mainwp' ); ?>" name="save_step" />
384 <a href="<?php echo esc_url( admin_url( 'index.php' ) ); ?>" class="ui big button"><?php esc_html_e( 'Back to WP Admin', 'mainwp' ); ?></a>
385 <a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&do=new' ) ); ?>" class="ui big button"><?php esc_html_e( 'Not Right Now', 'mainwp' ); ?></a>
386 <?php wp_nonce_field( 'mwp-setup' ); ?>
387 </form>
388 <?php
389 MainWP_System_View::render_comfirm_modal();
390 }
391
392
393 /**
394 * Method mwp_setup_system_requirements()
395 *
396 * Render System Requirements Step.
397 *
398 * @uses \MainWP\Dashboard\MainWP_Server_Information::render_quick_setup_system_check()
399 */
400 public function mwp_setup_system_requirements() {
401 ?>
402 <h1><?php esc_html_e( 'System Requirements Check', 'mainwp' ); ?></h1>
403 <?php MainWP_System_View::mainwp_warning_notice(); ?>
404 <form method="post" class="ui form">
405 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
406 <?php
407 $show_ssl = false;
408 if ( MainWP_Server_Information_Handler::is_openssl_config_warning() ) {
409 $openssl_loc = MainWP_System_Utility::get_openssl_conf();
410 ?>
411 <div class="ui secondary segment">
412 <div class="grouped fields">
413 <label><?php esc_html_e( 'What is the openssl.cnf file location on your computer?', 'mainwp' ); ?></label>
414 <div class="field" id="mainwp-setup-installation-openssl-location">
415 <div class="ui fluid input">
416 <input type="text" name="mwp_setup_openssl_lib_location" value="<?php echo esc_attr( $openssl_loc ); ?>">
417 </div>
418 <div><em><?php esc_html_e( 'Due to bug with PHP on some servers, enter the openssl.cnf file location so MainWP Dashboard can connect to your child sites. If your openssl.cnf file is saved to a different path from what is entered above please enter your exact path. ', 'mainwp' ); ?><?php printf( esc_html__( '%1$sClick here%2$s to see how to find the OpenSSL.cnf file.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/how-to-find-the-openssl-cnf-file/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?></em></div>
419 </div>
420 </div>
421 </div>
422 <?php
423 $show_ssl = true;
424 }
425 ?>
426 <div class="ui message warning"><?php esc_html_e( 'Any warning here may cause the MainWP Dashboard to malfunction. After you complete the Quick Start setup it is recommended to contact your host’s support and updating your server configuration for optimal performance.', 'mainwp' ); ?></div>
427 <?php MainWP_Server_Information::render_quick_setup_system_check(); ?>
428 <div class="ui hidden divider"></div>
429 <div class="ui hidden divider"></div>
430 <div class="ui hidden divider"></div>
431 <?php
432 if ( $show_ssl ) {
433 ?>
434 <input type="submit" class="ui big green right floated button" value="<?php esc_attr_e( 'Continue', 'mainwp' ); ?>" name="save_step" />
435 <?php
436 } else {
437 ?>
438 <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="ui big green right floated button"><?php esc_html_e( 'Continue', 'mainwp' ); ?></a>
439 <?php } ?>
440 <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="ui big button"><?php esc_html_e( 'Skip', 'mainwp' ); ?></a>
441 <a href="<?php echo esc_url( $this->get_back_step_link() ); ?>" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
442 <?php wp_nonce_field( 'mwp-setup' ); ?>
443 </form>
444 <?php
445 }
446
447
448 /**
449 * Method mwp_setup_introduction_save()
450 *
451 * Installation Step save to DB.
452 *
453 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
454 */
455 public function mwp_setup_introduction_save() {
456 check_admin_referer( 'mwp-setup' );
457 $enabled_tours = ! isset( $_POST['mainwp-guided-tours-option'] ) ? 0 : 1; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
458 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enabled_tours );
459 wp_safe_redirect( $this->get_next_step_link() );
460 exit;
461 }
462
463 /**
464 * Method mwp_setup_connect_first_site_save()
465 *
466 * Installation Step after connect first site.
467 */
468 public function mwp_setup_connect_first_site_save() {
469 check_admin_referer( 'mwp-setup' );
470 if ( isset( $_POST['mainwp-qsw-confirm-add-new-client'] ) && ! empty( $_POST['mainwp-qsw-confirm-add-new-client'] ) ) {
471 wp_safe_redirect( $this->get_next_step_link() );
472 } else {
473 wp_safe_redirect( $this->get_next_step_link( 'monitoring' ) );
474 }
475 exit;
476 }
477
478 /**
479 * Method mwp_setup_system_requirements_save()
480 *
481 * Installation Step save to DB.
482 *
483 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
484 */
485 public function mwp_setup_system_requirements_save() {
486 check_admin_referer( 'mwp-setup' );
487 if ( isset( $_POST['mwp_setup_openssl_lib_location'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
488 MainWP_Utility::update_option( 'mainwp_opensslLibLocation', isset( $_POST['mwp_setup_openssl_lib_location'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_setup_openssl_lib_location'] ) ) : '' ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
489 }
490 wp_safe_redirect( $this->get_next_step_link() );
491 exit;
492 }
493
494
495
496 /**
497 * Method mwp_setup_connect_first_site_already()
498 *
499 * Render Added first Child Site Step form.
500 */
501 public function mwp_setup_connect_first_site_already() {
502 $count_clients = MainWP_DB_Client::instance()->count_total_clients();
503 ?>
504 <h1 class="ui header"><?php esc_html_e( 'Congratulations!', 'mainwp' ); ?></h1>
505 <p><?php esc_html_e( 'You have successfully connected your first site to your MainWP Dashboard!', 'mainwp' ); ?></p>
506 <div class="ui form">
507 <form method="post" class="ui form">
508 <?php if ( empty( $count_clients ) ) { ?>
509 <div class="field">
510 <label><?php esc_html_e( 'Do you want to create a client for your first child site?', 'mainwp' ); ?></label>
511 <div><?php esc_html_e( 'By adding a new client, you streamline site management within MainWP. Assigning sites to clients allows you to group and manage websites according to the clients they belong to for better organization and accessibility.', 'mainwp' ); ?></div>
512 <div class="ui hidden divider"></div>
513 <div class="ui toggle checkbox">
514 <input type="checkbox" name="mainwp-qsw-confirm-add-new-client" id="mainwp-qsw-confirm-add-new-client" checked="true"/>
515 <label><?php esc_html_e( 'Select to create a New Client', 'mainwp' ); ?></label>
516 </div>
517 </div>
518 <?php } ?>
519 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
520 <div class="ui clearing hidden divider"></div>
521 <div class="ui hidden divider"></div>
522 <div class="ui hidden divider"></div>
523 <input type="submit" class="ui big green right floated button" value="<?php esc_attr_e( 'Continue', 'mainwp' ); ?>" name="save_step" />
524 <a href="<?php echo esc_url( $this->get_back_step_link() ); ?>" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
525 <?php wp_nonce_field( 'mwp-setup' ); ?>
526 <input type="hidden" id="nonce_secure_data" mainwp_addwp="<?php echo esc_js( wp_create_nonce( 'mainwp_addwp' ) ); ?>" mainwp_checkwp="<?php echo esc_attr( wp_create_nonce( 'mainwp_checkwp' ) ); ?>" />
527 </form>
528 </div>
529 <?php
530 }
531
532
533 /**
534 * Method mwp_setup_connect_first_site()
535 *
536 * Render Install first Child Site Step form.
537 *
538 * @uses MainWP_Manage_Sites_View::render_import_sites()
539 * @uses MainWP_Manage_Sites::mainwp_managesites_form_import_sites()
540 * @uses MainWP_Manage_Sites::mainwp_managesites_information_import_sites()
541 * @uses MainWP_Manage_Sites::render_import_sites_modal()
542 * @uses MainWP_Utility::show_mainwp_message()
543 */
544 public function mwp_setup_connect_first_site() {
545
546 $has_file_upload = isset( $_FILES['mainwp_managesites_file_bulkupload'] ) && isset( $_FILES['mainwp_managesites_file_bulkupload']['error'] ) && UPLOAD_ERR_OK === $_FILES['mainwp_managesites_file_bulkupload']['error'];
547 $has_import_data = ! empty( $_POST['mainwp_managesites_import'] );
548 ?>
549 <h1><?php esc_html_e( 'Connect Your First Child Site', 'mainwp' ); ?></h1>
550 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-qsw-add-site-message' ) ) { ?>
551 <div class="">
552 <p><?php esc_html_e( 'In the MainWP system, the sites you connect are referred to as "Child Sites."', 'mainwp' ); ?> <br/> <?php esc_html_e( 'These Child Sites will be managed centrally from your MainWP Dashboard.', 'mainwp' ); ?></p>
553 </div>
554 <?php } ?>
555
556 <div class="ui form">
557 <div class="ui hidden divider"></div>
558 <div class="ui hidden divider"></div>
559 <strong ><?php esc_html_e( 'Would you like to start with a single site or connect multiple sites to your MainWP Dashboard?', 'mainwp' ); ?></strong>
560 <div class="ui hidden divider"></div>
561 <div class="ui hidden divider"></div>
562 <div class="grouped fields mainwp-field-tab-connect">
563 <div class="field">
564 <div class="ui radio checkbox">
565 <input type="radio" name="tab_connect" tabindex="0" class="hidden" value="single-site">
566 <label for="tab_connect"><?php esc_html_e( 'Connect a Single Site', 'mainwp' ); ?></label>
567 </div>
568 </div>
569 <div class="field">
570 <div class="ui radio checkbox">
571 <input type="radio" name="tab_connect" tabindex="0" class="hidden" value="multiple-site">
572 <label for="tab_connect"><?php esc_html_e( 'Connect Multiple Sites', 'mainwp' ); ?></label>
573 </div>
574 </div>
575 </div>
576 </div>
577 <?php if ( ( $has_file_upload || $has_import_data ) && check_admin_referer( 'mainwp-admin-nonce' ) ) : ?>
578 <?php
579 $url = 'admin.php?page=mainwp-setup';
580 $url .= '&step=add_client';
581 MainWP_Manage_Sites::render_import_sites_modal( $url, 'Import Sites' );
582 ?>
583 <?php else : ?>
584 <form method="post" action="" class="ui form" enctype="multipart/form-data" id="mainwp_connect_first_site_form">
585 <div id="mainwp-qsw-connect-site-form" style="display:none">
586 <div class="ui hidden divider"></div>
587 <div class="ui hidden divider"></div>
588 <div class="ui message" id="mainwp-message-zone" style="display:none"></div>
589 <div class="ui red message" id="mainwp-error-zone" style="display:none"></div>
590 <div class="ui green message" id="mainwp-success-zone" style="display:none"></div>
591 <div class="ui info message" id="mainwp-info-zone" style="display:none"></div>
592 <div class="ui hidden divider"></div>
593 <div class="ui top attached tabular menu menu-connect-first-site">
594 <a class="item active" data-tab="single-site"><?php esc_html_e( 'Connect a Single Site', 'mainwp' ); ?></a>
595 <a class="item" data-tab="multiple-site"><?php esc_html_e( 'Connect Multiple Sites', 'mainwp' ); ?></a>
596 </div>
597 <div class="ui bottom attached tab segment active" data-tab="single-site">
598 <div class="ui secondary">
599 <div class="ui hidden divider"></div>
600 <div class="ui hidden divider"></div>
601 <div class="ui horizontal left aligned divider"><?php esc_html_e( 'Required Fields', 'mainwp' ); ?></div>
602 <div class="ui hidden divider"></div>
603 <div class="ui hidden divider"></div>
604 <div class="field">
605 <label for="mainwp_managesites_add_wpurl_protocol"><?php esc_html_e( 'What is the site URL? ', 'mainwp' ); ?></label>
606 <div class="ui left action input">
607 <select class="ui compact selection dropdown" id="mainwp_managesites_add_wpurl_protocol" name="mainwp_managesites_add_wpurl_protocol" style="width:120px;padding:0px;">
608 <option value="https">https://</option>
609 <option value="http">http://</option>
610 </select>
611 <input type="text" id="mainwp_managesites_add_wpurl" name="mainwp_managesites_add_wpurl" value="" placeholder="yoursite.com" />
612 </div>
613 </div>
614 <div class="field">
615 <label for="mainwp_managesites_add_wpadmin"><?php esc_html_e( 'What is your administrator username on that site? ', 'mainwp' ); ?></label>
616 <input type="text" id="mainwp_managesites_add_wpadmin" name="mainwp_managesites_add_wpadmin" value="" />
617 </div>
618 <div class="field">
619 <label for=""><?php esc_html_e( 'Choose your connection authentication method:', 'mainwp' ); ?></label>
620 <div class="ui hidden fitted divider"></div>
621 <div class="ui toggle checked checkbox not-auto-init" id="addsite-adminpwd" style="margin-right:2em;">
622 <input type="checkbox" id="mainwp-administrator-password-checkbox-field" checked=""><label><?php esc_html_e( 'Administrator password', 'mainwp' ); ?></label>
623 </div>
624 <div class="ui toggle checkbox not-auto-init" id="addsite-uniqueid">
625 <input type="checkbox" id="mainwp-unique-security-id-checkbox-field"><label><?php esc_html_e( 'Unique Security ID', 'mainwp' ); ?></label>
626 </div>
627 </div>
628 <div class="ui hidden fitted divider"></div>
629 <div class="ui fluid accordion" id="mainwp-connection-authentication-accordion" style="margin-top:1em">
630 <div class="title">
631 <i class="dropdown icon"></i>
632 <?php esc_html_e( 'Connection authentication methods explained', 'mainwp' ); ?>
633 </div>
634 <div class="content">
635 <span class="ui text"><?php esc_html_e( 'Choose options based on your MainWP Child plugin setup on the WordPress site you want to connect.', 'mainwp' ); ?></span>
636 <div class="ui bulleted small list">
637 <div class="item"><?php esc_html_e( 'Default Setup: Use only the Password field if you haven\'t changed the default settings.', 'mainwp' ); ?></div>
638 <div class="item"><?php esc_html_e( 'Advanced Setup: If you\'ve turned off all verification on the child site, switch off both fields.', 'mainwp' ); ?></div>
639 </div>
640 <span class="ui text"><?php esc_html_e( 'Use the sliders to control the fields shown:', 'mainwp' ); ?></span>
641 <div class="ui bulleted small list">
642 <div class="item"><?php esc_html_e( 'Password On: Displays the Password field.', 'mainwp' ); ?></div>
643 <div class="item"><?php esc_html_e( 'Security Key On: Displays the Security Key field.', 'mainwp' ); ?></div>
644 <div class="item"><?php esc_html_e( 'Both On: Displays both fields.', 'mainwp' ); ?></div>
645 <div class="item"><?php esc_html_e( 'Both Off: Hides both fields.', 'mainwp' ); ?></div>
646 </div>
647 <span class="ui text"><strong><?php esc_html_e( 'This needs to match what is set on your child site. Default is Administrator password.', 'mainwp' ); ?></strong></span>
648 </div>
649 </div>
650 <div class="ui hidden fitted divider"></div>
651 <div class="ui hidden fitted divider"></div>
652 <div class="field" id="mainwp-administrator-password-field">
653 <label for="mainwp_managesites_add_admin_pwd"><?php esc_html_e( 'What is your administrator password on that site?', 'mainwp' ); ?></label>
654 <input type="password" id="mainwp_managesites_add_admin_pwd" name="mainwp_managesites_add_admin_pwd" value="" />
655 </div>
656 <div class="field" id="mainwp-unique-security-id-field" style="display:none" >
657 <label for="mainwp_managesites_add_uniqueId"><?php esc_html_e( 'Did you generate unique security ID on the site? If yes, copy it here, if not, leave this field blank. ', 'mainwp' ); ?></label>
658 <input type="text" id="mainwp_managesites_add_uniqueId" name="mainwp_managesites_add_uniqueId" value="" />
659 </div>
660 <div class="field">
661 <label for="mainwp_managesites_add_wpname"><?php esc_html_e( 'Add site title. If left blank URL is used.', 'mainwp' ); ?></label>
662 <input type="text" id="mainwp_managesites_add_wpname" name="mainwp_managesites_add_wpname" value="" />
663 </div>
664 </div>
665 </div>
666 <div class="ui bottom attached tab segment" data-tab="multiple-site">
667 <div class="mainwp-wish-to-csv mainwp-wish-to-migrate">
668 <div class="ui blue message"><?php MainWP_Manage_Sites::mainwp_managesites_information_import_sites( true ); ?></div>
669 <?php MainWP_Manage_Sites::mainwp_managesites_form_import_sites(); ?>
670 <div class="ui hidden divider"></div>
671 <div class="ui hidden divider"></div>
672 <div class="ui hidden divider"></div>
673 <div class="ui hidden divider"></div>
674 <div class="ui horizontal left aligned divider">
675 <?php esc_attr_e( 'or upload csv file', 'mainwp' ); ?>
676 </div>
677 <div class="ui hidden divider"></div>
678 <div class="ui hidden divider"></div>
679 <div class="ui hidden divider"></div>
680 <div class="ui hidden divider"></div>
681 <div class="field">
682 <label for="mainwp_managesites_file_bulkupload"><?php esc_html_e( 'Upload the CSV file', 'mainwp' ); ?> (<a href="<?php echo esc_url( MAINWP_PLUGIN_URL . 'assets/csv/sample.csv' ); ?>"><?php esc_html_e( 'Download sample CSV file' ); ?></a>)</label>
683 <div class="ui grid">
684 <div class="eight wide middle aligned column" data-tooltip="<?php esc_attr_e( 'Click to upload the import file.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
685 <div class="ui file input">
686 <input type="file" name="mainwp_managesites_file_bulkupload" id="connect_first_site_file_bulkupload" accept="text/comma-separated-values" />
687 </div>
688 </div>
689 <div class="eight wide middle aligned column">
690 <div class="ui toggle checkbox ten wide middle aligned column" data-tooltip="<?php esc_attr_e( 'Enable if the import file contains a header.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
691 <input type="checkbox" name="mainwp_managesites_chk_header_first" checked="checked" id="managesites_chk_header_first" value="1" /> <label for="mainwp_managesites_chk_header_first"><?php esc_html_e( 'CSV file contains a header', 'mainwp' ); ?></label>
692 </div>
693 </div>
694 </div>
695 </div>
696 <div class="ui hidden divider"></div>
697 </div>
698 </div>
699 </div>
700 <div class="ui clearing hidden divider"></div>
701 <div class="ui hidden divider"></div>
702 <div class="ui hidden divider"></div>
703 <?php wp_nonce_field( 'mwp-setup' ); ?>
704 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
705 <input type="hidden" id="nonce_secure_data" mainwp_addwp="<?php echo esc_js( wp_create_nonce( 'mainwp_addwp' ) ); ?>" mainwp_checkwp="<?php echo esc_attr( wp_create_nonce( 'mainwp_checkwp' ) ); ?>" />
706 <div class="ui grid">
707 <div class="row">
708 <div class="three wide column">
709 <a href="<?php echo esc_url( $this->get_back_step_link() ); ?>" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
710 </div>
711 <div class="ten wide column middle aligned">
712 <div class="ui toggle checkbox" id="mainwp-qsw-toggle-verify-mainwp-child-active" style="display:none">
713 <input type="checkbox" name="mainwp-qsw-verify-mainwp-child-active" id="mainwp-qsw-verify-mainwp-child-active" >
714 <label for="mainwp-qsw-verify-mainwp-child-active" ><?php esc_html_e( 'Confirm that the MainWP Child plugin is activated on the site(s) you wish to connect.', 'mainwp' ); ?></label>
715 </div>
716 </div>
717 <div class="three wide column">
718 <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" id="mainwp_addsite_continue_button" class="ui big green right floated button"><?php esc_html_e( 'Continue', 'mainwp' ); ?></a>
719 <input type="button" style="display:none" name="mainwp_managesites_add" id="mainwp_managesites_add" class="ui button green big right floated" value="<?php esc_attr_e( 'Connect Site', 'mainwp' ); ?>" disabled />
720 <input type="button" style="display:none" name="mainwp_managesites_add_import" id="mainwp_managesites_add_import" class="ui button green big right floated" value="<?php esc_attr_e( 'Connect Sites', 'mainwp' ); ?>" disabled />
721 </div>
722 </div>
723 </div>
724
725 </form>
726 <?php endif; ?>
727 <script>
728 jQuery('.menu-connect-first-site .item').tab({
729 'onVisible': function() {
730 mainwp_menu_connect_first_site_onvisible_callback(this);
731 }
732 });
733 </script>
734 <?php
735 MainWP_Manage_Sites::render_add_site_scripts();
736 }
737
738 /**
739 * Method mwp_setup_add_client()
740 *
741 * Render Add first Client Step form.
742 */
743 public function mwp_setup_add_client() {
744 $count_clients = MainWP_DB_Client::instance()->count_total_clients();
745 $sites = MainWP_DB::instance()->get_sites(); // Get site data.
746 $total_sites = ! empty( $sites ) ? count( $sites ) : 5; // Set default.
747 $item_class_active = 1 === $total_sites ? 'active' : '';
748 $tab_class_active = 1 < $total_sites ? 'active' : '';
749 if ( ! empty( $count_clients ) ) :
750 ?>
751 <h1 class="ui header"><?php esc_html_e( 'Congratulations!', 'mainwp' ); ?></h1>
752 <p><?php esc_html_e( 'You have successfully created your first Client.', 'mainwp' ); ?></p>
753 <?php else : ?>
754 <?php $first_site_id = get_transient( 'mainwp_transient_just_connected_site_id' ); ?>
755 <h1><?php esc_html_e( 'Create a Client', 'mainwp' ); ?></h1>
756 <form action="" method="post" enctype="multipart/form-data" name="createclient_form" id="createclient_form" class="add:clients: validate">
757 <div class="ui red message" id="mainwp-message-zone" style="display:none"></div>
758 <div class="ui message" id="mainwp-message-zone-client" style="display:none;"></div>
759 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
760 <div class="ui top attached tabular menu mainwp-qsw-add-client">
761 <a class="item <?php echo esc_attr( $item_class_active ); ?>" data-tab="single-client"><?php esc_html_e( 'Single Client', 'mainwp' ); ?></a>
762 <a class="item <?php echo esc_attr( $tab_class_active ); ?>" data-tab="multiple-client"><?php esc_html_e( 'Multiple Clients', 'mainwp' ); ?></a>
763 </div>
764
765 <div class="ui bottom attached tab segment <?php echo esc_attr( $item_class_active ); ?>" data-tab="single-client">
766 <div class="ui hidden divider"></div>
767
768 <div id="mainwp-add-new-client-form" >
769 <?php $this->render_add_client_content( false, true ); ?>
770 </div>
771 <input type="hidden" name="selected_first_site" value="<?php echo intval( $first_site_id ); ?>">
772 </div>
773 <div class="ui bottom attached tab segment <?php echo esc_attr( $tab_class_active ); ?>" data-tab="multiple-client">
774 <div class="ui blue message">
775 <div><?php esc_html_e( 'For each site you’ve imported, please enter the Client Name and Client Email.', 'mainwp' ); ?></div>
776 <div><?php esc_html_e( 'If the same client name and email are used across multiple sites, those sites will be merged and assigned to a single client profile.', 'mainwp' ); ?></div>
777 <div><strong><?php esc_html_e( 'You can always update or edit this information later from the Clients module in your MainWP Dashboard.', 'mainwp' ); ?></strong></div>
778 </div>
779 <div class="ui mainwp-widget segment">
780 <div class="ui middle aligned left aligned compact grid">
781 <div class="ui row">
782 <div class="five wide column" >
783 <span class="ui text small"><strong><?php esc_html_e( 'Client Site URL (required)', 'mainwp' ); ?></strong></span>
784 </div>
785 <div class="five wide column">
786 <span class="ui text small"><strong><?php esc_html_e( 'Client Name (required)', 'mainwp' ); ?></strong></span>
787 </div>
788 <div class="five wide column">
789 <span class="ui text small"><strong><?php esc_html_e( 'Client Email (required)', 'mainwp' ); ?></strong></span>
790 </div>
791 <div class="one wide column">
792 <span></span>
793 </div>
794 </div>
795 <?php
796 for ( $i = 0; $i < $total_sites; $i++ ) {
797 $website = isset( $sites[ $i ] ) ? $sites[ $i ] : array();
798 $this->render_multi_add_client_content( $i, $website );
799 }
800 ?>
801 </div>
802 </div>
803 </div>
804 </form>
805 <div class="ui clearing hidden divider"></div>
806 <?php endif; ?>
807 <div class="ui hidden divider"></div>
808 <div class="ui hidden divider"></div>
809 <input type="button" style="display:none" name="createclient" current-page="qsw-add" id="bulk_add_createclient" class="ui big green right floated button" value="<?php echo esc_attr__( 'Add Client', 'mainwp' ); ?> "/>
810
811 <input type="button" style="display:none" name="create_multi_client" current-page="qsw-add" id="bulk_add_multi_create_client" class="ui big green right floated button" value="<?php echo esc_attr__( 'Add Clients', 'mainwp' ); ?> "/>
812
813 <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" id="mainwp_qsw_add_client_continue_button" class="ui big green right floated button"><?php esc_html_e( 'Continue', 'mainwp' ); ?></a>
814 <a href="<?php echo esc_url( $this->get_back_step_link() ); ?>" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
815 <script>
816 jQuery('.mainwp-qsw-add-client .item').tab({
817 'onVisible': function() {
818 mainwp_add_client_onvisible_callback(this);
819 }
820 });
821 </script>
822 <?php
823 }
824
825 /**
826 * Method render_add_client_content().
827 *
828 * Renders add client content window.
829 */
830 public function render_add_client_content() {
831 $edit_client = false;
832 $client_id = 0;
833 $default_client_fields = MainWP_Client_Handler::get_mini_default_client_fields();
834 $first_site_id = get_transient( 'mainwp_transient_just_connected_site_id' );
835 $website = MainWP_DB::instance()->get_website_by_id( $first_site_id );
836 ?>
837 <div class="ui form">
838 <?php if ( $first_site_id ) : ?>
839 <div class="field">
840 <label><?php esc_html_e( 'Client Site URL', 'mainwp' ); ?></label>
841 <div class="ui disabled fluid input">
842 <input type="text" value="<?php echo esc_url( $website->url ); ?>" />
843 </div>
844 </div>
845 <?php endif; ?>
846 <?php
847 foreach ( $default_client_fields as $field_name => $field ) {
848 $db_field = isset( $field['db_field'] ) ? $field['db_field'] : '';
849 $val = $edit_client && '' !== $db_field && property_exists( $edit_client, $db_field ) ? $edit_client->{$db_field} : '';
850 $tip = isset( $field['tooltip'] ) ? $field['tooltip'] : '';
851 ?>
852 <div class="field">
853 <label <?php echo '' !== $tip ? 'data-tooltip="' . esc_attr( $tip ) . '" data-inverted="" data-position="top left"' : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?> for="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]"><?php echo esc_html( $field['title'] ); ?></label>
854 <input type="text" value="<?php echo esc_html( $val ); ?>" id="mainwp_qsw_client_name_field" class="regular-text" name="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]"/>
855 </div>
856 <?php
857
858 if ( 'client.email' === $field_name ) {
859 ?>
860 <div class="field">
861 <label><?php esc_html_e( 'Client photo', 'mainwp' ); ?></label>
862 <div data-tooltip="<?php esc_attr_e( 'Upload a client photo.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
863 <div class="ui file input">
864 <input type="file" name="mainwp_client_image_uploader[client_field]" accept="image/*" data-inverted="" data-tooltip="<?php esc_attr_e( "Image must be 500KB maximum. It will be cropped to 310px wide and 70px tall. For best results us an image of this site. Allowed formats: jpeg, gif and png. Note that animated gifs aren't going to be preserved.", 'mainwp' ); ?>" />
865 </div>
866 </div>
867 </div>
868 <?php
869 }
870 }
871 $temp = $this->get_add_contact_temp( false );
872 ?>
873 <div class="field">
874 <a href="javascript:void(0);" class="mainwp-client-add-contact" add-contact-temp="<?php echo esc_attr( $temp ); ?>"><i class="ui eye icon"></i><?php esc_html_e( 'Add Additional Contact', 'mainwp' ); ?></a>
875 </div>
876 <div class="ui section hidden divider after-add-contact-field"></div>
877 </div>
878 <input type="hidden" name="client_fields[client_id]" value="<?php echo intval( $client_id ); ?>">
879 <?php
880 }
881
882 /**
883 * Method render_multi_add_client_content()
884 *
885 * Render form multi create client.
886 *
887 * @uses MainWP_Client_Handler::get_mini_default_contact_fields()
888 *
889 * @param int $index row index.
890 * @param array $website website data.
891 */
892 public function render_multi_add_client_content( $index, $website ) {
893 $contact_fields = MainWP_Client_Handler::get_mini_default_contact_fields();
894 ?>
895 <div class="row mainwp-qsw-add-client-rows" id="mainwp-qsw-add-client-row-<?php echo esc_attr( $index ); ?>">
896 <div class="five wide column">
897 <div class="ui mini fluid input">
898 <input type="text" name="mainwp_add_client[<?php echo esc_attr( $index ); ?>][site_url]" class="mainwp-qsw-add-client-site-url" value="<?php echo isset( $website['url'] ) ? esc_attr( $website['url'] ) : ''; ?>" data-row-index="<?php echo esc_attr( $index ); ?>" id="mainwp-qsw-add-client-site-url-<?php echo esc_attr( $index ); ?>" <?php echo isset( $website['id'] ) ? 'disabled' : ''; ?>>
899 <?php if ( isset( $website['id'] ) ) : ?>
900 <input type="hidden" name="mainwp_add_client[<?php echo esc_attr( $index ); ?>][website_id]" value="<?php echo intval( $website['id'] ); ?>" id="mainwp-qsw-add-client-website-id-<?php echo esc_attr( $index ); ?>" >
901 <?php endif ?>
902 </div>
903 </div>
904 <div class="five wide column">
905 <div class="ui mini fluid input">
906 <input type="text" name="mainwp_add_client[<?php echo esc_attr( $index ); ?>][client_name]" class="mainwp-qsw-add-client-client-name" value="" data-row-index="<?php echo esc_attr( $index ); ?>" id="mainwp-qsw-add-client-client-name-<?php echo esc_attr( $index ); ?>">
907 </div>
908 </div>
909 <div class="five wide column">
910 <div class="ui mini fluid input">
911 <input type="email" name="mainwp_add_client[<?php echo esc_attr( $index ); ?>][client_email]" class="mainwp-qsw-add-client-client-email" value="" data-row-index="<?php echo esc_attr( $index ); ?>" id="mainwp-qsw-add-client-client-email-<?php echo esc_attr( $index ); ?>">
912 </div>
913 </div>
914 <div class="one wide column">
915 <div class="ui mini fluid input">
916 <a class="mainwp-qsw-add-client-more-row" onclick="mainwp_qsw_add_client_more_row(<?php echo esc_attr( $index ); ?>)" style="margin-right: 10px !important;">
917 <i class="eye outline icon" id="icon-visible-<?php echo esc_attr( $index ); ?>"></i>
918 <i class="eye slash outline icon" id="icon-hidden-<?php echo esc_attr( $index ); ?>" style="display:none"></i>
919 </a>
920 <a class="mainwp-qsw-add-client-delete-row" href="javascript:void(0)" onclick="mainwp_qsw_add_client_delete_row(<?php echo esc_attr( $index ); ?>)">
921 <i class="trash alternate outline icon"></i>
922 </a>
923 </div>
924 </div>
925 <?php if ( ! empty( $contact_fields ) ) : ?>
926 <?php foreach ( $contact_fields as $field_name => $field ) : ?>
927 <div class="five wide column mainwp-qsw-add-client-column-more-<?php echo esc_attr( $index ); ?>" style="display:none">
928 <span class="ui small text"><?php echo esc_html( $field['title'] ); ?></span>
929 <div class="ui mini fluid input">
930 <input type="text" name="client_fields[<?php echo esc_attr( $index ); ?>][new_contacts_field][<?php echo esc_attr( $field_name ); ?>][]" class="mainwp-qsw-add-client-client-fields">
931 </div>
932 </div>
933 <?php endforeach; ?>
934 <?php endif; ?>
935 </div>
936 <?php
937 }
938
939 /**
940 * Method get_add_contact_temp().
941 *
942 * Get add contact template.
943 *
944 * @param bool $echo_out Echo template or not.
945 */
946 public function get_add_contact_temp( $echo_out = false ) {
947
948 $input_name = 'new_contacts_field';
949 $contact_id = 0;
950 ob_start();
951 ?>
952 <div class="ui hidden divider top-contact-fields"></div> <?php // must have class: top-contact-fields. ?>
953 <div class="ui left aligned horizontal divider"><?php esc_html_e( 'Add Contact', 'mainwp' ); ?></div>
954 <div class="ui hidden divider"></div>
955 <div class="ui hidden divider"></div>
956 <?php
957 $contact_fields = MainWP_Client_Handler::get_mini_default_contact_fields();
958 foreach ( $contact_fields as $field_name => $field ) {
959 $val = '';
960 $contact_id = '';
961 ?>
962 <div class="field">
963 <label><?php echo esc_html( $field['title'] ); ?></label>
964 <input type="text" value="<?php echo esc_html( $val ); ?>" class="regular-text" name="client_fields[<?php echo esc_html( $input_name ); ?>][<?php echo esc_attr( $field_name ); ?>][]"/>
965 </div>
966 <?php
967 }
968 ?>
969 <div class="field remove-contact-field-parent">
970 <a href="javascript:void(0);" contact-id="<?php echo intval( $contact_id ); ?>" class="mainwp-client-remove-contact"><i class="ui eye icon"></i><?php esc_html_e( 'Remove contact', 'mainwp' ); ?></a>
971 </div>
972 <div class="ui section hidden divider bottom-contact-fields"></div>
973 <?php
974 $html = ob_get_clean();
975 if ( $echo_out ) {
976 echo $html; //phpcs:ignore -- validated content.
977 }
978 return $html;
979 }
980
981 /**
982 * Method mwp_setup_monitoring()
983 *
984 * Render Monitoring Step.
985 */
986 public function mwp_setup_monitoring() {
987
988 $disableSitesHealthMonitoring = get_option( 'mainwp_disableSitesHealthMonitoring', 1 );
989 $sitehealthThreshold = get_option( 'mainwp_sitehealthThreshold', 80 ); // "Should be improved" threshold.
990
991 $global_settings = MainWP_Uptime_Monitoring_Handle::get_global_monitoring_settings();
992
993 $glo_active = 0;
994 if ( isset( $global_settings['active'] ) ) {
995 $glo_active = 1 === (int) $global_settings['active'] ? 1 : 0;
996 }
997
998 ?>
999 <h1 class="ui header">
1000 <?php esc_html_e( 'Uptime Monitoring', 'mainwp' ); ?>
1001 </h1>
1002 <div><?php esc_html_e( 'The MainWP Uptime Monitoring function periodically sends HTTP requests to your child sites, based on a chosen frequency from every 5 minutes to once daily, to check their operational status. It uses a direct cURL request to obtain an HTTP Header response, alerting you via email if a site fails to return a Status Code 200 (OK). This feature operates independently of third-party services, providing a straightforward and no-cost option for uptime monitoring across all your managed sites. However, it does not diagnose the specific nature of errors leading to site unavailability.', 'mainwp' ); ?></div>
1003 <div class="ui hidden divider"></div>
1004 <div class="ui hidden divider"></div>
1005 <form method="post" class="ui form">
1006 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
1007
1008 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-monitor-general" default-indi-value="0">
1009 <label class="six wide column middle aligned">
1010 <?php
1011 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_setup_enableUptimeMonitoring', (int) $glo_active, true, 0 );
1012 esc_html_e( 'Enable Uptime Monitoring', 'mainwp' );
1013 ?>
1014 </label>
1015 <div class="ten wide column ui toggle checkbox mainwp-checkbox-showhide-elements" hide-parent="uptime-monitoring">
1016 <input type="checkbox" value="1" class="settings-field-value-change-handler" name="mainwp_setup_enableUptimeMonitoring" id="mainwp_setup_enableUptimeMonitoring" <?php echo 1 === (int) $glo_active ? 'checked="true"' : ''; ?>/>
1017 </div>
1018 </div>
1019
1020 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-monitor-general" default-indi-value="60" <?php echo $glo_active ? '' : 'style="display:none"'; ?> hide-element="uptime-monitoring">
1021 <label class="six wide column middle aligned">
1022 <?php
1023 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_setup_monitor_interval_hidden', (int) $global_settings['interval'], true, 60 );
1024 esc_html_e( 'Monitor Interval (minutes)', 'mainwp' );
1025 ?>
1026 </label>
1027 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set Monitor Interval.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
1028 <div class="ui labeled ticked slider settings-field-value-change-handler" id="mainwp_setup_monitor_interval_slider"></div>
1029 <input type="hidden" name="mainwp_setup_monitor_interval_hidden" class="settings-field-value-change-handler" id="mainwp_setup_monitor_interval_hidden" value="<?php echo intval( $global_settings['interval'] ); ?>" />
1030 </div>
1031 </div>
1032
1033 <h1 class="ui header">
1034 <?php esc_html_e( 'Site Health Monitoring', 'mainwp' ); ?>
1035 </h1>
1036 <div><?php esc_html_e( "The MainWP Site Health Monitoring feature integrates with WordPress 5.1's Site Health tool, providing centralized notifications regarding the health status of your child sites. It allows you to choose between being notified for any status changes or only when the health drops below the 'Good' threshold, ensuring you're informed about crucial security and performance metrics.", 'mainwp' ); ?></div>
1037 <div class="ui hidden divider"></div>
1038 <div class="ui hidden divider"></div>
1039 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="1">
1040 <label class="six wide column middle aligned">
1041 <?php
1042 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_disableSitesHealthMonitoring', (int) $disableSitesHealthMonitoring );
1043 esc_html_e( 'Enable Site Health monitoring', 'mainwp' );
1044 ?>
1045 </label>
1046 <div class="ten wide column ui toggle checkbox mainwp-checkbox-showhide-elements" hide-parent="health-monitoring" style="max-width:100px !important;">
1047 <input type="checkbox" class="settings-field-value-change-handler" inverted-value="1" name="mainwp_setup_disable_sitesHealthMonitoring" id="mainwp_setup_disable_sitesHealthMonitoring" <?php echo 1 === (int) $disableSitesHealthMonitoring ? '' : 'checked="true"'; ?>/>
1048 </div>
1049 </div>
1050
1051 <div class="ui grid field settings-field-indicator-wrapper" default-indi-value="80" <?php echo $disableSitesHealthMonitoring ? 'style="display:none"' : ''; ?> hide-element="health-monitoring">
1052 <label class="six wide column middle aligned">
1053 <?php
1054 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_sitehealthThreshold', (int) $sitehealthThreshold );
1055 esc_html_e( 'Site health threshold', 'mainwp' );
1056 ?>
1057 </label>
1058 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Set preferred site health threshold.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
1059 <select name="mainwp_setup_site_healthThreshold" id="mainwp_setup_site_healthThreshold" class="ui dropdown settings-field-value-change-handler">
1060 <option value="80" <?php echo 80 === $sitehealthThreshold || 0 === $sitehealthThreshold ? 'selected' : ''; ?>><?php esc_html_e( 'Should be improved', 'mainwp' ); ?></option>
1061 <option value="100" <?php echo 100 === $sitehealthThreshold ? 'selected' : ''; ?>><?php esc_html_e( 'Good', 'mainwp' ); ?></option>
1062 </select>
1063 </div>
1064 </div>
1065 <div class="ui hidden divider"></div>
1066 <div class="ui hidden divider"></div>
1067 <input type="submit" class="ui big green right floated button" value="<?php esc_attr_e( 'Continue', 'mainwp' ); ?>" name="save_step" />
1068 <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="ui big button"><?php esc_html_e( 'Skip', 'mainwp' ); ?></a>
1069 <a href="<?php echo esc_url( $this->get_back_step_link() ); ?>" class="ui big basic green button"><?php esc_html_e( 'Back', 'mainwp' ); ?></a>
1070
1071 <?php wp_nonce_field( 'mwp-setup' ); ?>
1072 </form>
1073
1074 <script type="text/javascript">
1075 <?php
1076 $all_intervals = MainWP_Uptime_Monitoring_Edit::get_interval_values( false );
1077 echo 'var interval_label = ' . wp_json_encode( array_values( $all_intervals ) ) . ";\n";
1078 echo 'var interval_values = ' . wp_json_encode( array_keys( $all_intervals ) ) . ";\n";
1079 ?>
1080 jQuery('#mainwp_setup_monitor_interval_slider').slider({
1081 interpretLabel: function(value) {
1082 return interval_label[value];
1083 },
1084 autoAdjustLabels: false,
1085 min: 0,
1086 smooth: true,
1087 restrictedLabels: [interval_label[0],interval_label[<?php echo count( $all_intervals ) - 1; ?>]],
1088 showThumbTooltip: true,
1089 tooltipConfig: {
1090 position: 'bottom center',
1091 variation: 'small visible black'
1092 },
1093 max: <?php echo count( $all_intervals ) - 1; ?>,
1094 onChange: function(value) {
1095 jQuery('#mainwp_setup_monitor_interval_hidden').val(interval_values[value]).change();
1096 },
1097 onMove: function(value) {
1098 jQuery(this).find('.thumb').attr('data-tooltip', interval_label[value]);
1099 }
1100 });
1101 jQuery('#mainwp_setup_monitor_interval_slider').slider('set value', interval_values.indexOf(<?php echo intval( $global_settings['interval'] ); ?>));
1102 </script>
1103
1104 <?php
1105 }
1106
1107 /**
1108 * Method mwp_setup_monitoring_save()
1109 *
1110 * Save Monitoring form data.
1111 *
1112 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
1113 */
1114 public function mwp_setup_monitoring_save() {
1115 check_admin_referer( 'mwp-setup' );
1116 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1117
1118 $global_settings = MainWP_Uptime_Monitoring_Handle::get_global_monitoring_settings();
1119 $global_settings['active'] = ! empty( $_POST['mainwp_setup_enableUptimeMonitoring'] ) ? 1 : 0;
1120 $global_settings['interval'] = isset( $_POST['mainwp_setup_monitor_interval_hidden'] ) ? intval( $_POST['mainwp_setup_monitor_interval_hidden'] ) : 60;
1121
1122 MainWP_Uptime_Monitoring_Handle::update_uptime_global_settings( $global_settings );
1123
1124 MainWP_Utility::update_option( 'mainwp_disableSitesHealthMonitoring', ( ! isset( $_POST['mainwp_setup_disable_sitesHealthMonitoring'] ) ? 1 : 0 ) );
1125 $val = isset( $_POST['mainwp_setup_site_healthThreshold'] ) ? intval( $_POST['mainwp_setup_site_healthThreshold'] ) : 80;
1126 MainWP_Utility::update_option( 'mainwp_sitehealthThreshold', $val );
1127 // phpcs:enable
1128 wp_safe_redirect( $this->get_next_step_link() );
1129 exit;
1130 }
1131
1132 /**
1133 * Method mwp_setup_ready()
1134 *
1135 * Render MainWP Dashboard ready message.
1136 */
1137 public function mwp_setup_ready() {
1138 ?>
1139 <div class="ui hidden divider"></div>
1140 <div class="ui hidden divider"></div>
1141 <h1 class="ui icon header" style="display:block">
1142 <i class="thumbs up outline icon"></i>
1143 <div class="content">
1144 <?php esc_html_e( 'Your MainWP Dashboard is Ready!', 'mainwp' ); ?>
1145 <div class="sub header"><?php esc_html_e( 'Congratulations! Now you are ready to start managing your WordPress sites.', 'mainwp' ); ?></div>
1146 <div class="ui hidden divider"></div>
1147 <a class="ui massive green button" href="<?php echo esc_url( admin_url( 'admin.php?page=mainwp_tab' ) ); ?>"><?php esc_html_e( 'Start Managing Your Sites', 'mainwp' ); ?></a>
1148 </div>
1149 </h1>
1150 <div class="ui hidden divider"></div>
1151 <div class="ui hidden divider"></div>
1152 <?php
1153 }
1154
1155 /**
1156 * Render usetiful tours.
1157 */
1158 public static function mainwp_usetiful_tours() {
1159 echo "
1160 <script>
1161 (function (w, d, s) {
1162 let a = d.getElementsByTagName('head')[0];
1163 let r = d.createElement('script');
1164 r.async = 1;
1165 r.src = s;
1166 r.setAttribute('id', 'usetifulScript');
1167 r.dataset.token = '480fa17b0507a1c60abba94bfdadd0a7';
1168 a.appendChild(r);
1169 })(window, document, 'https://www.usetiful.com/dist/usetiful.js');</script>
1170 ";
1171 }
1172 }
1173