google-analytics-for-wordpress
Last commit date
assets
1 year ago
includes
1 year ago
languages
1 year ago
lite
1 year ago
googleanalytics.php
1 year ago
index.php
3 years ago
readme.txt
1 year ago
googleanalytics.php
833 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Plugin Name: Google Analytics for WordPress by MonsterInsights |
| 5 | * Plugin URI: https://www.monsterinsights.com/?utm_source=liteplugin&utm_medium=pluginheader&utm_campaign=pluginurl&utm_content=7%2E0%2E0 |
| 6 | * Description: The best Google Analytics plugin for WordPress. See how visitors find and use your website, so you can keep them coming back. |
| 7 | * Author: MonsterInsights |
| 8 | * Author URI: https://www.monsterinsights.com/lite/?utm_source=liteplugin&utm_medium=pluginheader&utm_campaign=authoruri&utm_content=7%2E0%2E0 |
| 9 | * |
| 10 | * Version: 9.2.0 |
| 11 | * Requires at least: 5.6.0 |
| 12 | * Requires PHP: 7.2 |
| 13 | * |
| 14 | * License: GPL v3 |
| 15 | * |
| 16 | * Text Domain: google-analytics-for-wordpress |
| 17 | * Domain Path: /languages |
| 18 | * |
| 19 | * MonsterInsights Lite |
| 20 | * Copyright (C) 2008-2024, MonsterInsights, support@monsterinsights.com |
| 21 | * |
| 22 | * This program is free software: you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation, either version 3 of the License, or |
| 25 | * (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 34 | * |
| 35 | * @category Plugin |
| 36 | * @copyright Copyright © 2018 Chris Christoff |
| 37 | * @author Chris Christoff |
| 38 | * @package MonsterInsights |
| 39 | */ |
| 40 | |
| 41 | // Exit if accessed directly. |
| 42 | if ( ! defined( 'ABSPATH' ) ) { |
| 43 | exit; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Main plugin class. |
| 48 | * |
| 49 | * @since 6.0.0 |
| 50 | * |
| 51 | * @package MonsterInsights |
| 52 | * @author Chris Christoff |
| 53 | * @access public |
| 54 | */ |
| 55 | final class MonsterInsights_Lite { |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Holds the class object. |
| 60 | * |
| 61 | * @since 6.0.0 |
| 62 | * @access public |
| 63 | * @var object Instance of instantiated MonsterInsights class. |
| 64 | */ |
| 65 | public static $instance; |
| 66 | |
| 67 | /** |
| 68 | * Plugin version, used for cache-busting of style and script file references. |
| 69 | * |
| 70 | * @since 6.0.0 |
| 71 | * @access public |
| 72 | * @var string $version Plugin version. |
| 73 | */ |
| 74 | public $version = '9.2.0'; |
| 75 | |
| 76 | /** |
| 77 | * Plugin file. |
| 78 | * |
| 79 | * @since 6.0.0 |
| 80 | * @access public |
| 81 | * @var string $file PHP File constant for main file. |
| 82 | */ |
| 83 | public $file; |
| 84 | |
| 85 | /** |
| 86 | * The name of the plugin. |
| 87 | * |
| 88 | * @since 6.0.0 |
| 89 | * @access public |
| 90 | * @var string $plugin_name Plugin name. |
| 91 | */ |
| 92 | public $plugin_name = 'MonsterInsights Lite'; |
| 93 | |
| 94 | /** |
| 95 | * Unique plugin slug identifier. |
| 96 | * |
| 97 | * @since 6.0.0 |
| 98 | * @access public |
| 99 | * @var string $plugin_slug Plugin slug. |
| 100 | */ |
| 101 | public $plugin_slug = 'monsterinsights-lite'; |
| 102 | |
| 103 | /** |
| 104 | * Holds instance of MonsterInsights License class. |
| 105 | * |
| 106 | * @since 6.0.0 |
| 107 | * @access public |
| 108 | * @var MonsterInsights_License $license Instance of License class. |
| 109 | */ |
| 110 | protected $license; |
| 111 | |
| 112 | /** |
| 113 | * Holds instance of MonsterInsights Admin Notice class. |
| 114 | * |
| 115 | * @since 6.0.0 |
| 116 | * @access public |
| 117 | * @var MonsterInsights_Admin_Notice $notices Instance of Admin Notice class. |
| 118 | */ |
| 119 | public $notices; |
| 120 | |
| 121 | /** |
| 122 | * Holds instance of MonsterInsights Reporting class. |
| 123 | * |
| 124 | * @since 6.0.0 |
| 125 | * @access public |
| 126 | * @var MonsterInsights_Reporting $reporting Instance of Reporting class. |
| 127 | */ |
| 128 | public $reporting; |
| 129 | |
| 130 | /** |
| 131 | * Holds instance of MonsterInsights Notifications class. |
| 132 | * |
| 133 | * @since 7.11 |
| 134 | * @access public |
| 135 | * @var MonsterInsights_Notifications $notifications Instance of Notifications class. |
| 136 | */ |
| 137 | public $notifications; |
| 138 | |
| 139 | /** |
| 140 | * Holds instance of MonsterInsights Notification Events |
| 141 | * |
| 142 | * @since 7.12.3 |
| 143 | * @access public |
| 144 | * @var MonsterInsights_Notification_Event $notification_event Instance of MonsterInsights_Notification_Event class. |
| 145 | */ |
| 146 | public $notification_event; |
| 147 | |
| 148 | /** |
| 149 | * Holds instance of MonsterInsights Auth class. |
| 150 | * |
| 151 | * @since 7.0.0 |
| 152 | * @access public |
| 153 | * @var MonsterInsights_Auth $auth Instance of Auth class. |
| 154 | */ |
| 155 | protected $auth; |
| 156 | |
| 157 | /** |
| 158 | * Holds instance of MonsterInsights API Auth class. |
| 159 | * |
| 160 | * @since 6.0.0 |
| 161 | * @access public |
| 162 | * @var MonsterInsights_Auth $api_auth Instance of APIAuth class. |
| 163 | */ |
| 164 | public $api_auth; |
| 165 | |
| 166 | /** |
| 167 | * Holds instance of MonsterInsights API Rest Routes class. |
| 168 | * |
| 169 | * @since 7.4.0 |
| 170 | * @access public |
| 171 | * @var MonsterInsights_Rest_Routes $routes Instance of rest routes. |
| 172 | */ |
| 173 | public $routes; |
| 174 | |
| 175 | /** |
| 176 | * The tracking mode used in the frontend. |
| 177 | * |
| 178 | * @since 7.15.0 |
| 179 | * @accces public |
| 180 | * @var string |
| 181 | * @deprecated Since 8.3 with the removal of ga compatibility |
| 182 | */ |
| 183 | public $tracking_mode; |
| 184 | |
| 185 | /** |
| 186 | * Setup checklist class property. |
| 187 | * |
| 188 | * @var MonsterInsights_Setup_Checklist |
| 189 | */ |
| 190 | public $setup_checklist; |
| 191 | |
| 192 | /** |
| 193 | * Primary class constructor. |
| 194 | * |
| 195 | * @since 6.0.0 |
| 196 | * @access public |
| 197 | */ |
| 198 | public function __construct() { |
| 199 | // We don't use this |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Returns the singleton instance of the class. |
| 204 | * |
| 205 | * @access public |
| 206 | * @return object The MonsterInsights_Lite object. |
| 207 | * @since 6.0.0 |
| 208 | * |
| 209 | */ |
| 210 | public static function get_instance() { |
| 211 | |
| 212 | if ( ! isset( self::$instance ) && ! ( self::$instance instanceof MonsterInsights_Lite ) ) { |
| 213 | self::$instance = new MonsterInsights_Lite(); |
| 214 | self::$instance->file = __FILE__; |
| 215 | |
| 216 | // Detect Pro version and return early |
| 217 | if ( defined( 'MONSTERINSIGHTS_PRO_VERSION' ) ) { |
| 218 | add_action( 'admin_notices', array( self::$instance, 'monsterinsights_pro_notice' ) ); |
| 219 | |
| 220 | return self::$instance; |
| 221 | } |
| 222 | |
| 223 | // Define constants |
| 224 | self::$instance->define_globals(); |
| 225 | |
| 226 | // Load in settings |
| 227 | self::$instance->load_settings(); |
| 228 | |
| 229 | // Compatibility check |
| 230 | if ( ! self::$instance->check_compatibility() ) { |
| 231 | return self::$instance; |
| 232 | } |
| 233 | |
| 234 | // Load in Licensing |
| 235 | self::$instance->load_licensing(); |
| 236 | |
| 237 | // Load in Auth |
| 238 | self::$instance->load_auth(); |
| 239 | |
| 240 | // Load files |
| 241 | self::$instance->require_files(); |
| 242 | |
| 243 | // This does the version to version background upgrade routines and initial install |
| 244 | $mi_version = get_option( 'monsterinsights_current_version', '5.5.3' ); |
| 245 | if ( version_compare( $mi_version, '8.13.0', '<' ) ) { |
| 246 | monsterinsights_lite_call_install_and_upgrade(); |
| 247 | } |
| 248 | |
| 249 | if ( is_admin() ) { |
| 250 | new AM_Deactivation_Survey( 'MonsterInsights', basename( __DIR__ ) ); |
| 251 | } |
| 252 | |
| 253 | // Load the plugin textdomain. |
| 254 | add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ), 15 ); |
| 255 | |
| 256 | // Load admin only components. |
| 257 | if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
| 258 | self::$instance->notices = new MonsterInsights_Notice_Admin(); |
| 259 | self::$instance->reporting = new MonsterInsights_Reporting(); |
| 260 | self::$instance->api_auth = new MonsterInsights_API_Auth(); |
| 261 | self::$instance->routes = new MonsterInsights_Rest_Routes(); |
| 262 | self::$instance->notifications = new MonsterInsights_Notifications(); |
| 263 | self::$instance->notification_event = new MonsterInsights_Notification_Event(); |
| 264 | self::$instance->setup_checklist = new MonsterInsights_Setup_Checklist(); |
| 265 | } |
| 266 | |
| 267 | if ( monsterinsights_is_pro_version() ) { |
| 268 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'pro/includes/load.php'; |
| 269 | } else { |
| 270 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/load.php'; |
| 271 | } |
| 272 | |
| 273 | // Run hook to load MonsterInsights addons. |
| 274 | do_action( 'monsterinsights_load_plugins' ); // the updater class for each addon needs to be instantiated via `monsterinsights_updater` |
| 275 | } |
| 276 | |
| 277 | return self::$instance; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Throw error on object clone |
| 282 | * |
| 283 | * The whole idea of the singleton design pattern is that there is a single |
| 284 | * object therefore, we don't want the object to be cloned. |
| 285 | * |
| 286 | * @return void |
| 287 | * @since 6.0.0 |
| 288 | * @access public |
| 289 | * |
| 290 | */ |
| 291 | public function __clone() { |
| 292 | _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'google-analytics-for-wordpress' ), '6.0.0' ); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Disable unserializing of the class |
| 297 | * |
| 298 | * Attempting to wakeup an MonsterInsights instance will throw a doing it wrong notice. |
| 299 | * |
| 300 | * @return void |
| 301 | * @since 6.0.0 |
| 302 | * @access public |
| 303 | * |
| 304 | */ |
| 305 | public function __wakeup() { |
| 306 | _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'google-analytics-for-wordpress' ), '6.0.0' ); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Magic get function. |
| 311 | * |
| 312 | * We use this to lazy load certain functionality. Right now used to lazyload |
| 313 | * the API & Auth frontend, so it's only loaded if user is using a plugin |
| 314 | * that requires it. |
| 315 | * |
| 316 | * @return void |
| 317 | * @since 7.0.0 |
| 318 | * @access public |
| 319 | * |
| 320 | */ |
| 321 | public function __get( $key ) { |
| 322 | if ( $key === 'auth' ) { |
| 323 | if ( empty( self::$instance->auth ) ) { |
| 324 | // LazyLoad Auth for Frontend |
| 325 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/auth.php'; |
| 326 | self::$instance->auth = new MonsterInsights_Auth(); |
| 327 | } |
| 328 | |
| 329 | return self::$instance->$key; |
| 330 | } else { |
| 331 | return self::$instance->$key; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Check compatibility with PHP and WP, and display notices if necessary |
| 337 | * |
| 338 | * @return bool |
| 339 | * @since 8.0.0 |
| 340 | */ |
| 341 | private function check_compatibility() { |
| 342 | if ( defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) && MONSTERINSIGHTS_FORCE_ACTIVATION ) { |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | require_once plugin_dir_path( __FILE__ ) . 'includes/compatibility-check.php'; |
| 347 | $compatibility = MonsterInsights_Compatibility_Check::get_instance(); |
| 348 | $compatibility->maybe_display_notice(); |
| 349 | |
| 350 | return $compatibility->is_php_compatible() && $compatibility->is_wp_compatible(); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Define MonsterInsights constants. |
| 355 | * |
| 356 | * This function defines all of the MonsterInsights PHP constants. |
| 357 | * |
| 358 | * @return void |
| 359 | * @since 6.0.0 |
| 360 | * @access public |
| 361 | * |
| 362 | */ |
| 363 | public function define_globals() { |
| 364 | |
| 365 | if ( ! defined( 'MONSTERINSIGHTS_VERSION' ) ) { |
| 366 | define( 'MONSTERINSIGHTS_VERSION', $this->version ); |
| 367 | } |
| 368 | |
| 369 | if ( ! defined( 'MONSTERINSIGHTS_LITE_VERSION' ) ) { |
| 370 | define( 'MONSTERINSIGHTS_LITE_VERSION', MONSTERINSIGHTS_VERSION ); |
| 371 | } |
| 372 | |
| 373 | if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_NAME' ) ) { |
| 374 | define( 'MONSTERINSIGHTS_PLUGIN_NAME', $this->plugin_name ); |
| 375 | } |
| 376 | |
| 377 | if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_SLUG' ) ) { |
| 378 | define( 'MONSTERINSIGHTS_PLUGIN_SLUG', $this->plugin_slug ); |
| 379 | } |
| 380 | |
| 381 | if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_FILE' ) ) { |
| 382 | define( 'MONSTERINSIGHTS_PLUGIN_FILE', $this->file ); |
| 383 | } |
| 384 | |
| 385 | if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_DIR' ) ) { |
| 386 | define( 'MONSTERINSIGHTS_PLUGIN_DIR', plugin_dir_path( $this->file ) ); |
| 387 | } |
| 388 | |
| 389 | if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_URL' ) ) { |
| 390 | define( 'MONSTERINSIGHTS_PLUGIN_URL', plugin_dir_url( $this->file ) ); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Loads the plugin textdomain for translations. |
| 396 | * |
| 397 | * @access public |
| 398 | * @return void |
| 399 | * @since 6.0.0 |
| 400 | * |
| 401 | */ |
| 402 | public function load_textdomain() { |
| 403 | $plugin_text_domain = 'google-analytics-for-wordpress'; |
| 404 | |
| 405 | $plugin_dir = basename( __DIR__ ); |
| 406 | |
| 407 | load_plugin_textdomain( |
| 408 | $plugin_text_domain, |
| 409 | false, |
| 410 | $plugin_dir . '/languages' |
| 411 | ); |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Output a nag notice if the user has both Lite and Pro activated |
| 416 | * |
| 417 | * @access public |
| 418 | * @return void |
| 419 | * @since 6.0.0 |
| 420 | * |
| 421 | */ |
| 422 | public function monsterinsights_pro_notice() { |
| 423 | $url = admin_url( 'plugins.php' ); |
| 424 | // Check for MS dashboard |
| 425 | if ( is_network_admin() ) { |
| 426 | $url = network_admin_url( 'plugins.php' ); |
| 427 | } |
| 428 | ?> |
| 429 | <div class="error"> |
| 430 | <p><?php echo sprintf(esc_html__('Please %1$suninstall%2$s the MonsterInsights Lite Plugin. Your Pro version of MonsterInsights may not work as expected until the Lite version is uninstalled.', 'google-analytics-for-wordpress'), '<a href="' . $url . '">', '</a>'); // phpcs:ignore ?></p> |
| 431 | </div> |
| 432 | <?php |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Loads MonsterInsights settings |
| 437 | * |
| 438 | * Adds the items to the base object, and adds the helper functions. |
| 439 | * |
| 440 | * @return void |
| 441 | * @since 6.0.0 |
| 442 | * @access public |
| 443 | * |
| 444 | */ |
| 445 | public function load_settings() { |
| 446 | global $monsterinsights_settings; |
| 447 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/options.php'; |
| 448 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/helpers.php'; |
| 449 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/deprecated.php'; |
| 450 | $monsterinsights_settings = monsterinsights_get_options(); |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /** |
| 455 | * Loads MonsterInsights License |
| 456 | * |
| 457 | * Loads license class used by MonsterInsights |
| 458 | * |
| 459 | * @return void |
| 460 | * @since 7.0.0 |
| 461 | * @access public |
| 462 | * |
| 463 | */ |
| 464 | public function load_licensing() { |
| 465 | if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
| 466 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/license-compat.php'; |
| 467 | self::$instance->license = new MonsterInsights_License_Compat(); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Loads MonsterInsights Auth |
| 473 | * |
| 474 | * Loads auth used by MonsterInsights |
| 475 | * |
| 476 | * @return void |
| 477 | * @since 7.0.0 |
| 478 | * @access public |
| 479 | * |
| 480 | */ |
| 481 | public function load_auth() { |
| 482 | if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
| 483 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/auth.php'; |
| 484 | self::$instance->auth = new MonsterInsights_Auth(); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Loads all files into scope. |
| 490 | * |
| 491 | * @access public |
| 492 | * @return void |
| 493 | * @since 6.0.0 |
| 494 | * |
| 495 | */ |
| 496 | public function require_files() { |
| 497 | |
| 498 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/capabilities.php'; |
| 499 | |
| 500 | if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
| 501 | |
| 502 | // Lite and Pro files |
| 503 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-deactivation-survey.php'; |
| 504 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/ajax.php'; |
| 505 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/admin.php'; |
| 506 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/common.php'; |
| 507 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notice.php'; |
| 508 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/autoupdate.php'; |
| 509 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/review.php'; |
| 510 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/setup-checklist.php'; |
| 511 | |
| 512 | // Pages |
| 513 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/settings.php'; |
| 514 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/tools.php'; |
| 515 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/reports.php'; |
| 516 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/addons.php'; |
| 517 | |
| 518 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/api-auth.php'; |
| 519 | |
| 520 | // Reports |
| 521 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/abstract-report.php'; |
| 522 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/overview.php'; |
| 523 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/site-summary.php'; |
| 524 | |
| 525 | // Reporting Functionality |
| 526 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reporting.php'; |
| 527 | |
| 528 | // Routes used by Vue |
| 529 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/routes.php'; |
| 530 | |
| 531 | // Load gutenberg editor functions |
| 532 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/gutenberg/gutenberg.php'; |
| 533 | |
| 534 | // Emails |
| 535 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/emails/class-emails.php'; |
| 536 | |
| 537 | // Notifications class. |
| 538 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notifications.php'; |
| 539 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notification-event.php'; |
| 540 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notification-event-runner.php'; |
| 541 | // Add notification manual events for lite version. |
| 542 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notifications/notification-events.php'; |
| 543 | } |
| 544 | |
| 545 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/exclude-page-metabox.php'; |
| 546 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/verified-badge/Controller.php'; |
| 547 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/site-notes/Controller.php'; |
| 548 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/api-request.php'; |
| 549 | |
| 550 | if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
| 551 | // Late loading classes (self instantiating) |
| 552 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/tracking.php'; |
| 553 | } |
| 554 | |
| 555 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/frontend.php'; |
| 556 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/seedprod.php'; |
| 557 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/measurement-protocol-v4.php'; |
| 558 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/feature-feedback/class-monsterInsights-feature-feedback.php'; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Get the tracking mode for the frontend scripts. |
| 563 | * |
| 564 | * @return string |
| 565 | * @deprecated Since 8.3 with the removal of ga compatibility |
| 566 | */ |
| 567 | public function get_tracking_mode() { |
| 568 | |
| 569 | if ( ! isset( $this->tracking_mode ) ) { |
| 570 | // This will already be set to 'analytics' to anybody already using the plugin before 7.15.0. |
| 571 | $this->tracking_mode = monsterinsights_get_option( 'tracking_mode', 'gtag' ); |
| 572 | } |
| 573 | |
| 574 | return $this->tracking_mode; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * Fired when the plugin is activated. |
| 580 | * |
| 581 | * @access public |
| 582 | * |
| 583 | * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false otherwise. |
| 584 | * |
| 585 | * @return void |
| 586 | * @global object $wpdb The WordPress database object. |
| 587 | * @since 6.0.0 |
| 588 | * |
| 589 | * @global int $wp_version The version of WordPress for this install. |
| 590 | */ |
| 591 | function monsterinsights_lite_activation_hook( $network_wide ) { |
| 592 | $url = admin_url( 'plugins.php' ); |
| 593 | // Check for MS dashboard |
| 594 | if ( is_network_admin() ) { |
| 595 | $url = network_admin_url( 'plugins.php' ); |
| 596 | } |
| 597 | |
| 598 | if ( class_exists( 'MonsterInsights' ) ) { |
| 599 | deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 600 | wp_die(sprintf(esc_html__('Please uninstall and remove MonsterInsights Pro before activating Google Analytics for WordPress by MonsterInsights. The Lite version has not been activated. %1$sClick here to return to the Dashboard%2$s.', 'google-analytics-by-wordpress'), '<a href="' . $url . '">', '</a>')); // phpcs:ignore |
| 601 | } |
| 602 | |
| 603 | require_once plugin_dir_path( __FILE__ ) . 'includes/compatibility-check.php'; |
| 604 | $compatibility = MonsterInsights_Compatibility_Check::get_instance(); |
| 605 | $compatibility->maybe_deactivate_plugin( plugin_basename( __FILE__ ) ); |
| 606 | |
| 607 | // Add transient to trigger redirect. |
| 608 | set_transient( '_monsterinsights_activation_redirect', 1, 30 ); |
| 609 | } |
| 610 | |
| 611 | register_activation_hook( __FILE__, 'monsterinsights_lite_activation_hook' ); |
| 612 | |
| 613 | /** |
| 614 | * Fired when the plugin is uninstalled. |
| 615 | * |
| 616 | * @access public |
| 617 | * @return void |
| 618 | * @since 6.0.0 |
| 619 | * |
| 620 | */ |
| 621 | function monsterinsights_lite_uninstall_hook() { |
| 622 | wp_cache_flush(); |
| 623 | |
| 624 | // Note, if both MI Pro and Lite are active, this is an MI Pro instance |
| 625 | // Therefore MI Lite can only use functions of the instance common to |
| 626 | // both plugins. If it needs to be pro specific, then include a file that |
| 627 | // has that method. |
| 628 | $instance = MonsterInsights(); |
| 629 | |
| 630 | $instance->define_globals(); |
| 631 | $instance->load_settings(); |
| 632 | |
| 633 | // If uninstalling via wp-cli load admin-specific files only here. |
| 634 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 635 | define( 'WP_ADMIN', true ); |
| 636 | $instance->require_files(); |
| 637 | $instance->load_auth(); |
| 638 | $instance->notices = new MonsterInsights_Notice_Admin(); |
| 639 | $instance->reporting = new MonsterInsights_Reporting(); |
| 640 | $instance->api_auth = new MonsterInsights_API_Auth(); |
| 641 | } |
| 642 | |
| 643 | // Don't delete any data if the PRO version is already active. |
| 644 | if ( monsterinsights_is_pro_version() ) { |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | require_once 'includes/admin/uninstall.php'; |
| 649 | |
| 650 | if ( is_multisite() ) { |
| 651 | $site_list = get_sites(); |
| 652 | foreach ( (array) $site_list as $site ) { |
| 653 | switch_to_blog( $site->blog_id ); |
| 654 | |
| 655 | // Deauthenticate. |
| 656 | $instance->api_auth->delete_auth(); |
| 657 | |
| 658 | // Delete report cache. |
| 659 | $instance->reporting->delete_aggregate_data(); |
| 660 | |
| 661 | // Delete options. |
| 662 | $instance->api_auth->uninstall_auth(); |
| 663 | |
| 664 | restore_current_blog(); |
| 665 | } |
| 666 | // Delete network auth using a custom function as some variables are not initiated. |
| 667 | $instance->api_auth->uninstall_network_auth(); |
| 668 | |
| 669 | // Delete network data. |
| 670 | $instance->reporting->delete_aggregate_data( 'network' ); |
| 671 | } else { |
| 672 | // Delete auth. |
| 673 | $instance->api_auth->delete_auth(); |
| 674 | |
| 675 | // Delete report cache. |
| 676 | $instance->reporting->delete_aggregate_data(); |
| 677 | |
| 678 | // Delete options. |
| 679 | $instance->api_auth->uninstall_auth(); |
| 680 | } |
| 681 | |
| 682 | // Clear notification cron schedules. |
| 683 | $schedules = wp_get_schedules(); |
| 684 | |
| 685 | if ( is_array( $schedules ) && ! empty( $schedules ) ) { |
| 686 | foreach ( $schedules as $key => $value ) { |
| 687 | if ( 0 === strpos( $key, 'monsterinsights_notification_' ) ) { |
| 688 | $cron_hook = implode( '_', explode( '_', $key, -2 ) ) . '_cron'; |
| 689 | wp_clear_scheduled_hook( $cron_hook ); |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | // Delete the notifications data. |
| 695 | $instance->notifications->delete_notifications_data(); |
| 696 | |
| 697 | // Delete Popular Posts data. |
| 698 | MonsterInsights_Popular_Posts_Inline()->get_cache()->delete_data(); |
| 699 | MonsterInsights_Popular_Posts_Widget()->get_cache()->delete_data(); |
| 700 | |
| 701 | // Delete other options. |
| 702 | monsterinsights_uninstall_remove_options(); |
| 703 | } |
| 704 | |
| 705 | register_uninstall_hook( __FILE__, 'monsterinsights_lite_uninstall_hook' ); |
| 706 | |
| 707 | /** |
| 708 | * The main function responsible for returning the one true MonsterInsights_Lite |
| 709 | * Instance to functions everywhere. |
| 710 | * |
| 711 | * Use this function like you would a global variable, except without needing |
| 712 | * to declare the global. |
| 713 | * |
| 714 | * Example: <?php $monsterinsights = MonsterInsights_Lite(); ?> |
| 715 | * |
| 716 | * @return MonsterInsights_Lite The singleton MonsterInsights_Lite instance. |
| 717 | * @uses MonsterInsights_Lite::get_instance() Retrieve MonsterInsights_Lite instance. |
| 718 | * |
| 719 | * @since 6.0.0 |
| 720 | * |
| 721 | */ |
| 722 | function MonsterInsights_Lite() { |
| 723 | return MonsterInsights_Lite::get_instance(); |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * MonsterInsights Install and Updates. |
| 728 | * |
| 729 | * This function is used install and upgrade MonsterInsights. This is used for upgrade routines |
| 730 | * that can be done automatically, behind the scenes without the need for user interaction |
| 731 | * (for example pagination or user input required), as well as the initial install. |
| 732 | * |
| 733 | * @return void |
| 734 | * @global string $wp_version WordPress version (provided by WordPress core). |
| 735 | * @uses MonsterInsights_Lite::load_settings() Loads MonsterInsights settings |
| 736 | * @uses MonsterInsights_Install::init() Runs upgrade process |
| 737 | * |
| 738 | * @since 6.0.0 |
| 739 | * @access public |
| 740 | * |
| 741 | */ |
| 742 | function monsterinsights_lite_install_and_upgrade() { |
| 743 | require_once plugin_dir_path( __FILE__ ) . 'includes/compatibility-check.php'; |
| 744 | $compatibility = MonsterInsights_Compatibility_Check::get_instance(); |
| 745 | |
| 746 | // If the WordPress site doesn't meet the correct WP or PHP version requirements, don't activate MonsterInsights |
| 747 | if ( ! $compatibility->is_php_compatible() || ! $compatibility->is_wp_compatible() ) { |
| 748 | if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
| 749 | return; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | // Don't run if MI Pro is installed |
| 754 | if ( class_exists( 'MonsterInsights' ) ) { |
| 755 | if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
| 756 | return; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | // Load settings and globals (so we can use/set them during the upgrade process) |
| 761 | MonsterInsights_Lite()->define_globals(); |
| 762 | MonsterInsights_Lite()->load_settings(); |
| 763 | |
| 764 | // Load in Auth |
| 765 | MonsterInsights()->load_auth(); |
| 766 | |
| 767 | // Load upgrade file |
| 768 | require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/install.php'; |
| 769 | |
| 770 | // Run the MonsterInsights upgrade routines |
| 771 | $updates = new MonsterInsights_Install(); |
| 772 | $updates->init(); |
| 773 | } |
| 774 | |
| 775 | /** |
| 776 | * MonsterInsights check for install and update processes. |
| 777 | * |
| 778 | * This function is used to call the MonsterInsights automatic upgrade class, which in turn |
| 779 | * checks to see if there are any update procedures to be run, and if |
| 780 | * so runs them. Also installs MonsterInsights for the first time. |
| 781 | * |
| 782 | * @return void |
| 783 | * @uses MonsterInsights_Install() Runs install and upgrade process. |
| 784 | * |
| 785 | * @since 6.0.0 |
| 786 | * @access public |
| 787 | * |
| 788 | */ |
| 789 | function monsterinsights_lite_call_install_and_upgrade() { |
| 790 | add_action( 'wp_loaded', 'monsterinsights_lite_install_and_upgrade' ); |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Returns the MonsterInsights combined object that you can use for both |
| 795 | * MonsterInsights Lite and Pro Users. When both plugins active, defers to the |
| 796 | * more complete Pro object. |
| 797 | * |
| 798 | * Warning: Do not use this in Lite or Pro specific code (use the individual objects instead). |
| 799 | * Also do not use in the MonsterInsights Lite/Pro upgrade and install routines. |
| 800 | * |
| 801 | * Use this function like you would a global variable, except without needing |
| 802 | * to declare the global. |
| 803 | * |
| 804 | * Prevents the need to do conditional global object logic when you have code that you want to work with |
| 805 | * both Pro and Lite. |
| 806 | * |
| 807 | * Example: <?php $monsterinsights = MonsterInsights(); ?> |
| 808 | * |
| 809 | * @return MonsterInsights The singleton MonsterInsights instance. |
| 810 | * @uses MonsterInsights::get_instance() Retrieve MonsterInsights Pro instance. |
| 811 | * @uses MonsterInsights_Lite::get_instance() Retrieve MonsterInsights Lite instance. |
| 812 | * |
| 813 | * @since 6.0.0 |
| 814 | * |
| 815 | */ |
| 816 | if ( ! function_exists( 'MonsterInsights' ) ) { |
| 817 | function MonsterInsights() { |
| 818 | return ( class_exists( 'MonsterInsights' ) ? MonsterInsights_Pro() : MonsterInsights_Lite() ); |
| 819 | } |
| 820 | |
| 821 | add_action( 'plugins_loaded', 'MonsterInsights' ); |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * Remove scheduled cron hooks during deactivation. |
| 826 | */ |
| 827 | function monsterinsights_lite_deactivation_hook() { |
| 828 | wp_clear_scheduled_hook( 'monsterinsights_usage_tracking_cron' ); |
| 829 | wp_clear_scheduled_hook( 'monsterinsights_email_summaries_cron' ); |
| 830 | } |
| 831 | |
| 832 | register_deactivation_hook( __FILE__, 'monsterinsights_lite_deactivation_hook' ); |
| 833 |