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