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

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