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 / class / class-mainwp-system.php

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

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