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