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: 7.15.0 |
10
|
|
|
* Requires at least: 3.8.0 |
11
|
|
|
* Requires PHP: 5.2 |
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, [email protected] |
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 = '7.15.0'; |
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
|
|
|
*/ |
180
|
|
|
public $tracking_mode; |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Primary class constructor. |
184
|
|
|
* |
185
|
|
|
* @since 6.0.0 |
186
|
|
|
* @access public |
187
|
|
|
*/ |
188
|
|
|
public function __construct() { |
189
|
|
|
// We don't use this |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Returns the singleton instance of the class. |
194
|
|
|
* |
195
|
|
|
* @access public |
196
|
|
|
* @since 6.0.0 |
197
|
|
|
* |
198
|
|
|
* @return object The MonsterInsights_Lite object. |
199
|
|
|
*/ |
200
|
|
|
public static function get_instance() { |
201
|
|
|
|
202
|
|
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof MonsterInsights_Lite ) ) { |
203
|
|
|
self::$instance = new MonsterInsights_Lite(); |
204
|
|
|
self::$instance->file = __FILE__; |
205
|
|
|
|
206
|
|
|
global $wp_version; |
207
|
|
|
|
208
|
|
|
// Detect non-supported WordPress version and return early |
209
|
|
|
if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) { |
|
|
|
|
210
|
|
|
add_action( 'admin_notices', array( self::$instance, 'monsterinsights_wp_notice' ) ); |
211
|
|
|
return; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
// Detect Pro version and return early |
215
|
|
|
if ( defined( 'MONSTERINSIGHTS_PRO_VERSION' ) ) { |
216
|
|
|
add_action( 'admin_notices', array( self::$instance, 'monsterinsights_pro_notice' ) ); |
217
|
|
|
return; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
// Define constants |
221
|
|
|
self::$instance->define_globals(); |
222
|
|
|
|
223
|
|
|
// Load in settings |
224
|
|
|
self::$instance->load_settings(); |
225
|
|
|
|
226
|
|
|
// Load in Licensing |
227
|
|
|
self::$instance->load_licensing(); |
228
|
|
|
|
229
|
|
|
// Load in Auth |
230
|
|
|
self::$instance->load_auth(); |
231
|
|
|
|
232
|
|
|
// Load files |
233
|
|
|
self::$instance->require_files(); |
234
|
|
|
|
235
|
|
|
// This does the version to version background upgrade routines and initial install |
236
|
|
|
$mi_version = get_option( 'monsterinsights_current_version', '5.5.3' ); |
237
|
|
|
if ( version_compare( $mi_version, '7.15.0', '<' ) ) { |
|
|
|
|
238
|
|
|
monsterinsights_lite_call_install_and_upgrade(); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
if ( is_admin() ) { |
242
|
|
|
new AM_Deactivation_Survey( 'MonsterInsights', basename( dirname( __FILE__ ) ) ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
// Load the plugin textdomain. |
246
|
|
|
add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ), 15 ); |
247
|
|
|
|
248
|
|
|
// Load admin only components. |
249
|
|
|
if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
250
|
|
|
self::$instance->notices = new MonsterInsights_Notice_Admin(); |
|
|
|
|
251
|
|
|
self::$instance->reporting = new MonsterInsights_Reporting(); |
252
|
|
|
self::$instance->api_auth = new MonsterInsights_API_Auth(); |
|
|
|
|
253
|
|
|
self::$instance->routes = new MonsterInsights_Rest_Routes(); |
254
|
|
|
self::$instance->notifications = new MonsterInsights_Notifications(); |
255
|
|
|
self::$instance->notification_event = new MonsterInsights_Notification_Event(); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
if ( monsterinsights_is_pro_version() ) { |
259
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'pro/includes/load.php'; |
260
|
|
|
} else { |
261
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/load.php'; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
// Run hook to load MonsterInsights addons. |
265
|
|
|
do_action( 'monsterinsights_load_plugins' ); // the updater class for each addon needs to be instantiated via `monsterinsights_updater` |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
return self::$instance; |
269
|
|
|
|
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Throw error on object clone |
274
|
|
|
* |
275
|
|
|
* The whole idea of the singleton design pattern is that there is a single |
276
|
|
|
* object therefore, we don't want the object to be cloned. |
277
|
|
|
* |
278
|
|
|
* @since 6.0.0 |
279
|
|
|
* @access public |
280
|
|
|
* |
281
|
|
|
* @return void |
282
|
|
|
*/ |
283
|
|
|
public function __clone() { |
284
|
|
|
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'google-analytics-for-wordpress' ), '6.0.0' ); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Disable unserializing of the class |
289
|
|
|
* |
290
|
|
|
* Attempting to wakeup an MonsterInsights instance will throw a doing it wrong notice. |
291
|
|
|
* |
292
|
|
|
* @since 6.0.0 |
293
|
|
|
* @access public |
294
|
|
|
* |
295
|
|
|
* @return void |
296
|
|
|
*/ |
297
|
|
|
public function __wakeup() { |
298
|
|
|
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'google-analytics-for-wordpress' ), '6.0.0' ); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Magic get function. |
303
|
|
|
* |
304
|
|
|
* We use this to lazy load certain functionality. Right now used to lazyload |
305
|
|
|
* the API & Auth frontend, so it's only loaded if user is using a plugin |
306
|
|
|
* that requires it. |
307
|
|
|
* |
308
|
|
|
* @since 7.0.0 |
309
|
|
|
* @access public |
310
|
|
|
* |
311
|
|
|
* @return void |
312
|
|
|
*/ |
313
|
|
|
public function __get( $key ) { |
314
|
|
|
if ( $key === 'auth' ) { |
315
|
|
|
if ( empty( self::$instance->auth ) ) { |
316
|
|
|
// LazyLoad Auth for Frontend |
317
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/auth.php'; |
318
|
|
|
self::$instance->auth = new MonsterInsights_Auth(); |
319
|
|
|
} |
320
|
|
|
return self::$instance->$key; |
321
|
|
|
} else { |
322
|
|
|
return self::$instance->$key; |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Define MonsterInsights constants. |
328
|
|
|
* |
329
|
|
|
* This function defines all of the MonsterInsights PHP constants. |
330
|
|
|
* |
331
|
|
|
* @since 6.0.0 |
332
|
|
|
* @access public |
333
|
|
|
* |
334
|
|
|
* @return void |
335
|
|
|
*/ |
336
|
|
|
public function define_globals() { |
337
|
|
|
|
338
|
|
|
if ( ! defined( 'MONSTERINSIGHTS_VERSION' ) ) { |
339
|
|
|
define( 'MONSTERINSIGHTS_VERSION', $this->version ); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
if ( ! defined( 'MONSTERINSIGHTS_LITE_VERSION' ) ) { |
343
|
|
|
define( 'MONSTERINSIGHTS_LITE_VERSION', MONSTERINSIGHTS_VERSION ); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_NAME' ) ) { |
347
|
|
|
define( 'MONSTERINSIGHTS_PLUGIN_NAME', $this->plugin_name ); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_SLUG' ) ) { |
351
|
|
|
define( 'MONSTERINSIGHTS_PLUGIN_SLUG', $this->plugin_slug ); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_FILE' ) ) { |
355
|
|
|
define( 'MONSTERINSIGHTS_PLUGIN_FILE', $this->file ); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_DIR' ) ) { |
359
|
|
|
define( 'MONSTERINSIGHTS_PLUGIN_DIR', plugin_dir_path( $this->file ) ); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_URL' ) ) { |
363
|
|
|
define( 'MONSTERINSIGHTS_PLUGIN_URL', plugin_dir_url( $this->file ) ); |
364
|
|
|
} |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Loads the plugin textdomain for translation. |
369
|
|
|
* |
370
|
|
|
* @access public |
371
|
|
|
* @since 6.0.0 |
372
|
|
|
* |
373
|
|
|
* @return void |
374
|
|
|
*/ |
375
|
|
|
public function load_plugin_textdomain() { |
376
|
|
|
|
377
|
|
|
$mi_locale = get_locale(); |
378
|
|
|
if ( function_exists( 'get_user_locale' ) ) { |
379
|
|
|
$mi_locale = get_user_locale(); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
// Traditional WordPress plugin locale filter. |
383
|
|
|
$mi_locale = apply_filters( 'plugin_locale', $mi_locale, 'google-analytics-for-wordpress' ); |
384
|
|
|
$mi_mofile = sprintf( '%1$s-%2$s.mo', 'google-analytics-for-wordpress', $mi_locale ); |
385
|
|
|
|
386
|
|
|
// Look for wp-content/languages/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo |
387
|
|
|
$mi_mofile1 = WP_LANG_DIR . '/google-analytics-for-wordpress/' . $mi_mofile; |
388
|
|
|
|
389
|
|
|
// Look in wp-content/languages/plugins/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo |
390
|
|
|
$mi_mofile2 = WP_LANG_DIR . '/plugins/google-analytics-for-wordpress/' . $mi_mofile; |
391
|
|
|
|
392
|
|
|
// Look in wp-content/languages/plugins/google-analytics-for-wordpress-{lang}_{country}.mo |
393
|
|
|
$mi_mofile3 = WP_LANG_DIR . '/plugins/' . $mi_mofile; |
394
|
|
|
|
395
|
|
|
// Look in wp-content/plugins/google-analytics-for-wordpress/languages/google-analytics-for-wordpress-{lang}_{country}.mo |
396
|
|
|
$mi_mofile4 = dirname( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ) . '/languages/'; |
397
|
|
|
$mi_mofile4 = apply_filters( 'monsterinsights_lite_languages_directory', $mi_mofile4 ); |
398
|
|
|
|
399
|
|
|
if ( file_exists( $mi_mofile1 ) ) { |
400
|
|
|
load_textdomain( 'google-analytics-for-wordpress', $mi_mofile1 ); |
401
|
|
|
} elseif ( file_exists( $mi_mofile2 ) ) { |
402
|
|
|
load_textdomain( 'google-analytics-for-wordpress', $mi_mofile2 ); |
403
|
|
|
} elseif ( file_exists( $mi_mofile3 ) ) { |
404
|
|
|
load_textdomain( 'google-analytics-for-wordpress', $mi_mofile3 ); |
405
|
|
|
} else { |
406
|
|
|
load_plugin_textdomain( 'google-analytics-for-wordpress', false, $mi_mofile4 ); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Output a nag notice if the user has an out of date WP version installed |
413
|
|
|
* |
414
|
|
|
* @access public |
415
|
|
|
* @since 6.0.0 |
416
|
|
|
* |
417
|
|
|
* @return void |
418
|
|
|
*/ |
419
|
|
|
public function monsterinsights_wp_notice() { |
420
|
|
|
$url = admin_url( 'plugins.php' ); |
421
|
|
|
// Check for MS dashboard |
422
|
|
|
if( is_network_admin() ) { |
423
|
|
|
$url = network_admin_url( 'plugins.php' ); |
424
|
|
|
} |
425
|
|
|
?> |
426
|
|
|
<div class="error"> |
427
|
|
|
<p><?php echo sprintf( esc_html__( 'Sorry, but your version of WordPress does not meet MonsterInsights\'s required version of %1$s3.8%2$s to run properly. The plugin not been activated. %3$sClick here to return to the Dashboard%4$s.', 'google-analytics-for-wordpress' ), '<strong>', '</strong>', '<a href="' . $url . '">', '</a>' ); ?></p> |
428
|
|
|
</div> |
429
|
|
|
<?php |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Output a nag notice if the user has both Lite and Pro activated |
434
|
|
|
* |
435
|
|
|
* @access public |
436
|
|
|
* @since 6.0.0 |
437
|
|
|
* |
438
|
|
|
* @return void |
439
|
|
|
*/ |
440
|
|
|
public function monsterinsights_pro_notice() { |
441
|
|
|
$url = admin_url( 'plugins.php' ); |
442
|
|
|
// Check for MS dashboard |
443
|
|
|
if( is_network_admin() ) { |
444
|
|
|
$url = network_admin_url( 'plugins.php' ); |
445
|
|
|
} |
446
|
|
|
?> |
447
|
|
|
<div class="error"> |
448
|
|
|
<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> |
449
|
|
|
</div> |
450
|
|
|
<?php |
451
|
|
|
|
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Loads MonsterInsights settings |
456
|
|
|
* |
457
|
|
|
* Adds the items to the base object, and adds the helper functions. |
458
|
|
|
* |
459
|
|
|
* @since 6.0.0 |
460
|
|
|
* @access public |
461
|
|
|
* |
462
|
|
|
* @return void |
463
|
|
|
*/ |
464
|
|
|
public function load_settings() { |
465
|
|
|
global $monsterinsights_settings; |
466
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/options.php'; |
467
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/helpers.php'; |
468
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/deprecated.php'; |
469
|
|
|
$monsterinsights_settings = monsterinsights_get_options(); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Loads MonsterInsights License |
475
|
|
|
* |
476
|
|
|
* Loads license class used by MonsterInsights |
477
|
|
|
* |
478
|
|
|
* @since 7.0.0 |
479
|
|
|
* @access public |
480
|
|
|
* |
481
|
|
|
* @return void |
482
|
|
|
*/ |
483
|
|
|
public function load_licensing(){ |
484
|
|
|
if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
485
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/license-compat.php'; |
486
|
|
|
self::$instance->license = new MonsterInsights_License_Compat(); |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Loads MonsterInsights Auth |
492
|
|
|
* |
493
|
|
|
* Loads auth used by MonsterInsights |
494
|
|
|
* |
495
|
|
|
* @since 7.0.0 |
496
|
|
|
* @access public |
497
|
|
|
* |
498
|
|
|
* @return void |
499
|
|
|
*/ |
500
|
|
|
public function load_auth() { |
501
|
|
|
if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
502
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/auth.php'; |
503
|
|
|
self::$instance->auth = new MonsterInsights_Auth(); |
504
|
|
|
} |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* Loads all files into scope. |
509
|
|
|
* |
510
|
|
|
* @access public |
511
|
|
|
* @since 6.0.0 |
512
|
|
|
* |
513
|
|
|
* @return void |
514
|
|
|
*/ |
515
|
|
|
public function require_files() { |
516
|
|
|
|
517
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/capabilities.php'; |
518
|
|
|
|
519
|
|
|
if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
520
|
|
|
|
521
|
|
|
// Lite and Pro files |
522
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-deactivation-survey.php'; |
523
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/ajax.php'; |
524
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/admin.php'; |
525
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/common.php'; |
526
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notice.php'; |
527
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/autoupdate.php'; |
528
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/review.php'; |
529
|
|
|
|
530
|
|
|
// Pages |
531
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/settings.php'; |
532
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/tools.php'; |
533
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/reports.php'; |
534
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/addons.php'; |
535
|
|
|
|
536
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/api-auth.php'; |
537
|
|
|
|
538
|
|
|
// Reports |
539
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/abstract-report.php'; |
540
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/overview.php'; |
541
|
|
|
|
542
|
|
|
// Reporting Functionality |
543
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reporting.php'; |
544
|
|
|
|
545
|
|
|
// Routes used by Vue |
546
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/routes.php'; |
547
|
|
|
|
548
|
|
|
// Load gutenberg editor functions |
549
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/gutenberg/gutenberg.php'; |
550
|
|
|
|
551
|
|
|
// Emails |
552
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/emails/class-emails.php'; |
553
|
|
|
|
554
|
|
|
// Notifications class. |
555
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notifications.php'; |
556
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notification-event.php'; |
557
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notification-event-runner.php'; |
558
|
|
|
// Add notification manual events for lite version. |
559
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notifications/notification-events.php'; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/api-request.php'; |
563
|
|
|
|
564
|
|
|
if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
565
|
|
|
// Late loading classes (self instantiating) |
566
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/tracking.php'; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/frontend.php'; |
570
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/seedprod.php'; |
571
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/measurement-protocol.php'; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* Get the tracking mode for the frontend scripts. |
576
|
|
|
* |
577
|
|
|
* @return string |
578
|
|
|
*/ |
579
|
|
|
public function get_tracking_mode() { |
580
|
|
|
|
581
|
|
|
if ( ! isset( $this->tracking_mode ) ) { |
582
|
|
|
// This will already be set to 'analytics' to anybody already using the plugin before 7.15.0. |
583
|
|
|
$this->tracking_mode = monsterinsights_get_option( 'tracking_mode', 'gtag' ); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
return $this->tracking_mode; |
587
|
|
|
} |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* Fired when the plugin is activated. |
592
|
|
|
* |
593
|
|
|
* @access public |
594
|
|
|
* @since 6.0.0 |
595
|
|
|
* |
596
|
|
|
* @global int $wp_version The version of WordPress for this install. |
597
|
|
|
* @global object $wpdb The WordPress database object. |
598
|
|
|
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false otherwise. |
599
|
|
|
* |
600
|
|
|
* @return void |
601
|
|
|
*/ |
602
|
|
|
function monsterinsights_lite_activation_hook( $network_wide ) { |
|
|
|
|
603
|
|
|
|
604
|
|
|
global $wp_version; |
605
|
|
|
|
606
|
|
|
$url = admin_url( 'plugins.php' ); |
607
|
|
|
// Check for MS dashboard |
608
|
|
|
if ( is_network_admin() ) { |
609
|
|
|
$url = network_admin_url( 'plugins.php' ); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) { |
|
|
|
|
613
|
|
|
deactivate_plugins( plugin_basename( __FILE__ ) ); |
614
|
|
|
wp_die( sprintf( esc_html__( 'Sorry, but your version of WordPress does not meet MonsterInsight\'s required version of %1$s3.8%2$s to run properly. The plugin not been activated. %3$sClick here to return to the Dashboard%4$s.', 'google-analytics-by-wordpress' ), '<strong>', '</strong>', '<a href="' . $url . '">', '</a>' ) ); |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
if ( class_exists( 'MonsterInsights' ) ) { |
618
|
|
|
deactivate_plugins( plugin_basename( __FILE__ ) ); |
619
|
|
|
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>' ) ); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
// Add transient to trigger redirect. |
623
|
|
|
set_transient( '_monsterinsights_activation_redirect', 1, 30 ); |
624
|
|
|
} |
625
|
|
|
register_activation_hook( __FILE__, 'monsterinsights_lite_activation_hook' ); |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* Fired when the plugin is uninstalled. |
629
|
|
|
* |
630
|
|
|
* @access public |
631
|
|
|
* @since 6.0.0 |
632
|
|
|
* |
633
|
|
|
* @return void |
634
|
|
|
*/ |
635
|
|
|
function monsterinsights_lite_uninstall_hook() { |
636
|
|
|
wp_cache_flush(); |
637
|
|
|
|
638
|
|
|
// Note, if both MI Pro and Lite are active, this is an MI Pro instance |
639
|
|
|
// Therefore MI Lite can only use functions of the instance common to |
640
|
|
|
// both plugins. If it needs to be pro specific, then include a file that |
641
|
|
|
// has that method. |
642
|
|
|
$instance = MonsterInsights(); |
643
|
|
|
|
644
|
|
|
// If uninstalling via wp-cli load admin-specific files only here. |
645
|
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
|
|
|
646
|
|
|
define( 'WP_ADMIN', true ); |
647
|
|
|
$instance->require_files(); |
648
|
|
|
$instance->load_auth(); |
649
|
|
|
$instance->notices = new MonsterInsights_Notice_Admin(); |
|
|
|
|
650
|
|
|
$instance->reporting = new MonsterInsights_Reporting(); |
651
|
|
|
$instance->api_auth = new MonsterInsights_API_Auth(); |
|
|
|
|
652
|
|
|
} |
653
|
|
|
|
654
|
|
|
// Don't delete any data if the PRO version is already active. |
655
|
|
|
if ( monsterinsights_is_pro_version() ) { |
656
|
|
|
return; |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
if ( is_multisite() ) { |
660
|
|
|
$site_list = get_sites(); |
661
|
|
|
foreach ( (array) $site_list as $site ) { |
662
|
|
|
switch_to_blog( $site->blog_id ); |
663
|
|
|
|
664
|
|
|
// Delete auth |
665
|
|
|
$instance->api_auth->delete_auth(); |
|
|
|
|
666
|
|
|
|
667
|
|
|
// Delete data |
668
|
|
|
$instance->reporting->delete_aggregate_data('site'); |
669
|
|
|
|
670
|
|
|
restore_current_blog(); |
671
|
|
|
} |
672
|
|
|
// Delete network auth using a custom function as some variables are not initiated. |
673
|
|
|
$instance->api_auth->uninstall_network_auth(); |
|
|
|
|
674
|
|
|
|
675
|
|
|
// Delete network data |
676
|
|
|
$instance->reporting->delete_aggregate_data('network'); |
677
|
|
|
} else { |
678
|
|
|
// Delete auth |
679
|
|
|
$instance->api_auth->delete_auth(); |
680
|
|
|
|
681
|
|
|
// Delete data |
682
|
|
|
$instance->reporting->delete_aggregate_data('site'); |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
// Clear notification cron schedules |
686
|
|
|
$schedules = wp_get_schedules(); |
687
|
|
|
|
688
|
|
|
if ( is_array( $schedules ) && ! empty( $schedules ) ) { |
689
|
|
|
foreach ( $schedules as $key => $value ) { |
690
|
|
|
if ( 0 === strpos($key, "monsterinsights_notification_") ) { |
691
|
|
|
$cron_hook = implode("_", explode( "_", $key, -2 ) ) . '_cron'; |
692
|
|
|
wp_clear_scheduled_hook( $cron_hook ); |
693
|
|
|
} |
694
|
|
|
} |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
} |
698
|
|
|
register_uninstall_hook( __FILE__, 'monsterinsights_lite_uninstall_hook' ); |
699
|
|
|
|
700
|
|
|
/** |
701
|
|
|
* The main function responsible for returning the one true MonsterInsights_Lite |
702
|
|
|
* Instance to functions everywhere. |
703
|
|
|
* |
704
|
|
|
* Use this function like you would a global variable, except without needing |
705
|
|
|
* to declare the global. |
706
|
|
|
* |
707
|
|
|
* Example: <?php $monsterinsights = MonsterInsights_Lite(); ?> |
708
|
|
|
* |
709
|
|
|
* @since 6.0.0 |
710
|
|
|
* |
711
|
|
|
* @uses MonsterInsights_Lite::get_instance() Retrieve MonsterInsights_Lite instance. |
712
|
|
|
* |
713
|
|
|
* @return MonsterInsights_Lite The singleton MonsterInsights_Lite instance. |
714
|
|
|
*/ |
715
|
|
|
function MonsterInsights_Lite() { |
716
|
|
|
return MonsterInsights_Lite::get_instance(); |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
/** |
720
|
|
|
* MonsterInsights Install and Updates. |
721
|
|
|
* |
722
|
|
|
* This function is used install and upgrade MonsterInsights. This is used for upgrade routines |
723
|
|
|
* that can be done automatically, behind the scenes without the need for user interaction |
724
|
|
|
* (for example pagination or user input required), as well as the initial install. |
725
|
|
|
* |
726
|
|
|
* @since 6.0.0 |
727
|
|
|
* @access public |
728
|
|
|
* |
729
|
|
|
* @global string $wp_version WordPress version (provided by WordPress core). |
730
|
|
|
* @uses MonsterInsights_Lite::load_settings() Loads MonsterInsights settings |
731
|
|
|
* @uses MonsterInsights_Install::init() Runs upgrade process |
732
|
|
|
* |
733
|
|
|
* @return void |
734
|
|
|
*/ |
735
|
|
|
function monsterinsights_lite_install_and_upgrade() { |
736
|
|
|
global $wp_version; |
737
|
|
|
|
738
|
|
|
// If the WordPress site doesn't meet the correct WP version requirements, don't activate MonsterInsights |
739
|
|
|
if ( version_compare( $wp_version, '3.8', '<' ) ) { |
740
|
|
|
if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
741
|
|
|
return; |
742
|
|
|
} |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
// Don't run if MI Pro is installed |
746
|
|
|
if ( class_exists( 'MonsterInsights' ) ) { |
747
|
|
|
if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
748
|
|
|
return; |
749
|
|
|
} |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
|
753
|
|
|
// Load settings and globals (so we can use/set them during the upgrade process) |
754
|
|
|
MonsterInsights_Lite()->define_globals(); |
755
|
|
|
MonsterInsights_Lite()->load_settings(); |
756
|
|
|
|
757
|
|
|
// Load in Auth |
758
|
|
|
MonsterInsights()->load_auth(); |
759
|
|
|
|
760
|
|
|
// Load upgrade file |
761
|
|
|
require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/install.php'; |
762
|
|
|
|
763
|
|
|
// Run the MonsterInsights upgrade routines |
764
|
|
|
$updates = new MonsterInsights_Install(); |
765
|
|
|
$updates->init(); |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
/** |
769
|
|
|
* MonsterInsights check for install and update processes. |
770
|
|
|
* |
771
|
|
|
* This function is used to call the MonsterInsights automatic upgrade class, which in turn |
772
|
|
|
* checks to see if there are any update procedures to be run, and if |
773
|
|
|
* so runs them. Also installs MonsterInsights for the first time. |
774
|
|
|
* |
775
|
|
|
* @since 6.0.0 |
776
|
|
|
* @access public |
777
|
|
|
* |
778
|
|
|
* @uses MonsterInsights_Install() Runs install and upgrade process. |
779
|
|
|
* |
780
|
|
|
* @return void |
781
|
|
|
*/ |
782
|
|
|
function monsterinsights_lite_call_install_and_upgrade(){ |
783
|
|
|
add_action( 'wp_loaded', 'monsterinsights_lite_install_and_upgrade' ); |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
/** |
787
|
|
|
* Returns the MonsterInsights combined object that you can use for both |
788
|
|
|
* MonsterInsights Lite and Pro Users. When both plugins active, defers to the |
789
|
|
|
* more complete Pro object. |
790
|
|
|
* |
791
|
|
|
* Warning: Do not use this in Lite or Pro specific code (use the individual objects instead). |
792
|
|
|
* Also do not use in the MonsterInsights Lite/Pro upgrade and install routines. |
793
|
|
|
* |
794
|
|
|
* Use this function like you would a global variable, except without needing |
795
|
|
|
* to declare the global. |
796
|
|
|
* |
797
|
|
|
* Prevents the need to do conditional global object logic when you have code that you want to work with |
798
|
|
|
* both Pro and Lite. |
799
|
|
|
* |
800
|
|
|
* Example: <?php $monsterinsights = MonsterInsights(); ?> |
801
|
|
|
* |
802
|
|
|
* @since 6.0.0 |
803
|
|
|
* |
804
|
|
|
* @uses MonsterInsights::get_instance() Retrieve MonsterInsights Pro instance. |
805
|
|
|
* @uses MonsterInsights_Lite::get_instance() Retrieve MonsterInsights Lite instance. |
806
|
|
|
* |
807
|
|
|
* @return MonsterInsights The singleton MonsterInsights instance. |
808
|
|
|
*/ |
809
|
|
|
if ( ! function_exists( 'MonsterInsights' ) ) { |
810
|
|
|
function MonsterInsights() { |
811
|
|
|
return ( class_exists( 'MonsterInsights' ) ? MonsterInsights_Pro() : MonsterInsights_Lite() ); |
|
|
|
|
812
|
|
|
} |
813
|
|
|
add_action( 'plugins_loaded', 'MonsterInsights' ); |
814
|
|
|
} |
815
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths