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

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

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