PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.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 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-system.php

class-mainwp-system.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.1, at class/class-mainwp-system.php

1,023 lines 32.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP System.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Defines MainWP Twitter Max Seconds.
12 *
13 * @const ( string ) 60 * 5
14 * @source https://github.com/mainwp/mainwp/blob/master/cron/bootstrap.php
15 */
16 define( 'MAINWP_TWITTER_MAX_SECONDS', 60 * 5 );
17
18 const MAINWP_VIEW_PER_SITE = 1;
19 const MAINWP_VIEW_PER_PLUGIN_THEME = 0;
20 const MAINWP_VIEW_PER_GROUP = 2;
21
22 // phpcs:disable WordPress.WP.AlternativeFunctions -- for custom read/write file.
23
24 /**
25 * Class MainWP_System
26 *
27 * @package MainWP\Dashboard
28 */
29 class MainWP_System {
30
31 /**
32 * Public static variable to hold the current plugin version.
33 *
34 * @var string Current plugin version.
35 */
36 public static $version = '4.1';
37
38 /**
39 * Private static variable to hold the single instance of the class.
40 *
41 * @var mixed Default null
42 */
43 private static $instance = null;
44
45 /**
46 * Public variable to hold the Metaboxes array.
47 *
48 * @var array Metaboxes.
49 */
50 public $metaboxes;
51
52 /**
53 * Private variable to hold the current version.
54 *
55 * @var string The plugin current version.
56 */
57 private $current_version = null;
58
59 /**
60 * Private variable to hold the plugin slug (mainwp/mainwp.php)
61 *
62 * @var string Plugin slug.
63 */
64 private $plugin_slug;
65
66 /**
67 * Method instance()
68 *
69 * Create a public static instance.
70 *
71 * @static
72 * @return MainWP_System
73 */
74 public static function instance() {
75 return self::$instance;
76 }
77
78 /**
79 * MainWP_System constructor.
80 *
81 * Runs any time class is called.
82 *
83 * @param string $mainwp_plugin_file Plugn slug.
84 */
85 public function __construct( $mainwp_plugin_file ) {
86 self::$instance = $this;
87 $this->load_all_options();
88 $this->update();
89 $this->plugin_slug = plugin_basename( $mainwp_plugin_file );
90
91 if ( is_admin() ) {
92 include_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php';
93 $pluginData = get_plugin_data( $mainwp_plugin_file );
94 $this->current_version = $pluginData['Version'];
95 $currentVersion = get_option( 'mainwp_plugin_version' );
96
97 if ( ! empty( $currentVersion ) && version_compare( $currentVersion, '4.0', '<' ) && version_compare( $this->current_version, '4.0', '>=' ) ) {
98 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'mainwp_4_update_notice' ) );
99 }
100
101 MainWP_Utility::update_option( 'mainwp_plugin_version', $this->current_version );
102 }
103
104 if ( ! defined( 'MAINWP_VERSION' ) ) {
105
106 /**
107 * Defines MainWP Version.
108 *
109 * @const ( string )
110 * @source https://code-reference.mainwp.com/classes/MainWP.Dashboard.MainWP_System.html
111 */
112 define( 'MAINWP_VERSION', $this->current_version );
113 }
114
115 $ssl_api_verifyhost = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( get_option( 'mainwp_api_sslVerifyCertificate' ) == 1 ) ) ? 1 : 0;
116 if ( 0 == $ssl_api_verifyhost ) {
117 add_filter(
118 'http_request_args',
119 array(
120 MainWP_Extensions_Handler::get_class_name(),
121 'no_ssl_filter_extension_upgrade',
122 ),
123 99,
124 2
125 );
126 }
127
128 MainWP_Extensions::init();
129
130 $systemHandler = MainWP_System_Handler::instance();
131
132 add_action( 'parse_request', array( &$this, 'parse_request' ) );
133 add_action( 'init', array( &$this, 'localization' ) );
134 add_filter( 'site_transient_update_plugins', array( $systemHandler, 'check_update_custom' ) );
135 add_filter( 'pre_set_site_transient_update_plugins', array( $systemHandler, 'pre_check_update_custom' ) );
136 add_filter( 'plugins_api', array( $systemHandler, 'plugins_api_info' ), 10, 3 );
137
138 $this->metaboxes = new MainWP_Meta_Boxes();
139
140 MainWP_Overview::get();
141
142 MainWP_Manage_Sites::init();
143 new MainWP_Hooks();
144 new MainWP_Menu();
145
146 add_action( 'admin_menu', array( MainWP_Menu::get_class_name(), 'init_mainwp_menus' ) );
147 add_filter( 'admin_footer', array( &$this, 'admin_footer' ), 15 );
148 add_action( 'admin_head', array( MainWP_System_View::get_class_name(), 'admin_head' ) );
149 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_styles' ) );
150 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
151 add_action( 'admin_body_class', array( MainWP_System_View::get_class_name(), 'admin_body_class' ) );
152
153 new MainWP_Bulk_Post();
154
155 add_action( 'admin_init', array( &$this, 'admin_init' ), 20 );
156 add_action( 'after_setup_theme', array( &$this, 'after_setup_theme' ) );
157
158 add_action( 'init', array( &$this, 'parse_init' ) );
159 add_action( 'init', array( &$this, 'init' ), 9999 );
160 add_action( 'admin_init', array( $this, 'admin_redirects' ) );
161 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
162 add_action( 'login_form', array( &$this, 'login_form_redirect' ) );
163 add_action( 'admin_print_styles', array( MainWP_System_View::get_class_name(), 'admin_print_styles' ) );
164
165 MainWP_Install_Bulk::init();
166
167 MainWP_System_Cron_Jobs::instance()->init_cron_jobs();
168
169 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'admin_notices' ) );
170 add_action( 'admin_notices', array( MainWP_System_View::get_class_name(), 'wp_admin_notices' ) );
171 add_action( 'wp_mail_failed', array( &$this, 'wp_mail_failed' ) );
172
173 add_action( 'after_plugin_row', array( MainWP_System_View::get_class_name(), 'after_extensions_plugin_row' ), 10, 3 );
174
175 add_filter( 'mainwp-activated-check', array( &$this, 'activated_check' ) ); // @deprecated Use 'mainwp_activated_check' instead.
176 add_filter( 'mainwp_activated_check', array( &$this, 'activated_check' ) );
177
178 do_action_deprecated( 'mainwp-activated', array(), '4.0.7.2', 'mainwp_activated' ); // @deprecated Use 'mainwp_activated' instead.
179
180 /**
181 * Action: mainwp_activated
182 *
183 * Fires upon MainWP plugin activation.
184 *
185 * @since Unknown
186 */
187 do_action( 'mainwp_activated' );
188
189 MainWP_Updates::init();
190 MainWP_Post::init();
191 MainWP_Settings::init();
192 if ( get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
193 MainWP_Manage_Backups::init();
194 }
195 MainWP_User::init();
196 MainWP_Page::init();
197 MainWP_Themes::init();
198 MainWP_Plugins::init();
199 MainWP_Updates_Overview::init();
200 if ( defined( 'WP_CLI' ) && WP_CLI ) {
201 MainWP_WP_CLI_Command::init();
202 }
203 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
204 if ( isset( $_GET['mainwp_run'] ) && ! empty( $_GET['mainwp_run'] ) ) {
205 add_action( 'init', array( MainWP_System_Cron_Jobs::instance(), 'cron_active' ), PHP_INT_MAX );
206 }
207 }
208 add_action( 'mainwp_admin_footer', array( MainWP_UI::get_class_name(), 'usersnap_integration' ) );
209 }
210
211 /**
212 * Method load_all_options()
213 *
214 * Load all wp_options data.
215 *
216 * @return array $alloptions Array of all options.
217 */
218 public function load_all_options() {
219
220 /**
221 * WordPress Database instance.
222 *
223 * @global object $wpdb
224 */
225 global $wpdb;
226
227 if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
228 $alloptions = wp_cache_get( 'alloptions', 'options' );
229 } else {
230 $alloptions = false;
231 }
232
233 if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
234 $notoptions = wp_cache_get( 'notoptions', 'options' );
235 } else {
236 $notoptions = false;
237 }
238
239 if ( ! isset( $alloptions['mainwp_db_version'] ) ) {
240 $suppress = $wpdb->suppress_errors();
241 $options = array(
242 'mainwp_db_version',
243 'mainwp_plugin_version',
244 'mainwp_upgradeVersionInfo',
245 'mainwp_extensions',
246 'mainwp_activated',
247 'mainwp_api_sslVerifyCertificate',
248 'mainwp_automaticDailyUpdate',
249 'mainwp_backup_before_upgrade',
250 'mainwp_enableLegacyBackupFeature',
251 'mainwp_hide_twitters_message',
252 'mainwp_maximumInstallUpdateRequests',
253 'mainwp_maximumSyncRequests',
254 'mainwp_primaryBackup',
255 'mainwp_refresh',
256 'mainwp_security',
257 'mainwp_use_favicon',
258 'mainwp_wp_cron',
259 'mainwp_timeDailyUpdate',
260 'mainwp_frequencyDailyUpdate',
261 'mainwp_wpcreport_extension',
262 'mainwp_daily_digest_plain_text',
263 'mainwp_enable_managed_cr_for_wc',
264 'mainwp_hide_update_everything',
265 'mainwp_show_usersnap',
266 'mainwp_number_overview_columns',
267 'mainwp_disable_update_confirmations',
268 'mainwp_settings_hide_widgets',
269 'mainwp_settings_hide_manage_sites_columns',
270 'mainwp_disableSitesChecking',
271 'mainwp_disableSitesHealthMonitoring',
272 'mainwp_frequencySitesChecking',
273 'mainwp_sitehealthThreshold',
274 'mainwp_updatescheck_frequency_today_count',
275 'mainwp_settings_notification_emails',
276 'mainwp_ignore_HTTP_response_status',
277 'mainwp_check_http_response',
278 'mainwp_setup_important_notification',
279 );
280
281 $query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
282 foreach ( $options as $option ) {
283 $query .= "'" . $option . "', ";
284 }
285 $query = substr( $query, 0, strlen( $query ) - 2 );
286 $query .= ")"; // phpcs:ignore -- ignore double quotes auto-correction.
287 $alloptions_db = $wpdb->get_results( $query ); // phpcs:ignore -- unprepared SQL ok.
288 $wpdb->suppress_errors( $suppress );
289 if ( ! is_array( $alloptions ) ) {
290 $alloptions = array();
291 }
292 if ( is_array( $alloptions_db ) ) {
293 foreach ( (array) $alloptions_db as $o ) {
294 $alloptions[ $o->option_name ] = $o->option_value;
295 unset( $options[ array_search( $o->option_name, $options ) ] );
296 }
297 foreach ( $options as $option ) {
298 $notoptions[ $option ] = true;
299 }
300 if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
301 wp_cache_set( 'alloptions', $alloptions, 'options' );
302 wp_cache_set( 'notoptions', $notoptions, 'options' );
303 }
304 }
305 }
306
307 return $alloptions;
308 }
309
310 /**
311 * Method parse_request()
312 *
313 * Includes api.php.
314 */
315 public function parse_request() {
316 include_once MAINWP_PLUGIN_DIR . 'includes/api.php';
317 }
318
319 /**
320 * Method localization()
321 *
322 * Loads plugin language files.
323 */
324 public function localization() {
325 load_plugin_textdomain( 'mainwp', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
326 }
327
328 /**
329 * Method wp_mail_failed()
330 *
331 * Check if there has been a wp mail failer.
332 *
333 * @param string $error Array of error messages.
334 */
335 public function wp_mail_failed( $error ) {
336 $mail_failed = get_option( 'mainwp_notice_wp_mail_failed' );
337 if ( is_object( $error ) && empty( $mail_failed ) ) {
338 MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'yes' );
339 $er = $error->get_error_message();
340 if ( ! empty( $er ) ) {
341 MainWP_Logger::instance()->debug( 'Error :: wp_mail :: [error=' . $er . ']' );
342 }
343 }
344 }
345
346 /**
347 * Method get_version()
348 *
349 * Get current plugin version.
350 *
351 * @return string Current plugin version.
352 */
353 public function get_version() {
354 return $this->current_version;
355 }
356
357 /**
358 * Method mainwp_cronpingchilds_action()
359 *
360 * Run cron ping childs action.
361 */
362 public function mainwp_cronpingchilds_action() {
363 MainWP_System_Cron_Jobs::instance()->cron_ping_childs();
364 }
365
366 /**
367 * Method mainwp_cronbackups_continue_action()
368 *
369 * Run cron backups continue action.
370 */
371 public function mainwp_cronbackups_continue_action() {
372 MainWP_System_Cron_Jobs::instance()->cron_backups_continue();
373 }
374
375 /**
376 * Method mainwp_cronbackups_action()
377 *
378 * Run cron backups action.
379 */
380 public function mainwp_cronbackups_action() {
381 MainWP_System_Cron_Jobs::instance()->cron_backups();
382 }
383
384 /**
385 * Method mainwp_cronstats_action()
386 *
387 * Run cron stats action.
388 */
389 public function mainwp_cronstats_action() {
390 MainWP_System_Cron_Jobs::instance()->cron_stats();
391 }
392
393 /**
394 * Method mainwp_cronupdatescheck_action()
395 *
396 * Run cron updates check action.
397 */
398 public function mainwp_cronupdatescheck_action() {
399 MainWP_System_Cron_Jobs::instance()->cron_updates_check();
400 }
401
402 /**
403 * Method mainwp_croncheckstatus_action()
404 *
405 * Run cron check sites status action.
406 */
407 public function mainwp_croncheckstatus_action() {
408 MainWP_System_Cron_Jobs::instance()->cron_check_websites_status();
409 }
410
411 /**
412 * Method mainwp_cronchecksitehealth_action()
413 *
414 * Run cron check sites health action.
415 */
416 public function mainwp_cronchecksitehealth_action() {
417 MainWP_System_Cron_Jobs::instance()->cron_check_websites_health();
418 }
419
420 /**
421 * Method is_mainwp_pages()
422 *
423 * Get the current page and check it for "mainwp_".
424 *
425 * @return boolean ture|false.
426 */
427 public static function is_mainwp_pages() {
428 $screen = get_current_screen();
429 if ( $screen && strpos( $screen->base, 'mainwp_' ) !== false && strpos( $screen->base, 'mainwp_child_tab' ) === false ) {
430 return true;
431 }
432
433 return false;
434 }
435
436 /**
437 * Method init()
438 *
439 * Instantiate Plugin.
440 */
441 public function init() {
442
443 /**
444 * MainWP disabled menu items array.
445 *
446 * @global object $_mainwp_disable_menus_items
447 */
448 global $_mainwp_disable_menus_items;
449
450 $_mainwp_disable_menus_items = apply_filters( 'mainwp_disablemenuitems', $_mainwp_disable_menus_items );
451
452 /**
453 * Filter: mainwp_main_menu_disable_menu_items
454 *
455 * Filters disabled MainWP navigation items.
456 *
457 * @since Unknown
458 */
459 $_mainwp_disable_menus_items = apply_filters( 'mainwp_main_menu_disable_menu_items', $_mainwp_disable_menus_items );
460
461 if ( ! function_exists( 'MainWP\Dashboard\mainwp_current_user_have_right' ) ) {
462
463 /**
464 * Method mainwp_current_user_have_right()
465 *
466 * Check permission level by hook mainwp_currentusercan of Team Control extension.
467 *
468 * @param string $cap_type group or type of capabilities.
469 * @param string $cap capabilities for current user.
470 *
471 * @return bool true|false
472 */
473 function mainwp_current_user_have_right( $cap_type = '', $cap ) {
474
475 /**
476 * Current user global.
477 *
478 * @global string
479 */
480 global $current_user;
481
482 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
483 return true;
484 }
485
486 if ( defined( 'WP_CLI' ) && WP_CLI ) {
487 return true;
488 }
489
490 if ( empty( $current_user ) ) {
491 if ( ! function_exists( 'wp_get_current_user' ) ) {
492 require_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'pluggable.php';
493 }
494 }
495
496 return apply_filters( 'mainwp_currentusercan', true, $cap_type, $cap );
497 }
498 }
499
500 MainWP_System_Handler::instance()->handle_settings_post();
501 }
502
503 /**
504 * Method parse_init()
505 *
506 * Initiate plugin installation & then run the Quick Setup Wizard.
507 */
508 public function parse_init() {
509 if ( isset( $_GET['mwpdl'] ) && isset( $_GET['sig'] ) ) {
510 $mwpDir = MainWP_System_Utility::get_mainwp_dir();
511 $mwpDir = $mwpDir[0];
512 $mwpdl = isset( $_REQUEST['mwpdl'] ) ? wp_unslash( $_REQUEST['mwpdl'] ) : '';
513 $file = trailingslashit( $mwpDir ) . rawurldecode( $mwpdl );
514
515 if ( stristr( rawurldecode( $mwpdl ), '..' ) ) {
516 return;
517 }
518
519 $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system();
520
521 /**
522 * WordPress files system object.
523 *
524 * @global object
525 */
526 global $wp_filesystem;
527
528 if ( $hasWPFileSystem && $wp_filesystem->exists( $file ) && md5( filesize( $file ) ) == $_GET['sig'] ) {
529 MainWP_System_Handler::instance()->upload_file( $file );
530 exit();
531 }
532 } elseif ( isset( $_GET['page'] ) ) {
533 if ( MainWP_System_Utility::is_admin() ) {
534 switch ( $_GET['page'] ) {
535 case 'mainwp-setup':
536 new MainWP_Setup_Wizard();
537 break;
538 }
539 }
540 }
541 }
542
543 /**
544 * Method login_form_redirect()
545 *
546 * Login redirect.
547 */
548 public function login_form_redirect() {
549
550 /**
551 * Redirect to global.
552 *
553 * @global string $redirect_to
554 */
555 global $redirect_to;
556 if ( ! isset( $_GET['redirect_to'] ) ) {
557 $redirect_to = get_admin_url() . 'index.php';
558 }
559 }
560
561 /**
562 * Method after_setup_theme()
563 *
564 * After setup theme hook, to support post thumbnails.
565 */
566 public function after_setup_theme() {
567 add_theme_support( 'post-thumbnails' );
568 }
569
570 /**
571 * Method admin_init()
572 *
573 * Do nothing if current user is not an Admin else display the page.
574 */
575 public function admin_init() {
576 if ( ! MainWP_System_Utility::is_admin() ) {
577 return;
578 }
579
580 add_action( 'mainwp_activate_extention', array( MainWP_System_Handler::instance(), 'activate_extension' ), 10, 2 ); // @deprecated Use 'mainwp_activate_extension' instead.
581 add_action( 'mainwp_deactivate_extention', array( MainWP_System_Handler::instance(), 'deactivate_extension' ), 10, 1 ); // @deprecated Use 'mainwp_deactivate_extension' instead.
582
583 add_action( 'mainwp_activate_extension', array( MainWP_System_Handler::instance(), 'activate_extension' ), 10, 2 );
584 add_action( 'mainwp_deactivate_extension', array( MainWP_System_Handler::instance(), 'deactivate_extension' ), 10, 1 );
585
586 /**
587 * MainWP use external primary backup method.
588 *
589 * @global string
590 */
591 global $mainwpUseExternalPrimaryBackupsMethod;
592
593 if ( null === $mainwpUseExternalPrimaryBackupsMethod ) {
594 $return = '';
595
596 /*
597 * @deprecated Use 'mainwp_getprimarybackup_activated' instead.
598 *
599 */
600 $return = apply_filters_deprecated( 'mainwp-getprimarybackup-activated', array( $return ), '4.0.7.2', 'mainwp_getprimarybackup_activated' );
601 $mainwpUseExternalPrimaryBackupsMethod = apply_filters( 'mainwp_getprimarybackup_activated', $return );
602 }
603
604 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'mainwp_warning_notice' ) );
605
606 MainWP_Post_Handler::instance()->init();
607 MainWP_Post_Site_Handler::instance()->init();
608 MainWP_Post_Plugin_Theme_Handler::instance()->init();
609 MainWP_Post_Extension_Handler::instance()->init();
610 MainWP_Post_Backup_Handler::instance()->init();
611
612 /**
613 * Filter: mainwp_ui_use_wp_calendar
614 *
615 * Filters whether default jQuery datepicker should be used to avoid potential problems with Senatic UI Calendar library.
616 *
617 * @since 4.0.5
618 */
619 $use_wp_datepicker = apply_filters( 'mainwp_ui_use_wp_calendar', false );
620 if ( $use_wp_datepicker ) {
621 wp_enqueue_script( 'jquery-ui-datepicker' );
622 }
623 wp_enqueue_script( 'jquery-ui-dialog' );
624 wp_enqueue_style( 'jquery-ui-style', MAINWP_PLUGIN_URL . 'assets/css/1.11.1/jquery-ui.min.css', array(), '1.11.1' );
625
626 $en_params = array( 'jquery-ui-dialog' );
627 if ( $use_wp_datepicker ) {
628 $en_params[] = 'jquery-ui-datepicker';
629 }
630 if ( self::is_mainwp_pages() ) {
631 $en_params[] = 'jquery-migrate';
632 }
633 wp_enqueue_script( 'mainwp', MAINWP_PLUGIN_URL . 'assets/js/mainwp.js', $en_params, $this->current_version, true );
634
635 $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
636 $primaryBackup = get_option( 'mainwp_primaryBackup' );
637 $disable_backup_checking = ( empty( $enableLegacyBackupFeature ) && empty( $primaryBackup ) ) ? true : false;
638
639 $mainwpParams = array(
640 'image_url' => MAINWP_PLUGIN_URL . 'assets/images/',
641 'backup_before_upgrade' => ( get_option( 'mainwp_backup_before_upgrade' ) == 1 ),
642 'disable_checkBackupBeforeUpgrade' => $disable_backup_checking,
643 'admin_url' => admin_url(),
644 'use_wp_datepicker' => $use_wp_datepicker ? 1 : 0,
645 'date_format' => get_option( 'date_format' ),
646 'time_format' => get_option( 'time_format' ),
647 'enabledTwit' => MainWP_Twitter::enabled_twitter_messages(),
648 'maxSecondsTwit' => MAINWP_TWITTER_MAX_SECONDS,
649 'installedBulkSettingsManager' => is_plugin_active( 'mainwp-bulk-settings-manager/mainwp-bulk-settings-manager.php' ) ? 1 : 0,
650 'maximumSyncRequests' => ( get_option( 'mainwp_maximumSyncRequests' ) === false ) ? 8 : get_option( 'mainwp_maximumSyncRequests' ),
651 'maximumInstallUpdateRequests' => ( get_option( 'mainwp_maximumInstallUpdateRequests' ) === false ) ? 3 : get_option( 'mainwp_maximumInstallUpdateRequests' ),
652 );
653 wp_localize_script( 'mainwp', 'mainwpParams', $mainwpParams );
654
655 $mainwpTranslations = MainWP_System_View::get_mainwp_translations();
656
657 wp_localize_script( 'mainwp', 'mainwpTranslations', $mainwpTranslations );
658
659 $security_nonces = MainWP_Post_Handler::instance()->get_security_nonces();
660
661 $nonces_filter = apply_filters( 'mainwp_security_nonces', array() );
662
663 if ( is_array( $nonces_filter ) && ! empty( $nonces_filter ) ) {
664 $security_nonces = array_merge( $security_nonces, $nonces_filter );
665 }
666
667 wp_localize_script( 'mainwp', 'security_nonces', $security_nonces );
668
669 wp_enqueue_script( 'thickbox' );
670 wp_enqueue_script( 'user-profile' );
671 wp_enqueue_style( 'thickbox' );
672
673 if ( isset( $_GET['page'] ) && ( 'mainwp_tab' === $_GET['page'] || ( 'managesites' === $_GET['page'] ) && isset( $_GET['dashboard'] ) ) ) {
674 wp_enqueue_script( 'dragula', MAINWP_PLUGIN_URL . 'assets/js/dragula/dragula.min.js', array(), $this->current_version, true );
675 wp_enqueue_style( 'dragula', MAINWP_PLUGIN_URL . 'assets/js/dragula/dragula.min.css', array(), $this->current_version );
676 }
677
678 if ( isset( $_GET['page'] ) && ( 'managesites' === $_GET['page'] || 'MonitoringSites' === $_GET['page'] ) ) {
679 wp_enqueue_script( 'dragula', MAINWP_PLUGIN_URL . 'assets/js/preview.js', array(), $this->current_version, true );
680 wp_enqueue_style( 'dragula', MAINWP_PLUGIN_URL . 'assets/css/preview.css', array(), $this->current_version );
681 }
682
683 $this->init_session();
684
685 if ( ! current_user_can( 'update_core' ) ) {
686 remove_action( 'admin_notices', 'update_nag', 3 );
687 }
688 }
689
690 /**
691 * Method admin_redirects()
692 *
693 * MainWP admin redirects.
694 */
695 public function admin_redirects() {
696 if ( ( defined( 'DOING_CRON' ) && DOING_CRON ) || defined( 'DOING_AJAX' ) ) {
697 return;
698 }
699
700 if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'mainwp-setup' ) ) ) {
701 return;
702 }
703
704 $quick_setup = get_option( 'mainwp_run_quick_setup', false );
705 if ( 'yes' === $quick_setup ) {
706 wp_safe_redirect( admin_url( 'admin.php?page=mainwp-setup' ) );
707 exit;
708 }
709
710 if ( 'yes' === get_option( 'mainwp_activated' ) ) {
711 delete_option( 'mainwp_activated' );
712 wp_cache_delete( 'mainwp_activated', 'options' );
713 wp_cache_delete( 'alloptions', 'options' );
714 wp_safe_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
715
716 return;
717 }
718
719 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
720 $_pos = strlen( $request_uri ) - strlen( '/wp-admin/' );
721 if ( ! empty( $request_uri ) && strpos( $request_uri, '/wp-admin/' ) !== false && strpos( $request_uri, '/wp-admin/' ) == $_pos ) {
722 if ( mainwp_current_user_have_right( 'dashboard', 'access_global_dashboard' ) ) {
723 wp_safe_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
724 die();
725 }
726 }
727 }
728
729 /**
730 * Method init_session()
731 *
732 * Chck witch page & initiate a session.
733 */
734 public function init_session() {
735 if ( isset( $_GET['page'] ) && in_array(
736 $_GET['page'],
737 array(
738 'PostBulkManage',
739 'PageBulkManage',
740 'PluginsManage',
741 'PluginsAutoUpdate',
742 'ThemesManage',
743 'ThemesAutoUpdate',
744 'UserBulkManage',
745 )
746 )
747 ) {
748 MainWP_Cache::init_session();
749 }
750 }
751
752 /**
753 * Method admin_enqueue_scripts()
754 *
755 * Enqueue all Mainwp Admin Scripts.
756 *
757 * @param mixed $hook Enqueue hook.
758 */
759 public function admin_enqueue_scripts( $hook ) {
760
761 $load_cust_scripts = false;
762
763 /**
764 * Current pagenow.
765 *
766 * @global string
767 */
768 global $pagenow;
769
770 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
771 $load_cust_scripts = true;
772 }
773
774 if ( self::is_mainwp_pages() ) {
775 wp_enqueue_script( 'mainwp-updates', MAINWP_PLUGIN_URL . 'assets/js/mainwp-updates.js', array(), $this->current_version, true );
776 wp_enqueue_script( 'mainwp-managesites-action', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-action.js', array(), $this->current_version, true );
777 wp_enqueue_script( 'mainwp-managesites-update', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-update.js', array(), $this->current_version, true );
778 wp_enqueue_script( 'mainwp-managesites-import', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-import.js', array(), $this->current_version, true );
779 wp_enqueue_script( 'mainwp-plugins-themes', MAINWP_PLUGIN_URL . 'assets/js/mainwp-plugins-themes.js', array(), $this->current_version, true );
780 wp_enqueue_script( 'mainwp-backups', MAINWP_PLUGIN_URL . 'assets/js/mainwp-backups.js', array(), $this->current_version, true );
781 wp_enqueue_script( 'mainwp-posts', MAINWP_PLUGIN_URL . 'assets/js/mainwp-posts.js', array(), $this->current_version, true );
782 wp_enqueue_script( 'mainwp-users', MAINWP_PLUGIN_URL . 'assets/js/mainwp-users.js', array(), $this->current_version, true );
783 wp_enqueue_script( 'mainwp-extensions', MAINWP_PLUGIN_URL . 'assets/js/mainwp-extensions.js', array(), $this->current_version, true );
784 wp_enqueue_script( 'mainwp-moment', MAINWP_PLUGIN_URL . 'assets/js/moment/moment.min.js', array(), $this->current_version, true );
785 wp_enqueue_script( 'semantic', MAINWP_PLUGIN_URL . 'assets/js/semantic-ui/semantic.min.js', array( 'jquery' ), $this->current_version, false );
786 wp_enqueue_script( 'semantic-ui-datatables', MAINWP_PLUGIN_URL . 'assets/js/datatables/datatables.min.js', array( 'jquery' ), $this->current_version, false );
787 wp_enqueue_script( 'semantic-ui-datatables-colreorder', MAINWP_PLUGIN_URL . 'assets/js/colreorder/dataTables.colReorder.js', array( 'jquery' ), $this->current_version, false );
788 wp_enqueue_script( 'semantic-ui-datatables-scroller', MAINWP_PLUGIN_URL . 'assets/js/scroller/scroller.dataTables.js', array( 'jquery' ), $this->current_version, false );
789 wp_enqueue_script( 'semantic-ui-datatables-fixedcolumns', MAINWP_PLUGIN_URL . 'assets/js/fixedcolumns/dataTables.fixedColumns.js', array( 'jquery' ), $this->current_version, false );
790 wp_enqueue_script( 'semantic-ui-calendar', MAINWP_PLUGIN_URL . 'assets/js/calendar/calendar.min.js', array( 'jquery' ), $this->current_version, true );
791 wp_enqueue_script( 'semantic-ui-hamburger', MAINWP_PLUGIN_URL . 'assets/js/hamburger/hamburger.js', array( 'jquery' ), $this->current_version, true );
792
793 /**
794 * WordPress version.
795 *
796 * @global string
797 */
798 global $wp_version;
799
800 if ( version_compare( $wp_version, '5.5', '>=' ) ) {
801 wp_enqueue_script( 'jquery-migrate', MAINWP_PLUGIN_URL . 'assets/js/jquery-migrate.min.js', array(), $this->current_version, true );
802 }
803 }
804
805 if ( $load_cust_scripts ) {
806 wp_enqueue_script( 'semantic', MAINWP_PLUGIN_URL . 'assets/js/semantic-ui/semantic.min.js', array( 'jquery' ), $this->current_version, true );
807 }
808
809 wp_enqueue_script( 'mainwp-ui', MAINWP_PLUGIN_URL . 'assets/js/mainwp-ui.js', array(), $this->current_version, true );
810 wp_enqueue_script( 'mainwp-js-popup', MAINWP_PLUGIN_URL . 'assets/js/mainwp-popup.js', array(), $this->current_version, true );
811 wp_enqueue_script( 'mainwp-fileuploader', MAINWP_PLUGIN_URL . 'assets/js/fileuploader.js', array(), $this->current_version ); // phpcs:ignore -- fileuploader scripts need to load at header.
812 wp_enqueue_script( 'mainwp-date', MAINWP_PLUGIN_URL . 'assets/js/date.js', array(), $this->current_version, true );
813 wp_enqueue_script( 'mainwp-filesaver', MAINWP_PLUGIN_URL . 'assets/js/FileSaver.js', array(), $this->current_version, true );
814 wp_enqueue_script( 'mainwp-jqueryfiletree', MAINWP_PLUGIN_URL . 'assets/js/jqueryFileTree.js', array(), $this->current_version, true );
815 }
816
817 /**
818 * Method admin_enqueue_styles()
819 *
820 * Enqueue all Mainwp Admin Styles.
821 *
822 * @param mixed $hook Enqueue hook.
823 */
824 public function admin_enqueue_styles( $hook ) {
825
826 wp_enqueue_style( 'mainwp', MAINWP_PLUGIN_URL . 'assets/css/mainwp.css', array(), $this->current_version );
827 wp_enqueue_style( 'mainwp-responsive-layouts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-responsive-layouts.css', array(), $this->current_version );
828
829 if ( isset( $_GET['hideall'] ) && 1 === $_GET['hideall'] ) {
830 remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
831 }
832
833 /**
834 * Current pagenow.
835 *
836 * @global string
837 */
838 global $pagenow;
839
840 $load_cust_scripts = false;
841 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
842 $load_cust_scripts = true;
843 }
844
845 if ( self::is_mainwp_pages() ) {
846 wp_enqueue_style( 'mainwp-filetree', MAINWP_PLUGIN_URL . 'assets/css/jqueryFileTree.css', array(), $this->current_version );
847 wp_enqueue_style( 'semantic', MAINWP_PLUGIN_URL . 'assets/js/semantic-ui/semantic.min.css', array(), $this->current_version );
848 wp_enqueue_style( 'semantic-mainwp', MAINWP_PLUGIN_URL . 'assets/css/mainwp-semantic.css', array(), $this->current_version );
849 wp_enqueue_style( 'semantic-ui-datatables', MAINWP_PLUGIN_URL . 'assets/js/datatables/datatables.min.css', array(), $this->current_version );
850 wp_enqueue_style( 'semantic-ui-datatables-colreorder', MAINWP_PLUGIN_URL . 'assets/js/colreorder/colReorder.semanticui.css', array(), $this->current_version );
851 wp_enqueue_style( 'semantic-ui-datatables-scroller', MAINWP_PLUGIN_URL . 'assets/js/scroller/scroller.dataTables.css', array(), $this->current_version );
852 wp_enqueue_style( 'semantic-ui-calendar', MAINWP_PLUGIN_URL . 'assets/js/calendar/calendar.min.css', array(), $this->current_version );
853 wp_enqueue_style( 'semantic-ui-hamburger', MAINWP_PLUGIN_URL . 'assets/js/hamburger/hamburger.css', array(), $this->current_version );
854 }
855
856 if ( $load_cust_scripts ) {
857 wp_enqueue_style( 'semantic', MAINWP_PLUGIN_URL . 'assets/js/semantic-ui/semantic.min.css', array(), $this->current_version );
858 }
859 }
860
861 /**
862 * Method admin_menu()
863 *
864 * Add Bulk Post/Pages menue.
865 */
866 public function admin_menu() {
867
868 /**
869 * Admin menu array.
870 *
871 * @global object
872 */
873 global $menu;
874
875 foreach ( $menu as $k => $item ) {
876 if ( 'edit.php?post_type=bulkpost' === $item[2] ) {
877 unset( $menu[ $k ] );
878 } elseif ( 'edit.php?post_type=bulkpage' === $item[2] ) {
879 unset( $menu[ $k ] );
880 }
881 }
882 }
883
884 /**
885 * Method enqueue_postbox_scripts()
886 *
887 * Enqueue postbox scripts.
888 */
889 public static function enqueue_postbox_scripts() {
890 wp_enqueue_script( 'common' );
891 wp_enqueue_script( 'wp-lists' );
892 wp_enqueue_script( 'postbox' );
893 }
894
895 /**
896 * Method admin_footer()
897 *
898 * Create MainWP admin footer.
899 */
900 public function admin_footer() {
901 if ( ! self::is_mainwp_pages() ) {
902 return;
903 }
904 if ( isset( $_GET['hideall'] ) && 1 === $_GET['hideall'] ) {
905 return;
906 }
907 $current_wpid = MainWP_System_Utility::get_current_wpid();
908 if ( $current_wpid ) {
909 $website = MainWP_DB::instance()->get_website_by_id( $current_wpid );
910 $websites = array( $website );
911 } else {
912 $is_staging = 'no';
913 if ( isset( $_GET['page'] ) ) {
914 if ( ( 'managesites' == $_GET['page'] ) && ! isset( $_GET['id'] ) && ! isset( $_GET['do'] ) && ! isset( $_GET['dashboard'] ) ) {
915 $group_ids = get_option( 'mainwp_managesites_filter_group' );
916 if ( ! empty( $group_ids ) ) {
917 $group_ids = explode( ',', $group_ids ); // convert to array.
918 }
919 if ( $group_ids ) {
920 $staging_group = get_option( 'mainwp_stagingsites_group_id' );
921 }
922 } elseif ( 'UpdatesManage' == $_GET['page'] || 'mainwp_tab' == $_GET['page'] ) {
923 $staging_enabled = is_plugin_active( 'mainwp-staging-extension/mainwp-staging-extension.php' ) ? true : false;
924 if ( $staging_enabled ) {
925 $staging_view = get_user_option( 'mainwp_staging_options_updates_view' ) == 'staging' ? true : false;
926 if ( $staging_view ) {
927 $is_staging = 'yes';
928 }
929 }
930 }
931 }
932 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp_sync.dtsSync DESC, wp.url ASC', false, false, null, false, array(), $is_staging ) );
933 }
934
935 MainWP_System_View::render_footer_content( $websites );
936 if ( empty( $current_wpid ) ) {
937 MainWP_DB::free_result( $websites );
938 }
939
940 MainWP_System_View::admin_footer();
941 MainWP_Menu::init_subpages_menu();
942
943 /**
944 * MainWP disabled menu items array.
945 *
946 * @global object
947 */
948 global $_mainwp_disable_menus_items;
949
950 $_mainwp_disable_menus_items = apply_filters( 'mainwp_all_disablemenuitems', $_mainwp_disable_menus_items );
951 }
952
953 /**
954 * Method activated_check()
955 *
956 * Activated check.
957 */
958 public function activated_check() {
959 MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
960 return $this->get_version();
961 }
962
963 /**
964 * Method activation()
965 *
966 * Activate MainWP.
967 */
968 public function activation() {
969 MainWP_Install::instance()->install();
970 MainWP_Utility::update_option( 'mainwp_activated', 'yes' );
971 }
972
973 /**
974 * Method deactivation()
975 *
976 * Deactivate MainWP.
977 */
978 public function deactivation() {
979 update_option( 'mainwp_extensions_all_activation_cached', '' );
980 }
981
982 /**
983 * Method update()
984 *
985 * Update MainWP.
986 */
987 public function update() {
988 MainWP_Install::instance()->install();
989 }
990
991 /**
992 * Method is_single_user()
993 *
994 * Check if single user environment.
995 *
996 * @return boolean true|false.
997 */
998 public function is_single_user() {
999 return true;
1000 }
1001
1002 /**
1003 * Method is_multi_user()
1004 *
1005 * Check if multi user environment.
1006 *
1007 * @return boolean true|false.
1008 */
1009 public function is_multi_user() {
1010 return ! $this->is_single_user();
1011 }
1012
1013 /**
1014 * Method get_plugin_slug()
1015 *
1016 * Get MainWP Plugin Slug.
1017 */
1018 public function get_plugin_slug() {
1019 return $this->plugin_slug;
1020 }
1021
1022 }
1023