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