PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.3.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.3.2
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 5.0.3.2, at class/class-mainwp-system.php

1,407 lines 50.4 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 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
11
12 const MAINWP_VIEW_PER_SITE = 1;
13 const MAINWP_VIEW_PER_PLUGIN_THEME = 0;
14 const MAINWP_VIEW_PER_GROUP = 2;
15
16 // phpcs:disable WordPress.WP.AlternativeFunctions -- for custom read/write file.
17
18 /**
19 * Class MainWP_System
20 *
21 * @package MainWP\Dashboard
22 */
23 class MainWP_System {
24
25 /**
26 * Public static variable to hold the current plugin version.
27 *
28 * @var string Current plugin version.
29 */
30 public static $version = '5.0.3.2'; // NOSONAR .
31
32 /**
33 * Private static variable to hold the single instance of the class.
34 *
35 * @var mixed Default null
36 */
37 private static $instance = null;
38
39 /**
40 * Public variable to hold the Metaboxes instance.
41 *
42 * @var object Metaboxes.
43 */
44 public $metaboxes;
45
46 /**
47 * Private variable to hold the current version.
48 *
49 * @var string The plugin current version.
50 */
51 private $current_version = null;
52
53
54 /**
55 * Private variable to hold the check update version number.
56 *
57 * @var string The plugin current update version.
58 */
59 private $check_ver_update = '0.0.5';
60
61 /**
62 * Private variable to hold the plugin slug (mainwp/mainwp.php)
63 *
64 * @var string Plugin slug.
65 */
66 private $plugin_slug;
67
68 /**
69 * Method instance()
70 *
71 * Create a public static instance.
72 *
73 * @static
74 * @return MainWP_System
75 */
76 public static function instance() {
77 return self::$instance;
78 }
79
80 /**
81 * MainWP_System constructor.
82 *
83 * Runs any time class is called.
84 *
85 * @param string $mainwp_plugin_file Plugn slug.
86 *
87 * @uses \MainWP\Dashboard\MainWP_Bulk_Post
88 * @uses \MainWP\Dashboard\MainWP_Hooks
89 * @uses \MainWP\Dashboard\MainWP_Menu::get_class_name()
90 * @uses \MainWP\Dashboard\MainWP_Menu
91 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes
92 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::init_cron_jobs()
93 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs
94 * @uses \MainWP\Dashboard\MainWP_System_Handler
95 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_class_name()
96 * @uses \MainWP\Dashboard\MainWP_System_View::get_class_name()
97 * @uses \MainWP\Dashboard\MainWP_UI::get_class_name()
98 * @uses \MainWP\Dashboard\MainWP_WP_CLI_Command::init()
99 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::init()
100 * @uses \MainWP\Dashboard\MainWP_Extensions::init()
101 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name()
102 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::init()
103 * @uses \MainWP\Dashboard\MainWP_Manage_Backups::init()
104 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::init()
105 * @uses \MainWP\Dashboard\MainWP_Overview::get()
106 * @uses \MainWP\Dashboard\MainWP_Page::init()
107 * @uses \MainWP\Dashboard\MainWP_Plugins::init()
108 * @uses \MainWP\Dashboard\MainWP_Post::init()
109 * @uses \MainWP\Dashboard\MainWP_Settings::init()
110 * @uses \MainWP\Dashboard\MainWP_Themes::init()
111 * @uses \MainWP\Dashboard\MainWP_Updates::init()
112 * @uses \MainWP\Dashboard\MainWP_User::init()
113 * @uses \MainWP\Dashboard\MainWP_Updates::init()
114 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
115 */
116 public function __construct( $mainwp_plugin_file ) {
117 self::$instance = $this;
118
119 MainWP_Execution_Helper::instance()->init_exec_time();
120
121 new MainWP_Includes();
122
123 MainWP_Keys_Manager::auto_load_files();
124
125 $this->load_all_options();
126
127 $this->update_install();
128 $this->plugin_slug = plugin_basename( $mainwp_plugin_file );
129
130 do_action( 'mainwp_system_init' );
131
132 // includes rest api work.
133 require 'class-mainwp-rest-api.php';
134 Rest_Api::instance()->init();
135
136 if ( is_admin() ) {
137 include_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php';
138 $pluginData = get_plugin_data( $mainwp_plugin_file, true, false ); // to fix issue of user language setting.
139 $this->current_version = $pluginData['Version'];
140 $currentVersion = get_option( 'mainwp_plugin_version' );
141
142 if ( ! empty( $currentVersion ) && version_compare( $currentVersion, '4.0', '<' ) && version_compare( $this->current_version, '4.0', '>=' ) ) {
143 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'mainwp_4_update_notice' ) );
144 }
145
146 if ( ! empty( $currentVersion ) && version_compare( $currentVersion, '5.0', '<' ) && version_compare( $this->current_version, '5.0', '>=' ) ) {
147 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'mainwp_ver5_update_notice' ) );
148 }
149
150 if ( ! empty( $currentVersion ) && version_compare( $currentVersion, '5.0.2', '<' ) && version_compare( $this->current_version, '5.0.2', '>=' ) ) {
151 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'mainwp_ver502_update_notice' ) );
152 }
153
154 MainWP_Utility::update_option( 'mainwp_plugin_version', $this->current_version );
155 }
156
157 if ( ! defined( 'MAINWP_VERSION' ) ) {
158
159 /**
160 * Defines MainWP Version.
161 *
162 * @const ( string )
163 * @source https://code-reference.mainwp.com/classes/MainWP.Dashboard.MainWP_System.html
164 */
165 define( 'MAINWP_VERSION', $this->current_version );
166 }
167
168 if ( get_option( 'mainwp_setting_demo_mode_enabled' ) ) {
169 if ( ! defined( 'MAINWP_DEMO_MODE' ) ) {
170 define( 'MAINWP_DEMO_MODE', true );
171 }
172 }
173
174 $ssl_api_verifyhost = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( 1 === (int) get_option( 'mainwp_api_sslVerifyCertificate' ) ) ) ? 1 : 0;
175 if ( empty( $ssl_api_verifyhost ) ) {
176 add_filter(
177 'http_request_args',
178 array(
179 MainWP_Extensions_Handler::get_class_name(),
180 'no_ssl_filter_extension_upgrade',
181 ),
182 99,
183 2
184 );
185 }
186
187 MainWP_Extensions::init();
188 MainWP_Extensions_Groups::init();
189
190 $systemHandler = MainWP_System_Handler::instance();
191
192 add_action( 'plugins_loaded', array( &$this, 'localization' ) );
193 add_filter( 'site_transient_update_plugins', array( $systemHandler, 'check_update_custom' ) );
194 add_filter( 'pre_set_site_transient_update_plugins', array( $systemHandler, 'pre_check_update_custom' ) );
195 add_filter( 'plugins_api', array( $systemHandler, 'plugins_api_extension_info' ), 10, 3 );
196 add_filter( 'plugins_api_result', array( $systemHandler, 'plugins_api_wp_plugins_api_result' ), 10, 3 );
197
198 $this->metaboxes = new MainWP_Meta_Boxes();
199
200 MainWP_Overview::get();
201 MainWP_Client_Overview::instance();
202
203 MainWP_Manage_Sites::init();
204 new MainWP_Hooks();
205 new MainWP_Menu();
206
207 add_action( 'admin_menu', array( MainWP_Menu::get_class_name(), 'init_mainwp_menus' ) );
208 add_filter( 'admin_footer', array( &$this, 'admin_footer' ), 15 );
209 add_action( 'admin_head', array( MainWP_System_View::get_class_name(), 'admin_head' ) );
210 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_styles' ) );
211 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
212 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts_fix_conflict' ), 9 );
213 add_action( 'admin_body_class', array( MainWP_System_View::get_class_name(), 'admin_body_class' ) );
214
215 new MainWP_Bulk_Post();
216
217 add_action( 'admin_init', array( &$this, 'admin_init' ), 20 );
218 add_action( 'admin_init', array( $this, 'hook_admin_update_check' ) );
219 add_action( 'after_setup_theme', array( &$this, 'after_setup_theme' ) );
220
221 add_action( 'init', array( &$this, 'parse_init' ) );
222 add_action( 'init', array( &$this, 'init' ), 9999 );
223 add_action( 'admin_init', array( $this, 'admin_redirects' ) );
224 add_action( 'current_screen', array( &$this, 'current_screen_redirects' ), 15 );
225 add_filter( 'plugin_action_links', array( $this, 'hook_plugin_action_links' ), 10, 4 );
226 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
227 add_action( 'admin_print_styles', array( MainWP_System_View::get_class_name(), 'admin_print_styles' ) );
228
229 add_action( 'wp_logout', array( &$this, 'clear_sessions' ) );
230
231 MainWP_Install_Bulk::init();
232
233 MainWP_System_Cron_Jobs::instance()->init_cron_jobs();
234
235 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'admin_notices' ) );
236 add_action( 'admin_notices', array( MainWP_System_View::get_class_name(), 'wp_admin_notices' ) );
237 add_action( 'wp_mail_failed', array( &$this, 'wp_mail_failed' ) );
238
239 add_action( 'after_plugin_row', array( MainWP_System_View::get_class_name(), 'after_extensions_plugin_row' ), 10, 3 );
240
241 add_filter( 'mainwp-activated-check', array( &$this, 'activated_check' ) ); // @deprecated Use 'mainwp_activated_check' instead.
242 add_filter( 'mainwp_activated_check', array( &$this, 'activated_check' ) );
243
244 do_action_deprecated( 'mainwp-activated', array(), '4.0.7.2', 'mainwp_activated' ); // @deprecated Use 'mainwp_activated' instead.
245
246 /**
247 * Action: mainwp_activated
248 *
249 * Fires upon MainWP plugin activation.
250 *
251 * @since Unknown
252 */
253 do_action( 'mainwp_activated' );
254
255 MainWP_Updates::init();
256 MainWP_Post::init();
257 MainWP_Settings::init();
258 if ( get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
259 MainWP_Manage_Backups::init();
260 }
261 MainWP_Manage_Groups::init();
262 MainWP_User::init();
263 MainWP_Page::init();
264 MainWP_Themes::init();
265 MainWP_Plugins::init();
266 MainWP_Updates_Overview::init();
267 MainWP_Client::init();
268 MainWP_Rest_Api_Page::init();
269 MainWP_Non_MainWP_Actions::instance();
270
271 if ( defined( 'WP_CLI' ) && WP_CLI ) {
272 MainWP_WP_CLI_Command::init();
273 }
274 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
275 if ( isset( $_GET['mainwp_run'] ) && 'test' === $_GET['mainwp_run'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
276 add_action( 'init', array( MainWP_System_Cron_Jobs::instance(), 'cron_active' ), PHP_INT_MAX );
277 }
278 }
279 }
280
281 /**
282 * Method get_dashboard_version()
283 *
284 * Get dashboard version.
285 *
286 * @return string $version Version.
287 */
288 public function get_dashboard_version() {
289 return self::$version;
290 }
291
292 /**
293 * Method load_all_options()
294 *
295 * Load all wp_options data.
296 *
297 * @return array $alloptions Array of all options.
298 */
299 public function load_all_options() {
300
301 /**
302 * WordPress Database instance.
303 *
304 * @global object $wpdb
305 */
306 global $wpdb;
307
308 if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
309 $alloptions = wp_cache_get( 'alloptions', 'options' );
310 } else {
311 $alloptions = false;
312 }
313
314 if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
315 $notoptions = wp_cache_get( 'notoptions', 'options' );
316 } else {
317 $notoptions = false;
318 }
319
320 if ( ! isset( $alloptions['mainwp_db_version'] ) ) {
321 $suppress = $wpdb->suppress_errors();
322 $options = array(
323 'mainwp_db_version',
324 'mainwp_plugin_version',
325 'mainwp_upgradeVersionInfo',
326 'mainwp_extensions',
327 'mainwp_activated',
328 'mainwp_api_sslVerifyCertificate',
329 'mainwp_automaticDailyUpdate',
330 'mainwp_backup_before_upgrade',
331 'mainwp_enableLegacyBackupFeature',
332 'mainwp_maximumInstallUpdateRequests',
333 'mainwp_maximumSyncRequests',
334 'mainwp_primaryBackup',
335 'mainwp_security',
336 'mainwp_use_favicon',
337 'mainwp_wp_cron',
338 'mainwp_timeDailyUpdate',
339 'mainwp_frequencyDailyUpdate',
340 'mainwp_delay_autoupdate',
341 'mainwp_wpcreport_extension',
342 'mainwp_daily_digest_plain_text',
343 'mainwp_hide_update_everything',
344 'mainwp_disable_update_confirmations',
345 'mainwp_settings_show_widgets',
346 'mainwp_clients_show_widgets',
347 'mainwp_settings_show_manage_sites_columns',
348 'mainwp_disableSitesChecking',
349 'mainwp_disableSitesHealthMonitoring',
350 'mainwp_frequencySitesChecking',
351 'mainwp_sitehealthThreshold',
352 'mainwp_settings_notification_emails',
353 'mainwp_ignore_HTTP_response_status',
354 'mainwp_check_http_response',
355 'mainwp_extmenu',
356 'mainwp_opensslLibLocation',
357 'mainwp_notice_wp_mail_failed',
358 'mainwp_show_language_updates',
359 'mainwp_logger_check_daily',
360 'mainwp_site_actions_notification_enable',
361 'mainwp_update_check_version',
362 'mainwp_setting_demo_mode_enabled',
363 'mainwp_log_wait_lasttime',
364 'mainwp_updatescheck_start_last_schedule_timestamp',
365 'mainwp_cron_license_deactivated_alert_lasttime',
366 );
367
368 $options = apply_filters( 'mainwp_init_load_all_options', $options );
369
370 $query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
371 foreach ( $options as $option ) {
372 $query .= "'" . $option . "', ";
373 }
374 $query = substr( $query, 0, strlen( $query ) - 2 );
375 $query .= ")"; // phpcs:ignore -- ignore double quotes auto-correction.
376 $alloptions_db = $wpdb->get_results( $query ); // phpcs:ignore -- unprepared SQL ok.
377 $wpdb->suppress_errors( $suppress );
378 if ( ! is_array( $alloptions ) ) {
379 $alloptions = array();
380 }
381 if ( is_array( $alloptions_db ) ) {
382 foreach ( (array) $alloptions_db as $o ) {
383 $alloptions[ $o->option_name ] = $o->option_value;
384 unset( $options[ array_search( $o->option_name, $options ) ] );
385 }
386 if ( ! is_array( $notoptions ) ) {
387 $notoptions = array();
388 }
389 foreach ( $options as $option ) {
390 $notoptions[ $option ] = true;
391 }
392 if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
393 wp_cache_set( 'alloptions', $alloptions, 'options' );
394 wp_cache_set( 'notoptions', $notoptions, 'options' );
395 }
396 }
397 }
398
399 return $alloptions;
400 }
401
402 /**
403 * Method localization()
404 *
405 * Loads plugin language files.
406 */
407 public function localization() {
408 $load = apply_filters( 'mainwp_load_text_domain', true );
409 if ( $load ) {
410 load_plugin_textdomain( 'mainwp', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
411 }
412 }
413
414 /**
415 * Method wp_mail_failed()
416 *
417 * Check if there has been a wp mail failer.
418 *
419 * @param string $error Array of error messages.
420 *
421 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
422 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
423 */
424 public function wp_mail_failed( $error ) {
425 $mail_failed = get_option( 'mainwp_notice_wp_mail_failed' );
426 if ( is_object( $error ) && empty( $mail_failed ) ) {
427 MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'yes' );
428 $er = $error->get_error_message();
429 if ( ! empty( $er ) ) {
430 MainWP_Logger::instance()->debug( 'Error :: wp_mail :: [error=' . $er . ']' );
431 }
432 }
433 }
434
435 /**
436 * Method get_version()
437 *
438 * Get current plugin version.
439 *
440 * @return string Current plugin version.
441 */
442 public function get_version() {
443 return $this->current_version;
444 }
445
446 /**
447 * Method mainwp_cronpingchilds_action()
448 *
449 * Run cron ping child's action.
450 *
451 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_ping_childs()
452 */
453 public function mainwp_cronpingchilds_action() {
454 MainWP_System_Cron_Jobs::instance()->cron_ping_childs();
455 }
456
457 /**
458 * Method mainwp_cronbackups_continue_action()
459 *
460 * Run cron backups continue action.
461 *
462 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_backups_continue()
463 */
464 public function mainwp_cronbackups_continue_action() {
465 MainWP_System_Cron_Jobs::instance()->cron_backups_continue();
466 }
467
468 /**
469 * Method mainwp_cronbackups_action()
470 *
471 * Run cron backups action.
472 *
473 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_backups()
474 */
475 public function mainwp_cronbackups_action() {
476 MainWP_System_Cron_Jobs::instance()->cron_backups();
477 }
478
479 /**
480 * Method mainwp_cronreconnect_action()
481 *
482 * Run cron stats action.
483 *
484 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_reconnect()
485 */
486 public function mainwp_cronreconnect_action() {
487 MainWP_System_Cron_Jobs::instance()->cron_reconnect();
488 }
489
490 /**
491 * Method mainwp_cronupdatescheck_action()
492 *
493 * Run cron updates check action.
494 *
495 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_updates_check()
496 */
497 public function mainwp_cronupdatescheck_action() {
498 MainWP_System_Cron_Jobs::instance()->cron_updates_check();
499 }
500
501 /**
502 * Method mainwp_crondeactivatedlicensesalert_action()
503 *
504 * Run cron activated licenses alert action.
505 */
506 public function mainwp_crondeactivatedlicensesalert_action() {
507 MainWP_System_Cron_Jobs::instance()->cron_deactivated_licenses_alert();
508 }
509
510 /**
511 * Method mainwp_croncheckstatus_action()
512 *
513 * Run cron check sites status action.
514 *
515 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_check_websites_status()
516 */
517 public function mainwp_croncheckstatus_action() {
518 MainWP_System_Cron_Jobs::instance()->cron_check_websites_status();
519 }
520
521 /**
522 * Method mainwp_cronchecksitehealth_action()
523 *
524 * Run cron check sites health action.
525 *
526 * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_check_websites_health()
527 */
528 public function mainwp_cronchecksitehealth_action() {
529 MainWP_System_Cron_Jobs::instance()->cron_check_websites_health();
530 }
531
532 /**
533 * Method is_mainwp_pages()
534 *
535 * Get the current page and check it for "mainwp_".
536 *
537 * @return boolean ture|false.
538 */
539 public static function is_mainwp_pages() {
540 $screen = get_current_screen();
541 if ( $screen && strpos( $screen->base, 'mainwp_' ) !== false && strpos( $screen->base, 'mainwp_child_tab' ) === false ) {
542 return true;
543 }
544
545 return false;
546 }
547
548 /**
549 * Method is_mainwp_site_page()
550 *
551 * Checks if the current page is under the site mode.
552 *
553 * @return boolean ture|false.
554 */
555 public static function is_mainwp_site_page() {
556 //phpcs:disable WordPress.Security.NonceVerification.Recommended
557 if ( isset( $_GET['page'] ) && 'CostTrackerAdd' !== $_GET['page'] ) {
558 if ( ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) || ( isset( $_GET['dashboard'] ) && ! empty( $_GET['dashboard'] ) ) || ( isset( $_GET['updateid'] ) && ! empty( $_GET['updateid'] ) ) || ( isset( $_GET['emailsettingsid'] ) && ! empty( $_GET['emailsettingsid'] ) ) || ( isset( $_GET['scanid'] ) && ! empty( $_GET['scanid'] ) ) ) {
559 return true;
560 } elseif ( 'ServerInformation' === $_GET['page'] || 'ServerInformationCron' === $_GET['page'] || 'ErrorLog' === $_GET['page'] || 'ActionLogs' === $_GET['page'] || 'PluginPrivacy' === $_GET['page'] ) {
561 return true;
562 } elseif ( 'Settings' === $_GET['page'] || 'SettingsAdvanced' === $_GET['page'] || 'SettingsEmail' === $_GET['page'] || 'MainWPTools' === $_GET['page'] || 'SettingsInsights' === $_GET['page'] || 'SettingsApiBackups' === $_GET['page'] ) {
563 return true;
564 }
565 }
566 //phpcs:enable
567 return false;
568 }
569
570 /**
571 * Method init()
572 *
573 * Instantiate Plugin.
574 */
575 public function init() {
576
577 /**
578 * MainWP disabled menu items array.
579 *
580 * @global object $_mainwp_disable_menus_items
581 */
582 global $_mainwp_disable_menus_items;
583
584 $_mainwp_disable_menus_items = apply_filters( 'mainwp_disablemenuitems', $_mainwp_disable_menus_items );
585
586 /**
587 * Filter: mainwp_main_menu_disable_menu_items
588 *
589 * Filters disabled MainWP navigation items.
590 *
591 * @since Unknown
592 */
593 $_mainwp_disable_menus_items = apply_filters( 'mainwp_main_menu_disable_menu_items', $_mainwp_disable_menus_items );
594
595 if ( ! function_exists( 'MainWP\Dashboard\mainwp_current_user_have_right' ) ) {
596
597 /**
598 * Method mainwp_current_user_have_right()
599 *
600 * Check permission level by hook mainwp_currentusercan of Team Control extension.
601 *
602 * @param string $cap_type group or type of capabilities.
603 * @param string $cap capabilities for current user.
604 *
605 * @return bool true|false
606 *
607 * @uses \MainWP\Dashboard\MainWP_System_Handler::handle_settings_post()
608 */
609 function mainwp_current_user_have_right( $cap_type = '', $cap = '' ) {
610
611 /**
612 * Current user global.
613 *
614 * @global string
615 */
616 global $current_user;
617
618 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
619 return true;
620 }
621
622 if ( defined( 'WP_CLI' ) && WP_CLI ) {
623 return true;
624 }
625
626 if ( defined( 'MAINWP_REST_API_DOING' ) && MAINWP_REST_API_DOING ) {
627 return true;
628 }
629
630 if ( empty( $current_user ) ) {
631 if ( ! function_exists( 'wp_get_current_user' ) ) {
632 require_once ABSPATH . WPINC . '/pluggable.php';
633 }
634 }
635
636 return apply_filters( 'mainwp_currentusercan', true, $cap_type, $cap );
637 }
638 }
639
640 MainWP_System_Handler::instance()->handle_settings_post();
641 }
642
643 /**
644 * Method parse_init()
645 *
646 * Initiate plugin installation & then run the Quick Setup Wizard.
647 *
648 * @uses \MainWP\Dashboard\MainWP_System_Handler::upload_file()
649 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir()
650 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system()
651 * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
652 * @uses \MainWP\Dashboard\MainWP_Setup_Wizard()
653 */
654 public function parse_init() {
655 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
656 if ( isset( $_GET['mwpdl'] ) && isset( $_GET['sig'] ) ) {
657 $mwpDir = MainWP_System_Utility::get_mainwp_dir();
658 $mwpDir = $mwpDir[0];
659 $mwpdl = isset( $_REQUEST['mwpdl'] ) ? wp_unslash( $_REQUEST['mwpdl'] ) : '';
660 $file = trailingslashit( $mwpDir ) . rawurldecode( $mwpdl );
661
662 if ( stristr( rawurldecode( $mwpdl ), '..' ) ) {
663 return;
664 }
665
666 $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system();
667
668 /**
669 * WordPress files system object.
670 *
671 * @global object
672 */
673 global $wp_filesystem;
674 $sig_value = wp_unslash( $_GET['sig'] );
675 $valid_sig = MainWP_System_Utility::valid_download_sig( $file, $sig_value );
676
677 if ( ! $valid_sig ) {
678 MainWP_Logger::instance()->debug( ' :: download :: invalid sig :: ' . base64_decode( $sig_value ) ); // phpcs:ignore -- for debug logging.
679 }
680
681 if ( $hasWPFileSystem && $wp_filesystem->exists( $file ) && $valid_sig ) {
682 MainWP_System_Handler::instance()->upload_file( $file );
683 exit();
684 }
685 } elseif ( isset( $_GET['page'] ) ) {
686 if ( MainWP_System_Utility::is_admin() ) {
687 switch ( $_GET['page'] ) {
688 case 'mainwp-setup':
689 new MainWP_Setup_Wizard();
690 break;
691 }
692 }
693 }
694 // phpcs:enable
695 }
696
697 /**
698 * Method after_setup_theme()
699 *
700 * After setup theme hook, to support post thumbnails.
701 */
702 public function after_setup_theme() {
703 add_theme_support( 'post-thumbnails' );
704 }
705
706
707 /**
708 * Method hook_admin_update_check()
709 */
710 public function hook_admin_update_check() {
711 $current_ver = $this->check_ver_update;
712 $saved_ver = get_option( 'mainwp_update_check_version', false );
713
714 if ( false === $saved_ver ) {
715 return;
716 }
717
718 if ( version_compare( $saved_ver, $current_ver, '=' ) ) {
719 return;
720 }
721
722 if ( version_compare( $saved_ver, '0.0.4', '<' ) ) {
723 $sched = wp_next_scheduled( 'mainwp_cronstats_action' );
724 if ( ! empty( $sched ) ) {
725 wp_unschedule_event( $sched, 'mainwp_cronstats_action' );
726 }
727 global $wpdb;
728 $wpdb->query( 'DELETE FROM ' . $wpdb->usermeta . ' WHERE meta_key = "mainwp_widgets_sorted_toplevel_page_mainwp_tab" OR meta_key="mainwp_settings_show_widgets"' );//phpcs:ignore -- safe.
729 }
730
731 if ( version_compare( $saved_ver, '0.0.5', '<' ) ) {
732 $all_ext = MainWP_Extensions_View::get_available_extensions();
733 foreach ( $all_ext as $slug => $info ) {
734 $data = MainWP_Api_Manager::instance()->get_activation_info( $slug );
735 if ( is_array( $data ) && isset( $data['api_key'] ) ) {
736 $data['api_key'] = '';
737 $data['activated_key'] = 'Deactivated';
738 MainWP_Api_Manager::instance()->set_activation_info( $slug, $data );
739 }
740 }
741 update_option( 'mainwp_extensions_all_activation_cached', '' );
742 }
743
744 MainWP_Utility::update_option( 'mainwp_update_check_version', $current_ver );
745 }
746
747 /**
748 * Method admin_init()
749 *
750 * Do nothing if current user is not an Admin else display the page.
751 *
752 * @uses \MainWP\Dashboard\MainWP_Post_Backup_Handler::init()
753 * @uses \MainWP\Dashboard\MainWP_Post_Extension_Handler::init()
754 * @uses \MainWP\Dashboard\MainWP_Post_Handler::init()
755 * @uses \MainWP\Dashboard\MainWP_Post_Plugin_Theme_Handler::init()
756 * @uses \MainWP\Dashboard\MainWP_Post_Site_Handler::init()
757 * @uses \MainWP\Dashboard\MainWP_System_Handler::activate_extension()
758 * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
759 * @uses \MainWP\Dashboard\MainWP_System_View::get_class_name()
760 * @uses \MainWP\Dashboard\MainWP_System_View::get_mainwp_translations()
761 */
762 public function admin_init() { // phpcs:ignore -- complex function.
763
764 if ( ! MainWP_System_Utility::is_admin() ) {
765 return;
766 }
767
768 add_action( 'mainwp_activate_extention', array( MainWP_System_Handler::instance(), 'activate_extension' ), 10, 2 ); // @deprecated Use 'mainwp_activate_extension' instead.
769 add_action( 'mainwp_deactivate_extention', array( MainWP_System_Handler::instance(), 'deactivate_extension' ), 10, 3 ); // @deprecated Use 'mainwp_deactivate_extension' instead.
770
771 add_action( 'mainwp_activate_extension', array( MainWP_System_Handler::instance(), 'activate_extension' ), 10, 2 );
772 add_action( 'mainwp_deactivate_extension', array( MainWP_System_Handler::instance(), 'deactivate_extension' ), 10, 3 );
773
774 /**
775 * MainWP use external primary backup method.
776 *
777 * @global string
778 */
779 global $mainwpUseExternalPrimaryBackupsMethod;
780
781 if ( null === $mainwpUseExternalPrimaryBackupsMethod ) {
782 $return = '';
783
784 /*
785 * @deprecated Use 'mainwp_getprimarybackup_activated' instead.
786 *
787 */
788 $return = apply_filters_deprecated( 'mainwp-getprimarybackup-activated', array( $return ), '4.0.7.2', 'mainwp_getprimarybackup_activated' );
789 $mainwpUseExternalPrimaryBackupsMethod = apply_filters( 'mainwp_getprimarybackup_activated', $return );
790 }
791
792 add_action( 'mainwp_before_header', array( MainWP_System_View::get_class_name(), 'mainwp_warning_notice' ) );
793
794 MainWP_Post_Handler::instance()->init();
795 MainWP_Post_Site_Handler::instance()->init();
796 MainWP_Post_Plugin_Theme_Handler::instance()->init();
797 MainWP_Post_Extension_Handler::instance()->init();
798 MainWP_Post_Backup_Handler::instance()->init();
799 MainWP_Manage_Sites_Filter_Segment::get_instance()->admin_init();
800
801 /**
802 * Filter: mainwp_ui_use_wp_calendar
803 *
804 * Filters whether default jQuery datepicker should be used to avoid potential problems with Senatic UI Calendar library.
805 *
806 * @since 4.0.5
807 */
808 $use_wp_datepicker = apply_filters( 'mainwp_ui_use_wp_calendar', false );
809 if ( $use_wp_datepicker ) {
810 wp_enqueue_script( 'jquery-ui-datepicker' );
811 }
812 wp_enqueue_script( 'jquery-ui-dialog' );
813 $en_params = array( 'jquery-ui-dialog' );
814 if ( $use_wp_datepicker ) {
815 $en_params[] = 'jquery-ui-datepicker';
816 }
817 wp_enqueue_script( 'mainwp', MAINWP_PLUGIN_URL . 'assets/js/mainwp.js', $en_params, $this->current_version, true );
818
819 $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
820 $primaryBackup = get_option( 'mainwp_primaryBackup' );
821 $disable_backup_checking = true; // removed option.
822
823 $mainwpParams = array(
824 'image_url' => MAINWP_PLUGIN_URL . 'assets/images/',
825 'backup_before_upgrade' => 1 === (int) get_option( 'mainwp_backup_before_upgrade' ),
826 'disable_checkBackupBeforeUpgrade' => $disable_backup_checking,
827 'admin_url' => admin_url(),
828 'use_wp_datepicker' => $use_wp_datepicker ? 1 : 0,
829 'date_format' => get_option( 'date_format' ),
830 'time_format' => get_option( 'time_format' ),
831 'installedBulkSettingsManager' => is_plugin_active( 'mainwp-bulk-settings-manager/mainwp-bulk-settings-manager.php' ) ? 1 : 0,
832 'maximumSyncRequests' => ( get_option( 'mainwp_maximumSyncRequests' ) === false ) ? 8 : get_option( 'mainwp_maximumSyncRequests' ),
833 'maximumInstallUpdateRequests' => ( get_option( 'mainwp_maximumInstallUpdateRequests' ) === false ) ? 3 : get_option( 'mainwp_maximumInstallUpdateRequests' ),
834 '_wpnonce' => wp_create_nonce( 'mainwp-admin-nonce' ),
835 'demoMode' => MainWP_Demo_Handle::is_demo_mode() ? 1 : 0,
836 );
837 wp_localize_script( 'mainwp', 'mainwpParams', $mainwpParams );
838
839 $mainwpTranslations = MainWP_System_View::get_mainwp_translations();
840
841 wp_localize_script( 'mainwp', 'mainwpTranslations', $mainwpTranslations );
842
843 $security_nonces = MainWP_Post_Handler::instance()->create_security_nonces(); // to fix conflict with Post S M T P plugin.
844 $nonces_filter = apply_filters( 'mainwp_security_nonces', array() );
845 if ( is_array( $nonces_filter ) && ! empty( $nonces_filter ) ) {
846 $security_nonces = array_merge( $security_nonces, $nonces_filter );
847 }
848 wp_localize_script( 'mainwp', 'security_nonces', $security_nonces );
849
850 wp_enqueue_script( 'thickbox' );
851 wp_enqueue_script( 'user-profile' );
852 wp_enqueue_style( 'thickbox' );
853
854 $load_gridster = false;
855
856 // phpcs:disable WordPress.Security.NonceVerification
857 if ( isset( $_GET['page'] ) && ( 'mainwp_tab' === $_GET['page'] || ( 'managesites' === $_GET['page'] && isset( $_GET['dashboard'] ) ) ) ) {
858 $load_gridster = true;
859 } elseif ( isset( $_GET['page'] ) && 'ManageClients' === $_GET['page'] && isset( $_GET['client_id'] ) ) {
860 $load_gridster = true;
861 } elseif ( isset( $_GET['page'] ) && 0 === strpos( wp_unslash( $_GET['page'] ), 'ManageSites' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- individual page.
862 $load_gridster = true;
863 }
864
865 $load_gridster = apply_filters( 'mainwp_enqueue_script_gridster', $load_gridster );
866
867 if ( $load_gridster ) {
868 wp_enqueue_script( 'gridster', MAINWP_PLUGIN_URL . 'assets/js/gridster/jquery.gridster.min.js', array(), $this->current_version, true );
869 wp_enqueue_style( 'gridster', MAINWP_PLUGIN_URL . 'assets/js/gridster/jquery.gridster.min.css', array(), $this->current_version );
870 }
871
872 if ( isset( $_GET['page'] ) && ( 'managesites' === $_GET['page'] || 'MonitoringSites' === $_GET['page'] || 'ManageGroups' === $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
873 wp_enqueue_script( 'preview', MAINWP_PLUGIN_URL . 'assets/js/preview.js', array(), $this->current_version, true );
874 wp_enqueue_style( 'preview', MAINWP_PLUGIN_URL . 'assets/css/preview.css', array(), $this->current_version );
875 }
876 // phpcs:enable
877
878 wp_enqueue_style( 'wp-color-picker' );
879 wp_enqueue_script( 'wp-color-picker' );
880
881 $this->init_session();
882
883 if ( ! current_user_can( 'update_core' ) ) {
884 remove_action( 'admin_notices', 'update_nag', 3 );
885 }
886 }
887
888 /**
889 * Method hook_plugin_action_links()
890 *
891 * @param string[] $actions An array of plugin action links. By default this can include
892 * 'activate', 'deactivate', and 'delete'. With Multisite active
893 * this can also include 'network_active' and 'network_only' items.
894 * @param string $plugin_file Path to the plugin file relative to the plugins directory.
895 * @param array $plugin_data An array of plugin data. See get_plugin_data()
896 * and the {@see 'plugin_row_meta'} filter for the list
897 * of possible values.
898 */
899 public function hook_plugin_action_links( $actions, $plugin_file, $plugin_data ) {
900 if ( is_array( $plugin_data ) && ! empty( $plugin_data['slug'] ) && ! empty( $plugin_data['plugin'] ) && 'mainwp' === $plugin_data['slug'] && 'mainwp/mainwp.php' === $plugin_data['plugin'] ) {
901 $tmp = array(
902 'mainwp-setup' => '<a href="admin.php?page=mainwp-setup" id="mainwp-setup" aria-label="' . esc_html__( 'MainWP Dashboard Setup Wizard', 'mainwp' ) . '">' . esc_html__( 'Quick Setup', 'mainwp' ) . '</a>',
903 );
904 if ( is_array( $actions ) ) {
905 foreach ( $actions as $key => $val ) {
906 $tmp[ $key ] = $val;
907
908 }
909 }
910 return $tmp;
911 }
912 return $actions;
913 }
914
915 /**
916 * Method current_screen_redirects()
917 *
918 * MainWP current screen redirects.
919 */
920 public function current_screen_redirects() {
921
922 if ( ( defined( 'DOING_CRON' ) && DOING_CRON ) || defined( 'DOING_AJAX' ) ) {
923 return;
924 }
925 if ( self::is_mainwp_pages() ) {
926 $quick_setup = get_option( 'mainwp_run_quick_setup', false );
927 if ( 'yes' === $quick_setup ) {
928 delete_option( 'mainwp_run_quick_setup' );
929 wp_safe_redirect( admin_url( 'admin.php?page=mainwp-setup' ) );
930 exit;
931 }
932 }
933
934 if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'mainwp-setup' ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
935 return;
936 }
937
938 if ( self::is_mainwp_pages() ) {
939 if ( 'yes' === get_option( 'mainwp_activated' ) ) {
940 delete_option( 'mainwp_activated' );
941 wp_cache_delete( 'mainwp_activated', 'options' );
942 wp_cache_delete( 'alloptions', 'options' );
943 wp_safe_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
944 exit;
945 }
946 }
947 }
948
949 /**
950 * Method admin_redirects()
951 *
952 * MainWP admin redirects.
953 */
954 public function admin_redirects() {
955 if ( ( defined( 'DOING_CRON' ) && DOING_CRON ) || defined( 'DOING_AJAX' ) ) {
956 return;
957 }
958
959 if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'mainwp-setup' ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
960 return;
961 }
962
963 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
964 $_pos = strlen( $request_uri ) - strlen( '/wp-admin/' );
965 if ( ! empty( $request_uri ) && strpos( $request_uri, '/wp-admin/' ) !== false && strpos( $request_uri, '/wp-admin/' ) === $_pos ) {
966 $referer = wp_get_referer();
967 if ( ! empty( $referer ) && strpos( $referer, 'wp-login.php?redirect_to' ) !== false && strpos( $referer, '&reauth=1' ) !== false ) {
968 if ( mainwp_current_user_have_right( 'dashboard', 'access_global_dashboard' ) ) {
969 wp_safe_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
970 die();
971 }
972 }
973 }
974
975 MainWP_Logger::instance()->check_log_daily();
976 }
977
978 /**
979 * Method init_session()
980 *
981 * Check current page & initiate a session.
982 *
983 * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
984 */
985 public function init_session() {
986 $page = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
987 if ( ! empty( $page ) && in_array(
988 $page,
989 array(
990 'PostBulkManage',
991 'PageBulkManage',
992 'PluginsManage',
993 'PluginsAutoUpdate',
994 'ThemesManage',
995 'ThemesAutoUpdate',
996 'UserBulkManage',
997 )
998 )
999 ) {
1000 MainWP_Cache::init_session();
1001 }
1002 }
1003
1004 /**
1005 * Method clear_sessions()
1006 *
1007 * When logout clear the sessions to reset.
1008 */
1009 public function clear_sessions() {
1010 MainWP_Cache::init_session();
1011 $clear_cached = array(
1012 'Post',
1013 'Page',
1014 );
1015 foreach ( $clear_cached as $ca ) {
1016 MainWP_Cache::init_cache( $ca ); // to re-set cache.
1017 }
1018 }
1019
1020 /**
1021 * Method admin_enqueue_scripts()
1022 *
1023 * Enqueue all Mainwp Admin Scripts.
1024 */
1025 public function admin_enqueue_scripts() {
1026
1027 $load_cust_scripts = false;
1028
1029 /**
1030 * Current pagenow.
1031 *
1032 * @global string
1033 */
1034 global $pagenow;
1035
1036 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
1037 $load_cust_scripts = true;
1038 }
1039
1040 if ( self::is_mainwp_pages() ) {
1041 wp_enqueue_script( 'jquery-migrate' );
1042 wp_enqueue_script( 'mainwp-updates', MAINWP_PLUGIN_URL . 'assets/js/mainwp-updates.js', array(), $this->current_version, true );
1043 wp_enqueue_script( 'mainwp-managesites-action', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-action.js', array(), $this->current_version, true );
1044 wp_enqueue_script( 'mainwp-managesites-update', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-update.js', array(), $this->current_version, true );
1045 wp_enqueue_script( 'mainwp-managesites-import', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-import.js', array(), $this->current_version, true );
1046 wp_enqueue_script( 'mainwp-plugins-themes', MAINWP_PLUGIN_URL . 'assets/js/mainwp-plugins-themes.js', array(), $this->current_version, true );
1047 wp_enqueue_script( 'mainwp-backups', MAINWP_PLUGIN_URL . 'assets/js/mainwp-backups.js', array(), $this->current_version, true );
1048 wp_enqueue_script( 'mainwp-posts', MAINWP_PLUGIN_URL . 'assets/js/mainwp-posts.js', array(), $this->current_version, true );
1049 wp_enqueue_script( 'mainwp-users', MAINWP_PLUGIN_URL . 'assets/js/mainwp-users.js', array(), $this->current_version, true );
1050 wp_enqueue_script( 'mainwp-clients', MAINWP_PLUGIN_URL . 'assets/js/mainwp-clients.js', array(), $this->current_version, true );
1051 wp_enqueue_script( 'mainwp-extensions', MAINWP_PLUGIN_URL . 'assets/js/mainwp-extensions.js', array(), $this->current_version, true );
1052 wp_enqueue_script( 'mainwp-moment', MAINWP_PLUGIN_URL . 'assets/js/moment/moment.min.js', array(), $this->current_version, true );
1053 wp_enqueue_script( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.js', array( 'jquery' ), $this->current_version, false );
1054
1055 wp_enqueue_script( 'datatables', MAINWP_PLUGIN_URL . 'assets/js/datatables/jquery.dataTables.js', array( 'jquery' ), $this->current_version, false );
1056 wp_enqueue_script( 'datatables-semanticui', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.semanticui.js', array( 'jquery' ), $this->current_version, false );
1057 wp_enqueue_script( 'datatables-fixedColumns', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.fixedColumns.min.js', array( 'jquery' ), $this->current_version, false );
1058 wp_enqueue_script( 'datatables-scroller', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.scroller.js', array( 'jquery' ), $this->current_version, false );
1059 wp_enqueue_script( 'datatables-colreorder', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.colReorder.min.js', array( 'jquery' ), $this->current_version, false );
1060 wp_enqueue_script( 'datatables-responsive', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.responsive.min.js', array( 'jquery' ), $this->current_version, true );
1061
1062 wp_enqueue_script( 'hamburger', MAINWP_PLUGIN_URL . 'assets/js/hamburger/hamburger.js', array( 'jquery' ), $this->current_version, true );
1063 wp_enqueue_script( 'datatables-natural-sorting', MAINWP_PLUGIN_URL . 'assets/js/sorting/natural.js', array( 'jquery' ), $this->current_version, true );
1064
1065 wp_enqueue_script( 'mainwp-clipboard', MAINWP_PLUGIN_URL . 'assets/js/clipboard/clipboard.min.js', array( 'jquery' ), $this->current_version, true );
1066 wp_enqueue_script( 'mainwp-rest-api', MAINWP_PLUGIN_URL . 'assets/js/mainwp-rest-api.js', array(), $this->current_version, true );
1067
1068 if ( isset( $_GET['page'] ) && 'ManageGroups' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1069 wp_enqueue_script( 'mainwp-groups', MAINWP_PLUGIN_URL . 'assets/js/mainwp-groups.js', array(), $this->current_version, true );
1070 }
1071 $enqueue_scripts = apply_filters( 'mainwp_admin_enqueue_scripts', array() );
1072 if ( is_array( $enqueue_scripts ) ) {
1073 if ( ! empty( $enqueue_scripts['apexcharts'] ) ) {
1074 wp_enqueue_script(
1075 'mainwp-apexcharts',
1076 MAINWP_PLUGIN_URL . 'assets/js/apexcharts/apexcharts.js',
1077 array(
1078 'jquery',
1079 'mainwp',
1080 ),
1081 $this->current_version,
1082 true
1083 );
1084 }
1085 }
1086 }
1087
1088 if ( $load_cust_scripts ) {
1089 wp_enqueue_script( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.js', array( 'jquery' ), $this->current_version, true );
1090 }
1091
1092 wp_enqueue_script( 'mainwp-ui', MAINWP_PLUGIN_URL . 'assets/js/mainwp-ui.js', array(), $this->current_version, true );
1093 wp_enqueue_script( 'mainwp-js-popup', MAINWP_PLUGIN_URL . 'assets/js/mainwp-popup.js', array(), $this->current_version, true );
1094 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.
1095 wp_enqueue_script( 'mainwp-date', MAINWP_PLUGIN_URL . 'assets/js/date.js', array(), $this->current_version, true );
1096 wp_enqueue_script( 'mainwp-filesaver', MAINWP_PLUGIN_URL . 'assets/js/FileSaver.js', array(), $this->current_version, true );
1097 }
1098
1099 /**
1100 * Method admin_enqueue_scripts_fix_conflict()
1101 *
1102 * Enqueue Admin Scripts fix conflict.
1103 */
1104 public function admin_enqueue_scripts_fix_conflict() {
1105 if ( self::is_mainwp_pages() ) {
1106 // to fix conflict with the SVG Support plugin.
1107 remove_action( 'admin_enqueue_scripts', 'bodhi_svgs_admin_multiselect' );
1108 }
1109 }
1110
1111 /**
1112 * Method admin_enqueue_styles()
1113 *
1114 * Enqueue all Mainwp Admin Styles.
1115 */
1116 public function admin_enqueue_styles() {
1117
1118 wp_enqueue_style( 'mainwp', MAINWP_PLUGIN_URL . 'assets/css/mainwp.css', array(), $this->current_version );
1119 wp_enqueue_style( 'mainwp-responsive-layouts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-responsive-layouts.css', array(), $this->current_version );
1120
1121 if ( isset( $_GET['hideall'] ) && 1 === (int) $_GET['hideall'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1122 remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
1123 }
1124
1125 /**
1126 * Current pagenow.
1127 *
1128 * @global string
1129 */
1130 global $pagenow;
1131
1132 $load_cust_scripts = false;
1133 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
1134 $load_cust_scripts = true;
1135 }
1136
1137 if ( self::is_mainwp_pages() ) {
1138 wp_enqueue_style( 'mainwp-fonts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fonts.css', array(), $this->current_version );
1139 wp_enqueue_style( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.css', array(), $this->current_version );
1140 wp_enqueue_style( 'mainwp-fomantic', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fomantic.css', array(), $this->current_version );
1141
1142 wp_enqueue_style( 'datatables', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.semanticui.css', array(), $this->current_version );
1143 wp_enqueue_style( 'datatables-colreorder', MAINWP_PLUGIN_URL . 'assets/js/datatables/colReorder.dataTables.min.css', array(), $this->current_version );
1144 wp_enqueue_style( 'datatables-fixedColumns', MAINWP_PLUGIN_URL . 'assets/js/datatables/fixedColumns.dataTables.min.css', array(), $this->current_version );
1145 wp_enqueue_style( 'datatables-scroller', MAINWP_PLUGIN_URL . 'assets/js/datatables/scroller.semanticui.css', array(), $this->current_version );
1146 wp_enqueue_style( 'datatables-responsive', MAINWP_PLUGIN_URL . 'assets/js/datatables/responsive.dataTables.min.css', array(), $this->current_version );
1147
1148 wp_enqueue_style( 'hamburger', MAINWP_PLUGIN_URL . 'assets/js/hamburger/hamburger.css', array(), $this->current_version );
1149 // to fix conflict layout.
1150 wp_enqueue_style( 'jquery-ui-style', MAINWP_PLUGIN_URL . 'assets/css/1.11.1/jquery-ui.min.css', array(), '1.11.1' );
1151
1152 // load custom MainWP theme.
1153 $selected_theme = MainWP_Settings::get_instance()->get_selected_theme();
1154 if ( ! empty( $selected_theme ) ) {
1155 if ( 'dark' === $selected_theme ) {
1156 wp_enqueue_style( 'mainwp-custom-dashboard-extension-dark-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-dark-theme.css', array(), $this->current_version );
1157 } elseif ( 'wpadmin' === $selected_theme ) {
1158 wp_enqueue_style( 'mainwp-custom-dashboard-extension-wp-admin-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-wpadmin-theme.css', array(), $this->current_version );
1159 } elseif ( 'minimalistic' === $selected_theme ) {
1160 wp_enqueue_style( 'mainwp-custom-dashboard-extension-minimalistic-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-minimalistic-theme.css', array(), $this->current_version );
1161 } elseif ( 'default' === $selected_theme ) {
1162 wp_enqueue_style( 'mainwp-custom-dashboard-extension-default-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-default-theme.css', array(), $this->current_version );
1163 } else {
1164 $dirs = MainWP_Settings::get_instance()->get_custom_theme_folder();
1165 $custom_theme_url = $dirs[1];
1166 wp_enqueue_style( 'mainwp-custom-dashboard-theme', $custom_theme_url . $selected_theme, array(), $this->current_version );
1167 }
1168 }
1169 }
1170
1171 if ( $load_cust_scripts ) {
1172 wp_enqueue_style( 'mainwp-fonts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fonts.css', array(), $this->current_version );
1173 wp_enqueue_style( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.css', array(), $this->current_version );
1174 }
1175 }
1176
1177 /**
1178 * Method admin_menu()
1179 *
1180 * Add Bulk Post/Pages menue.
1181 */
1182 public function admin_menu() {
1183
1184 /**
1185 * Admin menu array.
1186 *
1187 * @global object
1188 */
1189 global $menu;
1190
1191 foreach ( $menu as $k => $item ) {
1192 if ( 'edit.php?post_type=bulkpost' === $item[2] ) {
1193 unset( $menu[ $k ] );
1194 } elseif ( 'edit.php?post_type=bulkpage' === $item[2] ) {
1195 unset( $menu[ $k ] );
1196 }
1197 }
1198 }
1199
1200 /**
1201 * Method enqueue_postbox_scripts()
1202 *
1203 * Enqueue postbox scripts.
1204 */
1205 public static function enqueue_postbox_scripts() {
1206 wp_enqueue_script( 'common' );
1207 wp_enqueue_script( 'wp-lists' );
1208 wp_enqueue_script( 'postbox' );
1209 }
1210
1211 /**
1212 * Method admin_footer()
1213 *
1214 * Create MainWP admin footer.
1215 *
1216 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1217 * @uses \MainWP\Dashboard\MainWP_DB::query()
1218 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
1219 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
1220 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_menu()
1221 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
1222 * @uses \MainWP\Dashboard\MainWP_System_View::render_footer_content()
1223 * @uses \MainWP\Dashboard\MainWP_System_View::admin_footer()
1224 */
1225 public function admin_footer() {
1226 if ( ! self::is_mainwp_pages() ) {
1227 $sites_count = MainWP_DB::instance()->get_websites_count();
1228 if ( empty( $sites_count ) ) {
1229 ?>
1230 <script type="text/javascript">
1231 jQuery( function(){
1232 jQuery( 'li#toplevel_page_mainwp_tab .wp-submenu-wrap .wp-submenu-head' ).after('<li style="background: #FFD300 !important;" class="wp-first-item"><a href="admin.php?page=mainwp-setup" style="color: #000 !important;" class="wp-first-item"><?php esc_html_e( 'Quick Setup', 'mainwp' ); ?></a></li>');
1233 });
1234 </script>
1235 <?php
1236 }
1237 return;
1238 }
1239
1240 ?>
1241 <div class="ui large modal" id="mainwp-response-data-modal">
1242 <i class="close icon"></i>
1243 <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div>
1244 <div class="content">
1245 <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?>
1246 </div>
1247 </div>
1248 <div class="scrolling content content-response"></div>
1249 <div class="actions">
1250 <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button>
1251 </div>
1252 </div>
1253 <div id="mainwp-response-data-container" resp-data=""></div>
1254 <?php
1255
1256 if ( isset( $_GET['hideall'] ) && 1 === (int) $_GET['hideall'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1257 return;
1258 }
1259 $current_wpid = MainWP_System_Utility::get_current_wpid();
1260 if ( $current_wpid ) {
1261 $website = MainWP_DB::instance()->get_website_by_id( $current_wpid );
1262 $websites = array( $website );
1263 } else {
1264 $is_staging = 'no';
1265 if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1266 if ( ( 'managesites' === $_GET['page'] ) && ! isset( $_GET['id'] ) && ! isset( $_GET['do'] ) && ! isset( $_GET['dashboard'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1267 $group_ids = get_user_option( 'mainwp_managesites_filter_group' );
1268 if ( ! empty( $group_ids ) ) {
1269 $group_ids = explode( ',', $group_ids ); // convert to array.
1270 }
1271 if ( $group_ids ) {
1272 $staging_group = get_option( 'mainwp_stagingsites_group_id' );
1273 }
1274 } elseif ( 'UpdatesManage' === $_GET['page'] || 'mainwp_tab' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1275 $staging_enabled = is_plugin_active( 'mainwp-staging-extension/mainwp-staging-extension.php' ) ? true : false;
1276 if ( $staging_enabled ) {
1277 $staging_view = MainWP_System_Utility::get_staging_options_sites_view_for_current_users();
1278 if ( 'staging' === $staging_view ) {
1279 $is_staging = 'yes';
1280 }
1281 }
1282 }
1283 }
1284 $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 ) );
1285 }
1286
1287 MainWP_System_View::render_footer_content( $websites, $current_wpid );
1288 if ( empty( $current_wpid ) ) {
1289 MainWP_DB::free_result( $websites );
1290 }
1291
1292 MainWP_System_View::admin_footer();
1293 MainWP_System_View::render_plugins_install_check();
1294
1295 MainWP_Menu::init_sub_pages();
1296
1297 /**
1298 * MainWP disabled menu items array.
1299 *
1300 * @global object
1301 */
1302 global $_mainwp_disable_menus_items;
1303
1304 $_mainwp_disable_menus_items = apply_filters( 'mainwp_all_disablemenuitems', $_mainwp_disable_menus_items );
1305 }
1306
1307 /**
1308 * Method activated_check()
1309 *
1310 * Activated check.
1311 *
1312 * @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
1313 */
1314 public function activated_check() {
1315 MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
1316 return $this->get_version();
1317 }
1318
1319 /**
1320 * Method activation()
1321 *
1322 * Activate MainWP.
1323 *
1324 * @uses \MainWP\Dashboard\MainWP_Install::install()
1325 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
1326 */
1327 public function activation() {
1328 $this->update_install();
1329 MainWP_Utility::update_option( 'mainwp_activated', 'yes' );
1330 }
1331
1332 /**
1333 * Method deactivation()
1334 *
1335 * Deactivate MainWP.
1336 */
1337 public function deactivation() {
1338 update_option( 'mainwp_extensions_all_activation_cached', '' );
1339 }
1340
1341 /**
1342 * Method update_install()
1343 *
1344 * Update MainWP.
1345 *
1346 * @uses \MainWP\Dashboard\MainWP_Install::install()
1347 */
1348 public function update_install() {
1349 MainWP_DB_Client::instance();
1350 MainWP_DB_Site_Actions::instance();
1351 MainWP_Install::instance()->install();
1352 $this->check_to_updates();
1353 }
1354
1355
1356 /**
1357 * Method check_to_updates()
1358 *
1359 * To check updates options.
1360 */
1361 public function check_to_updates() {
1362 $update_ver = get_option( 'mainwp_update_check_version', false );
1363 $current_ver = $this->check_ver_update;
1364
1365 if ( false === $update_ver && version_compare( $current_ver, '0.0.1', '=' ) ) {
1366 // to update new saving format.
1367 MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key();
1368 MainWP_Utility::update_option( 'mainwp_update_check_version', $current_ver );
1369 }
1370
1371 if ( false === $update_ver ) {
1372 return;
1373 }
1374 }
1375
1376 /**
1377 * Method is_single_user()
1378 *
1379 * Check if single user environment.
1380 *
1381 * @return boolean true|false.
1382 */
1383 public function is_single_user() {
1384 return true;
1385 }
1386
1387 /**
1388 * Method is_multi_user()
1389 *
1390 * Check if multi user environment.
1391 *
1392 * @return boolean true|false.
1393 */
1394 public function is_multi_user() {
1395 return ! $this->is_single_user();
1396 }
1397
1398 /**
1399 * Method get_plugin_slug()
1400 *
1401 * Get MainWP Plugin Slug.
1402 */
1403 public function get_plugin_slug() {
1404 return $this->plugin_slug;
1405 }
1406 }
1407