Passed
Push — master ( 29aa47...a9ceae )
by Chris
09:18
created

monsterinsights_is_code_installed_frontend()   B

Complexity

Conditions 9
Paths 11

Size

Total Lines 41
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 21
c 1
b 0
f 0
nc 11
nop 0
dl 0
loc 41
rs 8.0555
1
<?php
2
/**
3
 * Helper functions.
4
 *
5
 * @since 6.0.0
6
 *
7
 * @package MonsterInsights
8
 * @subpackage Helper
9
 * @author  Chris Christoff
10
 */
11
12
// Exit if accessed directly
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
function monsterinsights_is_page_reload() {
18
	// Can't be a refresh without having a referrer
19
	if ( ! isset( $_SERVER['HTTP_REFERER'] ) ) {
20
		return false;
21
	}
22
23
	// IF the referrer is identical to the current page request, then it's a refresh
24
	return ( parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_PATH ) === parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );
25
}
26
27
28
function monsterinsights_track_user( $user_id = -1 ) {
29
	if ( $user_id === -1 ) {
30
		$user = wp_get_current_user();
31
	} else {
32
		$user = new WP_User( $user_id );
33
	}
34
35
	$track_user  = true;
36
	$roles     = monsterinsights_get_option( 'ignore_users', array() );
37
38
	if ( ! empty( $roles ) && is_array( $roles ) ) {
0 ignored issues
show
introduced by
The condition is_array($roles) is always false.
Loading history...
39
		foreach ( $roles as $role ) {
40
			if ( is_string( $role ) ) {
41
				if ( user_can( $user, $role ) ) {
42
					$track_user = false;
43
					break;
44
				}
45
			}
46
		}
47
	}
48
49
	$track_super_admin = apply_filters( 'monsterinsights_track_super_admins', false );
50
	if ( $track_super_admin === false && is_multisite() && is_super_admin() ) {
51
		$track_user = false;
52
	}
53
54
	// or if UA code is not entered
55
	$ua_code = monsterinsights_get_ua();
56
	if ( empty( $ua_code ) ) {
57
		$track_user = false;
58
	}
59
60
	return apply_filters( 'monsterinsights_track_user', $track_user, $user );
61
}
62
63
function monsterinsights_get_client_id( $payment_id = false ) {
64
	if ( is_object( $payment_id ) ) {
65
		$payment_id = $payment_id->ID;
66
	}
67
	$user_cid    = monsterinsights_get_uuid();
68
	$saved_cid   = ! empty( $payment_id ) ? get_post_meta( $payment_id, '_yoast_gau_uuid', true ) : false;
69
70
	if ( ! empty( $payment_id ) && ! empty( $saved_cid ) ) {
71
		return $saved_cid;
72
	} else if ( ! empty( $user_cid ) ) {
73
		return $user_cid;
74
	} else {
75
		return monsterinsights_generate_uuid();
76
	}
77
}
78
79
/**
80
 * Returns the Google Analytics clientId to store for later use
81
 *
82
 * @since 6.0.0
83
 *
84
 * @link  https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#getClientId
85
 *
86
 * @return bool|string False if cookie isn't set, GA UUID otherwise
87
 */
88
function monsterinsights_get_uuid() {
89
	if ( empty( $_COOKIE['_ga'] ) ) {
90
		return false;
91
	}
92
93
	/**
94
	 * Example cookie formats:
95
	 *
96
	 * GA1.2.XXXXXXX.YYYYY
97
	 * _ga=1.2.XXXXXXX.YYYYYY -- We want the XXXXXXX.YYYYYY part
98
	 *
99
	 */
100
101
	$ga_cookie    = $_COOKIE['_ga'];
102
	$cookie_parts = explode('.', $ga_cookie );
103
	if ( is_array( $cookie_parts ) && ! empty( $cookie_parts[2] ) && ! empty( $cookie_parts[3] ) ) {
104
		$uuid = (string) $cookie_parts[2] . '.' . (string) $cookie_parts[3];
105
		if ( is_string( $uuid ) ) {
0 ignored issues
show
introduced by
The condition is_string($uuid) is always true.
Loading history...
106
			return $uuid;
107
		} else {
108
			return false;
109
		}
110
	} else {
111
		return false;
112
	}
113
}
114
115
116
/**
117
 * Generate UUID v4 function - needed to generate a CID when one isn't available
118
 *
119
 * @link http://www.stumiller.me/implementing-google-analytics-measurement-protocol-in-php-and-wordpress/
120
 *
121
 * @since 6.1.8
122
 * @return string
123
 */
124
function monsterinsights_generate_uuid() {
125
126
	return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
127
128
		// 32 bits for "time_low"
129
		mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
130
131
		// 16 bits for "time_mid"
132
		mt_rand( 0, 0xffff ),
133
134
		// 16 bits for "time_hi_and_version",
135
		// four most significant bits holds version number 4
136
		mt_rand( 0, 0x0fff ) | 0x4000,
137
138
		// 16 bits, 8 bits for "clk_seq_hi_res",
139
		// 8 bits for "clk_seq_low",
140
		// two most significant bits holds zero and one for variant DCE1.1
141
		mt_rand( 0, 0x3fff ) | 0x8000,
142
143
		// 48 bits for "node"
144
		mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
145
	);
146
}
147
148
/**
149
 * Returns the Google Analytics clientId to store for later use
150
 *
151
 * @since 6.0.0
152
 *
153
 * @return GA UUID or error code.
0 ignored issues
show
Bug introduced by
The type GA was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
154
 */
155
function monsterinsights_get_cookie( $debug = false ) {
156
	if ( empty( $_COOKIE['_ga'] ) ) {
157
		return ( $debug ) ? 'FCE' : false;
158
	}
159
160
	$ga_cookie    = $_COOKIE['_ga'];
161
	$cookie_parts = explode('.', $ga_cookie );
162
	if ( is_array( $cookie_parts ) && ! empty( $cookie_parts[2] ) && ! empty( $cookie_parts[3] ) ) {
163
		$uuid = (string) $cookie_parts[2] . '.' . (string) $cookie_parts[3];
164
		if ( is_string( $uuid ) ) {
0 ignored issues
show
introduced by
The condition is_string($uuid) is always true.
Loading history...
165
			return $ga_cookie;
166
		} else {
167
			return ( $debug ) ? 'FA' : false;
168
		}
169
	} else {
170
		return ( $debug ) ? 'FAE' : false;
171
	}
172
}
173
174
175
function monsterinsights_generate_ga_client_id() {
176
	return rand(100000000,999999999) . '.' . time();
177
}
178
179
180
/**
181
 * Hours between two timestamps.
182
 *
183
 * @access public
184
 * @since 6.0.0
185
 *
186
 * @param string $start Timestamp of start time (in seconds since Unix).
187
 * @param string $stop  Timestamp of stop time (in seconds since Unix). Optional. If not used, current_time (in UTC 0 / GMT ) is used.
188
 *
189
 * @return int Hours between the two timestamps, rounded.
190
 */
191
function monsterinsights_hours_between( $start, $stop = false ) {
192
	if ( $stop === false ) {
193
		$stop = time();
194
	}
195
196
	$diff = (int) abs( $stop -  $start );
197
	$hours = round( $diff / HOUR_IN_SECONDS );
198
	return $hours;
199
}
200
201
/**
202
 * Is This MonsterInsights Pro?
203
 *
204
 * We use this function monsterinsights_to determine if the install is a pro version or a lite version install of MonsterInsights.
205
 * If the install is a lite version we disable the install from admin functionality[1] for addons as WordPress.org requires us to,
206
 * we change the links for where to get support (wp.org forum for free; our site for pro), we use this determine what class to load as
207
 * the base class in addons (to avoid fatal errors) and we use this on the system info page to know what constants to display values for
208
 * as the lite and pro versions of our plugin have different constants (and names for those constants) you can declare and use.
209
 *
210
 * [1] Note: This is not "feature-locking" under GPL guidelines but rather something WordPress.org requires us to do to stay
211
 * in compliance with their rules. We wish we didn't have to do this, as in our oppinion this diminishes the user experience
212
 * of users installing our free and premium addons, and we'd love to turn this on for non-Pro installs, but we're not allowed to.
213
 * If WordPress.org ever changes their mind on this subject, we'd totally turn on that feature for Lite installs in a heartbeat.
214
 *
215
 * @todo  Are we allowed to turn on admin installing if the user has to manually declare a PHP constant (and thus would not be on
216
 * either by default or via any sort of user interface)? If so, we could add a constant for forcing Pro version so that users can see
217
 * for themselves that we're not feature locking anything inside the plugin + it would make it easier for our team to test stuff (both via
218
 * Travis-CI but also when installing addons to test with the Lite version). Also this would allow for a better user experience for users
219
 * who want that feature.
220
 *
221
 * @since 6.0.0
222
 * @access public
223
 *
224
 * @return bool True if pro version.
225
 */
226
function monsterinsights_is_pro_version() {
227
	if ( class_exists( 'MonsterInsights' ) ) {
228
		return true;
229
	} else {
230
		return false;
231
	}
232
}
233
234
235
/**
236
 * Get the user roles of this WordPress blog
237
 *
238
 * @return array
239
 */
240
function monsterinsights_get_roles() {
241
	global $wp_roles;
242
243
	$all_roles = $wp_roles->roles;
244
	$roles     = array();
245
246
	/**
247
	 * Filter: 'editable_roles' - Allows filtering of the roles shown within the plugin (and elsewhere in WP as it's a WP filter)
248
	 *
249
	 * @api array $all_roles
250
	 */
251
	$editable_roles = apply_filters( 'editable_roles', $all_roles );
252
253
	foreach ( $editable_roles as $id => $name ) {
254
		$roles[ $id ] = translate_user_role( $name['name'] );
255
	}
256
257
	return $roles;
258
}
259
260
/**
261
 * Get the user roles which can manage options. Used to prevent these roles from getting unselected in the settings.
262
 *
263
 * @return array
264
 */
265
function monsterinsights_get_manage_options_roles() {
266
	global $wp_roles;
267
268
	$all_roles = $wp_roles->roles;
269
	$roles     = array();
270
271
	/**
272
	 * Filter: 'editable_roles' - Allows filtering of the roles shown within the plugin (and elsewhere in WP as it's a WP filter)
273
	 *
274
	 * @api array $all_roles
275
	 */
276
	$editable_roles = apply_filters( 'editable_roles', $all_roles );
277
278
	foreach ( $editable_roles as $id => $role ) {
279
		if ( isset( $role['capabilities']['manage_options'] ) && $role['capabilities']['manage_options'] ) {
280
			$roles[ $id ] = translate_user_role( $role['name'] );
281
		}
282
	}
283
284
	return $roles;
285
}
286
287
/** Need to escape in advance of passing in $text. */
288
function monsterinsights_get_message( $type = 'error', $text = '' ) {
289
	$div = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $div is dead and can be removed.
Loading history...
290
	if ( $type === 'error' || $type === 'alert' || $type === 'success' || $type === 'info' ) {
291
		$base = MonsterInsights();
292
		return $base->notices->display_inline_notice( 'monsterinsights_standard_notice', '', $text, $type, false, array( 'skip_message_escape' => true ) );
293
	} else {
294
		return '';
295
	}
296
}
297
298
function monsterinsights_is_dev_url( $url = '' ) {
299
	$is_local_url = false;
300
	// Trim it up
301
	$url = strtolower( trim( $url ) );
302
	// Need to get the host...so let's add the scheme so we can use parse_url
303
	if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) {
304
		$url = 'http://' . $url;
305
	}
306
	$url_parts = parse_url( $url );
307
	$host      = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false;
308
	if ( ! empty( $url ) && ! empty( $host ) ) {
309
		if ( false !== ip2long( $host ) ) {
310
			if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
311
				$is_local_url = true;
312
			}
313
		} else if ( 'localhost' === $host ) {
314
			$is_local_url = true;
315
		}
316
317
		$tlds_to_check = array( '.local', ':8888', ':8080', ':8081', '.invalid', '.example', '.test' );
318
		foreach ( $tlds_to_check as $tld ) {
319
				if ( false !== strpos( $host, $tld ) ) {
320
					$is_local_url = true;
321
					break;
322
				}
323
324
		}
325
		if ( substr_count( $host, '.' ) > 1 ) {
326
			$subdomains_to_check =  array( 'dev.', '*.staging.', 'beta.', 'test.' );
327
			foreach ( $subdomains_to_check as $subdomain ) {
328
				$subdomain = str_replace( '.', '(.)', $subdomain );
329
				$subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain );
330
				if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) {
331
					$is_local_url = true;
332
					break;
333
				}
334
			}
335
		}
336
	}
337
	return $is_local_url;
338
}
339
340
// Set cookie to expire in 2 years
341
function monsterinsights_get_cookie_expiration_date( $time ) {
342
	return date('D, j F Y H:i:s', time() + $time );
343
}
344
345
function monsterinsights_string_ends_with( $string, $ending ) {
346
	$strlen = strlen($string);
347
	$endinglen = strlen($ending);
348
	if ( $endinglen > $strlen ) {
349
		return false;
350
	}
351
	return substr_compare( $string, $ending, $strlen - $endinglen, $endinglen) === 0;
352
}
353
354
function monsterinsights_string_starts_with( $string, $start ) {
355
	if ( ! is_string( $string ) || ! is_string( $start ) ) {
356
		return false;
357
	}
358
359
	return substr( $string, 0, strlen( $start ) ) === $start;
360
}
361
362
function monsterinsights_get_country_list( $translated = false ) {
363
	if ( $translated ) {
364
		$countries = array(
365
			''   => '',
366
			'US' => __( 'United States', 'google-analytics-for-wordpress' ),
367
			'CA' => __( 'Canada', 'google-analytics-for-wordpress' ),
368
			'GB' => __( 'United Kingdom', 'google-analytics-for-wordpress' ),
369
			'AF' => __( 'Afghanistan', 'google-analytics-for-wordpress' ),
370
			'AX' => __( '&#197;land Islands', 'google-analytics-for-wordpress' ),
371
			'AL' => __( 'Albania', 'google-analytics-for-wordpress' ),
372
			'DZ' => __( 'Algeria', 'google-analytics-for-wordpress' ),
373
			'AS' => __( 'American Samoa', 'google-analytics-for-wordpress' ),
374
			'AD' => __( 'Andorra', 'google-analytics-for-wordpress' ),
375
			'AO' => __( 'Angola', 'google-analytics-for-wordpress' ),
376
			'AI' => __( 'Anguilla', 'google-analytics-for-wordpress' ),
377
			'AQ' => __( 'Antarctica', 'google-analytics-for-wordpress' ),
378
			'AG' => __( 'Antigua and Barbuda', 'google-analytics-for-wordpress' ),
379
			'AR' => __( 'Argentina', 'google-analytics-for-wordpress' ),
380
			'AM' => __( 'Armenia', 'google-analytics-for-wordpress' ),
381
			'AW' => __( 'Aruba', 'google-analytics-for-wordpress' ),
382
			'AU' => __( 'Australia', 'google-analytics-for-wordpress' ),
383
			'AT' => __( 'Austria', 'google-analytics-for-wordpress' ),
384
			'AZ' => __( 'Azerbaijan', 'google-analytics-for-wordpress' ),
385
			'BS' => __( 'Bahamas', 'google-analytics-for-wordpress' ),
386
			'BH' => __( 'Bahrain', 'google-analytics-for-wordpress' ),
387
			'BD' => __( 'Bangladesh', 'google-analytics-for-wordpress' ),
388
			'BB' => __( 'Barbados', 'google-analytics-for-wordpress' ),
389
			'BY' => __( 'Belarus', 'google-analytics-for-wordpress' ),
390
			'BE' => __( 'Belgium', 'google-analytics-for-wordpress' ),
391
			'BZ' => __( 'Belize', 'google-analytics-for-wordpress' ),
392
			'BJ' => __( 'Benin', 'google-analytics-for-wordpress' ),
393
			'BM' => __( 'Bermuda', 'google-analytics-for-wordpress' ),
394
			'BT' => __( 'Bhutan', 'google-analytics-for-wordpress' ),
395
			'BO' => __( 'Bolivia', 'google-analytics-for-wordpress' ),
396
			'BQ' => __( 'Bonaire, Saint Eustatius and Saba', 'google-analytics-for-wordpress' ),
397
			'BA' => __( 'Bosnia and Herzegovina', 'google-analytics-for-wordpress' ),
398
			'BW' => __( 'Botswana', 'google-analytics-for-wordpress' ),
399
			'BV' => __( 'Bouvet Island', 'google-analytics-for-wordpress' ),
400
			'BR' => __( 'Brazil', 'google-analytics-for-wordpress' ),
401
			'IO' => __( 'British Indian Ocean Territory', 'google-analytics-for-wordpress' ),
402
			'BN' => __( 'Brunei Darrussalam', 'google-analytics-for-wordpress' ),
403
			'BG' => __( 'Bulgaria', 'google-analytics-for-wordpress' ),
404
			'BF' => __( 'Burkina Faso', 'google-analytics-for-wordpress' ),
405
			'BI' => __( 'Burundi', 'google-analytics-for-wordpress' ),
406
			'KH' => __( 'Cambodia', 'google-analytics-for-wordpress' ),
407
			'CM' => __( 'Cameroon', 'google-analytics-for-wordpress' ),
408
			'CV' => __( 'Cape Verde', 'google-analytics-for-wordpress' ),
409
			'KY' => __( 'Cayman Islands', 'google-analytics-for-wordpress' ),
410
			'CF' => __( 'Central African Republic', 'google-analytics-for-wordpress' ),
411
			'TD' => __( 'Chad', 'google-analytics-for-wordpress' ),
412
			'CL' => __( 'Chile', 'google-analytics-for-wordpress' ),
413
			'CN' => __( 'China', 'google-analytics-for-wordpress' ),
414
			'CX' => __( 'Christmas Island', 'google-analytics-for-wordpress' ),
415
			'CC' => __( 'Cocos Islands', 'google-analytics-for-wordpress' ),
416
			'CO' => __( 'Colombia', 'google-analytics-for-wordpress' ),
417
			'KM' => __( 'Comoros', 'google-analytics-for-wordpress' ),
418
			'CD' => __( 'Congo, Democratic People\'s Republic', 'google-analytics-for-wordpress' ),
419
			'CG' => __( 'Congo, Republic of', 'google-analytics-for-wordpress' ),
420
			'CK' => __( 'Cook Islands', 'google-analytics-for-wordpress' ),
421
			'CR' => __( 'Costa Rica', 'google-analytics-for-wordpress' ),
422
			'CI' => __( 'Cote d\'Ivoire', 'google-analytics-for-wordpress' ),
423
			'HR' => __( 'Croatia/Hrvatska', 'google-analytics-for-wordpress' ),
424
			'CU' => __( 'Cuba', 'google-analytics-for-wordpress' ),
425
			'CW' => __( 'Cura&Ccedil;ao', 'google-analytics-for-wordpress' ),
426
			'CY' => __( 'Cyprus', 'google-analytics-for-wordpress' ),
427
			'CZ' => __( 'Czechia', 'google-analytics-for-wordpress' ),
428
			'DK' => __( 'Denmark', 'google-analytics-for-wordpress' ),
429
			'DJ' => __( 'Djibouti', 'google-analytics-for-wordpress' ),
430
			'DM' => __( 'Dominica', 'google-analytics-for-wordpress' ),
431
			'DO' => __( 'Dominican Republic', 'google-analytics-for-wordpress' ),
432
			'TP' => __( 'East Timor', 'google-analytics-for-wordpress' ),
433
			'EC' => __( 'Ecuador', 'google-analytics-for-wordpress' ),
434
			'EG' => __( 'Egypt', 'google-analytics-for-wordpress' ),
435
			'GQ' => __( 'Equatorial Guinea', 'google-analytics-for-wordpress' ),
436
			'SV' => __( 'El Salvador', 'google-analytics-for-wordpress' ),
437
			'ER' => __( 'Eritrea', 'google-analytics-for-wordpress' ),
438
			'EE' => __( 'Estonia', 'google-analytics-for-wordpress' ),
439
			'ET' => __( 'Ethiopia', 'google-analytics-for-wordpress' ),
440
			'FK' => __( 'Falkland Islands', 'google-analytics-for-wordpress' ),
441
			'FO' => __( 'Faroe Islands', 'google-analytics-for-wordpress' ),
442
			'FJ' => __( 'Fiji', 'google-analytics-for-wordpress' ),
443
			'FI' => __( 'Finland', 'google-analytics-for-wordpress' ),
444
			'FR' => __( 'France', 'google-analytics-for-wordpress' ),
445
			'GF' => __( 'French Guiana', 'google-analytics-for-wordpress' ),
446
			'PF' => __( 'French Polynesia', 'google-analytics-for-wordpress' ),
447
			'TF' => __( 'French Southern Territories', 'google-analytics-for-wordpress' ),
448
			'GA' => __( 'Gabon', 'google-analytics-for-wordpress' ),
449
			'GM' => __( 'Gambia', 'google-analytics-for-wordpress' ),
450
			'GE' => __( 'Georgia', 'google-analytics-for-wordpress' ),
451
			'DE' => __( 'Germany', 'google-analytics-for-wordpress' ),
452
			'GR' => __( 'Greece', 'google-analytics-for-wordpress' ),
453
			'GH' => __( 'Ghana', 'google-analytics-for-wordpress' ),
454
			'GI' => __( 'Gibraltar', 'google-analytics-for-wordpress' ),
455
			'GL' => __( 'Greenland', 'google-analytics-for-wordpress' ),
456
			'GD' => __( 'Grenada', 'google-analytics-for-wordpress' ),
457
			'GP' => __( 'Guadeloupe', 'google-analytics-for-wordpress' ),
458
			'GU' => __( 'Guam', 'google-analytics-for-wordpress' ),
459
			'GT' => __( 'Guatemala', 'google-analytics-for-wordpress' ),
460
			'GG' => __( 'Guernsey', 'google-analytics-for-wordpress' ),
461
			'GN' => __( 'Guinea', 'google-analytics-for-wordpress' ),
462
			'GW' => __( 'Guinea-Bissau', 'google-analytics-for-wordpress' ),
463
			'GY' => __( 'Guyana', 'google-analytics-for-wordpress' ),
464
			'HT' => __( 'Haiti', 'google-analytics-for-wordpress' ),
465
			'HM' => __( 'Heard and McDonald Islands', 'google-analytics-for-wordpress' ),
466
			'VA' => __( 'Holy See (City Vatican State)', 'google-analytics-for-wordpress' ),
467
			'HN' => __( 'Honduras', 'google-analytics-for-wordpress' ),
468
			'HK' => __( 'Hong Kong', 'google-analytics-for-wordpress' ),
469
			'HU' => __( 'Hungary', 'google-analytics-for-wordpress' ),
470
			'IS' => __( 'Iceland', 'google-analytics-for-wordpress' ),
471
			'IN' => __( 'India', 'google-analytics-for-wordpress' ),
472
			'ID' => __( 'Indonesia', 'google-analytics-for-wordpress' ),
473
			'IR' => __( 'Iran', 'google-analytics-for-wordpress' ),
474
			'IQ' => __( 'Iraq', 'google-analytics-for-wordpress' ),
475
			'IE' => __( 'Ireland', 'google-analytics-for-wordpress' ),
476
			'IM' => __( 'Isle of Man', 'google-analytics-for-wordpress' ),
477
			'IL' => __( 'Israel', 'google-analytics-for-wordpress' ),
478
			'IT' => __( 'Italy', 'google-analytics-for-wordpress' ),
479
			'JM' => __( 'Jamaica', 'google-analytics-for-wordpress' ),
480
			'JP' => __( 'Japan', 'google-analytics-for-wordpress' ),
481
			'JE' => __( 'Jersey', 'google-analytics-for-wordpress' ),
482
			'JO' => __( 'Jordan', 'google-analytics-for-wordpress' ),
483
			'KZ' => __( 'Kazakhstan', 'google-analytics-for-wordpress' ),
484
			'KE' => __( 'Kenya', 'google-analytics-for-wordpress' ),
485
			'KI' => __( 'Kiribati', 'google-analytics-for-wordpress' ),
486
			'KW' => __( 'Kuwait', 'google-analytics-for-wordpress' ),
487
			'KG' => __( 'Kyrgyzstan', 'google-analytics-for-wordpress' ),
488
			'LA' => __( 'Lao People\'s Democratic Republic', 'google-analytics-for-wordpress' ),
489
			'LV' => __( 'Latvia', 'google-analytics-for-wordpress' ),
490
			'LB' => __( 'Lebanon', 'google-analytics-for-wordpress' ),
491
			'LS' => __( 'Lesotho', 'google-analytics-for-wordpress' ),
492
			'LR' => __( 'Liberia', 'google-analytics-for-wordpress' ),
493
			'LY' => __( 'Libyan Arab Jamahiriya', 'google-analytics-for-wordpress' ),
494
			'LI' => __( 'Liechtenstein', 'google-analytics-for-wordpress' ),
495
			'LT' => __( 'Lithuania', 'google-analytics-for-wordpress' ),
496
			'LU' => __( 'Luxembourg', 'google-analytics-for-wordpress' ),
497
			'MO' => __( 'Macau', 'google-analytics-for-wordpress' ),
498
			'MK' => __( 'Macedonia (FYROM)', 'google-analytics-for-wordpress' ),
499
			'MG' => __( 'Madagascar', 'google-analytics-for-wordpress' ),
500
			'MW' => __( 'Malawi', 'google-analytics-for-wordpress' ),
501
			'MY' => __( 'Malaysia', 'google-analytics-for-wordpress' ),
502
			'MV' => __( 'Maldives', 'google-analytics-for-wordpress' ),
503
			'ML' => __( 'Mali', 'google-analytics-for-wordpress' ),
504
			'MT' => __( 'Malta', 'google-analytics-for-wordpress' ),
505
			'MH' => __( 'Marshall Islands', 'google-analytics-for-wordpress' ),
506
			'MQ' => __( 'Martinique', 'google-analytics-for-wordpress' ),
507
			'MR' => __( 'Mauritania', 'google-analytics-for-wordpress' ),
508
			'MU' => __( 'Mauritius', 'google-analytics-for-wordpress' ),
509
			'YT' => __( 'Mayotte', 'google-analytics-for-wordpress' ),
510
			'MX' => __( 'Mexico', 'google-analytics-for-wordpress' ),
511
			'FM' => __( 'Micronesia', 'google-analytics-for-wordpress' ),
512
			'MD' => __( 'Moldova, Republic of', 'google-analytics-for-wordpress' ),
513
			'MC' => __( 'Monaco', 'google-analytics-for-wordpress' ),
514
			'MN' => __( 'Mongolia', 'google-analytics-for-wordpress' ),
515
			'ME' => __( 'Montenegro', 'google-analytics-for-wordpress' ),
516
			'MS' => __( 'Montserrat', 'google-analytics-for-wordpress' ),
517
			'MA' => __( 'Morocco', 'google-analytics-for-wordpress' ),
518
			'MZ' => __( 'Mozambique', 'google-analytics-for-wordpress' ),
519
			'MM' => __( 'Myanmar', 'google-analytics-for-wordpress' ),
520
			'NA' => __( 'Namibia', 'google-analytics-for-wordpress' ),
521
			'NR' => __( 'Nauru', 'google-analytics-for-wordpress' ),
522
			'NP' => __( 'Nepal', 'google-analytics-for-wordpress' ),
523
			'NL' => __( 'Netherlands', 'google-analytics-for-wordpress' ),
524
			'AN' => __( 'Netherlands Antilles', 'google-analytics-for-wordpress' ),
525
			'NC' => __( 'New Caledonia', 'google-analytics-for-wordpress' ),
526
			'NZ' => __( 'New Zealand', 'google-analytics-for-wordpress' ),
527
			'NI' => __( 'Nicaragua', 'google-analytics-for-wordpress' ),
528
			'NE' => __( 'Niger', 'google-analytics-for-wordpress' ),
529
			'NG' => __( 'Nigeria', 'google-analytics-for-wordpress' ),
530
			'NU' => __( 'Niue', 'google-analytics-for-wordpress' ),
531
			'NF' => __( 'Norfolk Island', 'google-analytics-for-wordpress' ),
532
			'KP' => __( 'North Korea', 'google-analytics-for-wordpress' ),
533
			'MP' => __( 'Northern Mariana Islands', 'google-analytics-for-wordpress' ),
534
			'NO' => __( 'Norway', 'google-analytics-for-wordpress' ),
535
			'OM' => __( 'Oman', 'google-analytics-for-wordpress' ),
536
			'PK' => __( 'Pakistan', 'google-analytics-for-wordpress' ),
537
			'PW' => __( 'Palau', 'google-analytics-for-wordpress' ),
538
			'PS' => __( 'Palestinian Territories', 'google-analytics-for-wordpress' ),
539
			'PA' => __( 'Panama', 'google-analytics-for-wordpress' ),
540
			'PG' => __( 'Papua New Guinea', 'google-analytics-for-wordpress' ),
541
			'PY' => __( 'Paraguay', 'google-analytics-for-wordpress' ),
542
			'PE' => __( 'Peru', 'google-analytics-for-wordpress' ),
543
			'PH' => __( 'Philippines', 'google-analytics-for-wordpress' ),
544
			'PN' => __( 'Pitcairn Island', 'google-analytics-for-wordpress' ),
545
			'PL' => __( 'Poland', 'google-analytics-for-wordpress' ),
546
			'PT' => __( 'Portugal', 'google-analytics-for-wordpress' ),
547
			'PR' => __( 'Puerto Rico', 'google-analytics-for-wordpress' ),
548
			'QA' => __( 'Qatar', 'google-analytics-for-wordpress' ),
549
			'XK' => __( 'Republic of Kosovo', 'google-analytics-for-wordpress' ),
550
			'RE' => __( 'Reunion Island', 'google-analytics-for-wordpress' ),
551
			'RO' => __( 'Romania', 'google-analytics-for-wordpress' ),
552
			'RU' => __( 'Russian Federation', 'google-analytics-for-wordpress' ),
553
			'RW' => __( 'Rwanda', 'google-analytics-for-wordpress' ),
554
			'BL' => __( 'Saint Barth&eacute;lemy', 'google-analytics-for-wordpress' ),
555
			'SH' => __( 'Saint Helena', 'google-analytics-for-wordpress' ),
556
			'KN' => __( 'Saint Kitts and Nevis', 'google-analytics-for-wordpress' ),
557
			'LC' => __( 'Saint Lucia', 'google-analytics-for-wordpress' ),
558
			'MF' => __( 'Saint Martin (French)', 'google-analytics-for-wordpress' ),
559
			'SX' => __( 'Saint Martin (Dutch)', 'google-analytics-for-wordpress' ),
560
			'PM' => __( 'Saint Pierre and Miquelon', 'google-analytics-for-wordpress' ),
561
			'VC' => __( 'Saint Vincent and the Grenadines', 'google-analytics-for-wordpress' ),
562
			'SM' => __( 'San Marino', 'google-analytics-for-wordpress' ),
563
			'ST' => __( 'S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'google-analytics-for-wordpress' ),
564
			'SA' => __( 'Saudi Arabia', 'google-analytics-for-wordpress' ),
565
			'SN' => __( 'Senegal', 'google-analytics-for-wordpress' ),
566
			'RS' => __( 'Serbia', 'google-analytics-for-wordpress' ),
567
			'SC' => __( 'Seychelles', 'google-analytics-for-wordpress' ),
568
			'SL' => __( 'Sierra Leone', 'google-analytics-for-wordpress' ),
569
			'SG' => __( 'Singapore', 'google-analytics-for-wordpress' ),
570
			'SK' => __( 'Slovak Republic', 'google-analytics-for-wordpress' ),
571
			'SI' => __( 'Slovenia', 'google-analytics-for-wordpress' ),
572
			'SB' => __( 'Solomon Islands', 'google-analytics-for-wordpress' ),
573
			'SO' => __( 'Somalia', 'google-analytics-for-wordpress' ),
574
			'ZA' => __( 'South Africa', 'google-analytics-for-wordpress' ),
575
			'GS' => __( 'South Georgia', 'google-analytics-for-wordpress' ),
576
			'KR' => __( 'South Korea', 'google-analytics-for-wordpress' ),
577
			'SS' => __( 'South Sudan', 'google-analytics-for-wordpress' ),
578
			'ES' => __( 'Spain', 'google-analytics-for-wordpress' ),
579
			'LK' => __( 'Sri Lanka', 'google-analytics-for-wordpress' ),
580
			'SD' => __( 'Sudan', 'google-analytics-for-wordpress' ),
581
			'SR' => __( 'Suriname', 'google-analytics-for-wordpress' ),
582
			'SJ' => __( 'Svalbard and Jan Mayen Islands', 'google-analytics-for-wordpress' ),
583
			'SZ' => __( 'Swaziland', 'google-analytics-for-wordpress' ),
584
			'SE' => __( 'Sweden', 'google-analytics-for-wordpress' ),
585
			'CH' => __( 'Switzerland', 'google-analytics-for-wordpress' ),
586
			'SY' => __( 'Syrian Arab Republic', 'google-analytics-for-wordpress' ),
587
			'TW' => __( 'Taiwan', 'google-analytics-for-wordpress' ),
588
			'TJ' => __( 'Tajikistan', 'google-analytics-for-wordpress' ),
589
			'TZ' => __( 'Tanzania', 'google-analytics-for-wordpress' ),
590
			'TH' => __( 'Thailand', 'google-analytics-for-wordpress' ),
591
			'TL' => __( 'Timor-Leste', 'google-analytics-for-wordpress' ),
592
			'TG' => __( 'Togo', 'google-analytics-for-wordpress' ),
593
			'TK' => __( 'Tokelau', 'google-analytics-for-wordpress' ),
594
			'TO' => __( 'Tonga', 'google-analytics-for-wordpress' ),
595
			'TT' => __( 'Trinidad and Tobago', 'google-analytics-for-wordpress' ),
596
			'TN' => __( 'Tunisia', 'google-analytics-for-wordpress' ),
597
			'TR' => __( 'Turkey', 'google-analytics-for-wordpress' ),
598
			'TM' => __( 'Turkmenistan', 'google-analytics-for-wordpress' ),
599
			'TC' => __( 'Turks and Caicos Islands', 'google-analytics-for-wordpress' ),
600
			'TV' => __( 'Tuvalu', 'google-analytics-for-wordpress' ),
601
			'UG' => __( 'Uganda', 'google-analytics-for-wordpress' ),
602
			'UA' => __( 'Ukraine', 'google-analytics-for-wordpress' ),
603
			'AE' => __( 'United Arab Emirates', 'google-analytics-for-wordpress' ),
604
			'UY' => __( 'Uruguay', 'google-analytics-for-wordpress' ),
605
			'UM' => __( 'US Minor Outlying Islands', 'google-analytics-for-wordpress' ),
606
			'UZ' => __( 'Uzbekistan', 'google-analytics-for-wordpress' ),
607
			'VU' => __( 'Vanuatu', 'google-analytics-for-wordpress' ),
608
			'VE' => __( 'Venezuela', 'google-analytics-for-wordpress' ),
609
			'VN' => __( 'Vietnam', 'google-analytics-for-wordpress' ),
610
			'VG' => __( 'Virgin Islands (British)', 'google-analytics-for-wordpress' ),
611
			'VI' => __( 'Virgin Islands (USA)', 'google-analytics-for-wordpress' ),
612
			'WF' => __( 'Wallis and Futuna Islands', 'google-analytics-for-wordpress' ),
613
			'EH' => __( 'Western Sahara', 'google-analytics-for-wordpress' ),
614
			'WS' => __( 'Western Samoa', 'google-analytics-for-wordpress' ),
615
			'YE' => __( 'Yemen', 'google-analytics-for-wordpress' ),
616
			'ZM' => __( 'Zambia', 'google-analytics-for-wordpress' ),
617
			'ZW' => __( 'Zimbabwe', 'google-analytics-for-wordpress' ),
618
		);
619
	} else {
620
		$countries = array(
621
			''   => '',
622
			'US' => 'United States',
623
			'CA' => 'Canada',
624
			'GB' => 'United Kingdom',
625
			'AF' => 'Afghanistan',
626
			'AX' => '&#197;land Islands',
627
			'AL' => 'Albania',
628
			'DZ' => 'Algeria',
629
			'AS' => 'American Samoa',
630
			'AD' => 'Andorra',
631
			'AO' => 'Angola',
632
			'AI' => 'Anguilla',
633
			'AQ' => 'Antarctica',
634
			'AG' => 'Antigua and Barbuda',
635
			'AR' => 'Argentina',
636
			'AM' => 'Armenia',
637
			'AW' => 'Aruba',
638
			'AU' => 'Australia',
639
			'AT' => 'Austria',
640
			'AZ' => 'Azerbaijan',
641
			'BS' => 'Bahamas',
642
			'BH' => 'Bahrain',
643
			'BD' => 'Bangladesh',
644
			'BB' => 'Barbados',
645
			'BY' => 'Belarus',
646
			'BE' => 'Belgium',
647
			'BZ' => 'Belize',
648
			'BJ' => 'Benin',
649
			'BM' => 'Bermuda',
650
			'BT' => 'Bhutan',
651
			'BO' => 'Bolivia',
652
			'BQ' => 'Bonaire, Saint Eustatius and Saba',
653
			'BA' => 'Bosnia and Herzegovina',
654
			'BW' => 'Botswana',
655
			'BV' => 'Bouvet Island',
656
			'BR' => 'Brazil',
657
			'IO' => 'British Indian Ocean Territory',
658
			'BN' => 'Brunei Darrussalam',
659
			'BG' => 'Bulgaria',
660
			'BF' => 'Burkina Faso',
661
			'BI' => 'Burundi',
662
			'KH' => 'Cambodia',
663
			'CM' => 'Cameroon',
664
			'CV' => 'Cape Verde',
665
			'KY' => 'Cayman Islands',
666
			'CF' => 'Central African Republic',
667
			'TD' => 'Chad',
668
			'CL' => 'Chile',
669
			'CN' => 'China',
670
			'CX' => 'Christmas Island',
671
			'CC' => 'Cocos Islands',
672
			'CO' => 'Colombia',
673
			'KM' => 'Comoros',
674
			'CD' => 'Congo, Democratic People\'s Republic',
675
			'CG' => 'Congo, Republic of',
676
			'CK' => 'Cook Islands',
677
			'CR' => 'Costa Rica',
678
			'CI' => 'Cote d\'Ivoire',
679
			'HR' => 'Croatia/Hrvatska',
680
			'CU' => 'Cuba',
681
			'CW' => 'Cura&Ccedil;ao',
682
			'CY' => 'Cyprus',
683
			'CZ' => 'Czechia',
684
			'DK' => 'Denmark',
685
			'DJ' => 'Djibouti',
686
			'DM' => 'Dominica',
687
			'DO' => 'Dominican Republic',
688
			'TP' => 'East Timor',
689
			'EC' => 'Ecuador',
690
			'EG' => 'Egypt',
691
			'GQ' => 'Equatorial Guinea',
692
			'SV' => 'El Salvador',
693
			'ER' => 'Eritrea',
694
			'EE' => 'Estonia',
695
			'ET' => 'Ethiopia',
696
			'FK' => 'Falkland Islands',
697
			'FO' => 'Faroe Islands',
698
			'FJ' => 'Fiji',
699
			'FI' => 'Finland',
700
			'FR' => 'France',
701
			'GF' => 'French Guiana',
702
			'PF' => 'French Polynesia',
703
			'TF' => 'French Southern Territories',
704
			'GA' => 'Gabon',
705
			'GM' => 'Gambia',
706
			'GE' => 'Georgia',
707
			'DE' => 'Germany',
708
			'GR' => 'Greece',
709
			'GH' => 'Ghana',
710
			'GI' => 'Gibraltar',
711
			'GL' => 'Greenland',
712
			'GD' => 'Grenada',
713
			'GP' => 'Guadeloupe',
714
			'GU' => 'Guam',
715
			'GT' => 'Guatemala',
716
			'GG' => 'Guernsey',
717
			'GN' => 'Guinea',
718
			'GW' => 'Guinea-Bissau',
719
			'GY' => 'Guyana',
720
			'HT' => 'Haiti',
721
			'HM' => 'Heard and McDonald Islands',
722
			'VA' => 'Holy See (City Vatican State)',
723
			'HN' => 'Honduras',
724
			'HK' => 'Hong Kong',
725
			'HU' => 'Hungary',
726
			'IS' => 'Iceland',
727
			'IN' => 'India',
728
			'ID' => 'Indonesia',
729
			'IR' => 'Iran',
730
			'IQ' => 'Iraq',
731
			'IE' => 'Ireland',
732
			'IM' => 'Isle of Man',
733
			'IL' => 'Israel',
734
			'IT' => 'Italy',
735
			'JM' => 'Jamaica',
736
			'JP' => 'Japan',
737
			'JE' => 'Jersey',
738
			'JO' => 'Jordan',
739
			'KZ' => 'Kazakhstan',
740
			'KE' => 'Kenya',
741
			'KI' => 'Kiribati',
742
			'KW' => 'Kuwait',
743
			'KG' => 'Kyrgyzstan',
744
			'LA' => 'Lao People\'s Democratic Republic',
745
			'LV' => 'Latvia',
746
			'LB' => 'Lebanon',
747
			'LS' => 'Lesotho',
748
			'LR' => 'Liberia',
749
			'LY' => 'Libyan Arab Jamahiriya',
750
			'LI' => 'Liechtenstein',
751
			'LT' => 'Lithuania',
752
			'LU' => 'Luxembourg',
753
			'MO' => 'Macau',
754
			'MK' => 'Macedonia',
755
			'MG' => 'Madagascar',
756
			'MW' => 'Malawi',
757
			'MY' => 'Malaysia',
758
			'MV' => 'Maldives',
759
			'ML' => 'Mali',
760
			'MT' => 'Malta',
761
			'MH' => 'Marshall Islands',
762
			'MQ' => 'Martinique',
763
			'MR' => 'Mauritania',
764
			'MU' => 'Mauritius',
765
			'YT' => 'Mayotte',
766
			'MX' => 'Mexico',
767
			'FM' => 'Micronesia',
768
			'MD' => 'Moldova, Republic of',
769
			'MC' => 'Monaco',
770
			'MN' => 'Mongolia',
771
			'ME' => 'Montenegro',
772
			'MS' => 'Montserrat',
773
			'MA' => 'Morocco',
774
			'MZ' => 'Mozambique',
775
			'MM' => 'Myanmar (Burma)',
776
			'NA' => 'Namibia',
777
			'NR' => 'Nauru',
778
			'NP' => 'Nepal',
779
			'NL' => 'Netherlands',
780
			'AN' => 'Netherlands Antilles',
781
			'NC' => 'New Caledonia',
782
			'NZ' => 'New Zealand',
783
			'NI' => 'Nicaragua',
784
			'NE' => 'Niger',
785
			'NG' => 'Nigeria',
786
			'NU' => 'Niue',
787
			'NF' => 'Norfolk Island',
788
			'KP' => 'North Korea',
789
			'MP' => 'Northern Mariana Islands',
790
			'NO' => 'Norway',
791
			'OM' => 'Oman',
792
			'PK' => 'Pakistan',
793
			'PW' => 'Palau',
794
			'PS' => 'Palestinian Territories',
795
			'PA' => 'Panama',
796
			'PG' => 'Papua New Guinea',
797
			'PY' => 'Paraguay',
798
			'PE' => 'Peru',
799
			'PH' => 'Philippines',
800
			'PN' => 'Pitcairn Island',
801
			'PL' => 'Poland',
802
			'PT' => 'Portugal',
803
			'PR' => 'Puerto Rico',
804
			'QA' => 'Qatar',
805
			'XK' => 'Republic of Kosovo',
806
			'RE' => 'Reunion Island',
807
			'RO' => 'Romania',
808
			'RU' => 'Russia',
809
			'RW' => 'Rwanda',
810
			'BL' => 'Saint Barth&eacute;lemy',
811
			'SH' => 'Saint Helena',
812
			'KN' => 'Saint Kitts and Nevis',
813
			'LC' => 'Saint Lucia',
814
			'MF' => 'Saint Martin (French)',
815
			'SX' => 'Saint Martin (Dutch)',
816
			'PM' => 'Saint Pierre and Miquelon',
817
			'VC' => 'Saint Vincent and the Grenadines',
818
			'SM' => 'San Marino',
819
			'ST' => 'S&atilde;o Tom&eacute; and Pr&iacute;ncipe',
820
			'SA' => 'Saudi Arabia',
821
			'SN' => 'Senegal',
822
			'RS' => 'Serbia',
823
			'SC' => 'Seychelles',
824
			'SL' => 'Sierra Leone',
825
			'SG' => 'Singapore',
826
			'SK' => 'Slovak Republic',
827
			'SI' => 'Slovenia',
828
			'SB' => 'Solomon Islands',
829
			'SO' => 'Somalia',
830
			'ZA' => 'South Africa',
831
			'GS' => 'South Georgia',
832
			'KR' => 'South Korea',
833
			'SS' => 'South Sudan',
834
			'ES' => 'Spain',
835
			'LK' => 'Sri Lanka',
836
			'SD' => 'Sudan',
837
			'SR' => 'Suriname',
838
			'SJ' => 'Svalbard and Jan Mayen Islands',
839
			'SZ' => 'Swaziland',
840
			'SE' => 'Sweden',
841
			'CH' => 'Switzerland',
842
			'SY' => 'Syrian Arab Republic',
843
			'TW' => 'Taiwan',
844
			'TJ' => 'Tajikistan',
845
			'TZ' => 'Tanzania',
846
			'TH' => 'Thailand',
847
			'TL' => 'Timor-Leste',
848
			'TG' => 'Togo',
849
			'TK' => 'Tokelau',
850
			'TO' => 'Tonga',
851
			'TT' => 'Trinidad and Tobago',
852
			'TN' => 'Tunisia',
853
			'TR' => 'Turkey',
854
			'TM' => 'Turkmenistan',
855
			'TC' => 'Turks and Caicos Islands',
856
			'TV' => 'Tuvalu',
857
			'UG' => 'Uganda',
858
			'UA' => 'Ukraine',
859
			'AE' => 'United Arab Emirates',
860
			'UY' => 'Uruguay',
861
			'UM' => 'US Minor Outlying Islands',
862
			'UZ' => 'Uzbekistan',
863
			'VU' => 'Vanuatu',
864
			'VE' => 'Venezuela',
865
			'VN' => 'Vietnam',
866
			'VG' => 'Virgin Islands (British)',
867
			'VI' => 'Virgin Islands (USA)',
868
			'WF' => 'Wallis and Futuna Islands',
869
			'EH' => 'Western Sahara',
870
			'WS' => 'Western Samoa',
871
			'YE' => 'Yemen',
872
			'ZM' => 'Zambia',
873
			'ZW' => 'Zimbabwe',
874
		);
875
	}
876
	return $countries;
877
}
878
879
function monsterinsights_get_api_url(){
880
	return apply_filters( 'monsterinsights_get_api_url', 'api.monsterinsights.com/v2/' );
881
}
882
883
function monsterinsights_get_licensing_url(){
884
	return apply_filters( 'monsterinsights_get_licensing_url', 'https://www.monsterinsights.com' );
885
}
886
887
function monsterinsights_is_wp_seo_active( ) {
888
	$wp_seo_active = false; // @todo: improve this check. This is from old Yoast code.
889
890
	// Makes sure is_plugin_active is available when called from front end
891
	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
892
	if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) || is_plugin_active( 'wordpress-seo-premium/wp-seo-premium.php' ) ) {
893
		$wp_seo_active = true;
894
	}
895
	return $wp_seo_active;
896
}
897
898
function monsterinsights_get_asset_version() {
899
	if ( monsterinsights_is_debug_mode() || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
900
		return time();
901
	} else {
902
		return MONSTERINSIGHTS_VERSION;
903
	}
904
}
905
906
function monsterinsights_is_debug_mode() {
907
	$debug_mode = false;
908
	if ( defined( 'MONSTERINSIGHTS_DEBUG_MODE' ) && MONSTERINSIGHTS_DEBUG_MODE ) {
0 ignored issues
show
Bug introduced by
The constant MONSTERINSIGHTS_DEBUG_MODE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
909
		$debug_mode = true;
910
	}
911
912
	return apply_filters( 'monsterinsights_is_debug_mode', $debug_mode );
913
}
914
915
function monsterinsights_is_network_active() {
916
	if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
917
		require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
918
	}
919
920
	if ( is_multisite() && is_plugin_active_for_network( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ) ) {
921
	   return true;
922
	} else {
923
		return false;
924
	}
925
}
926
927
if ( ! function_exists ( 'remove_class_filter' ) ) {
928
	/**
929
	 * Remove Class Filter Without Access to Class Object
930
	 *
931
	 * In order to use the core WordPress remove_filter() on a filter added with the callback
932
	 * to a class, you either have to have access to that class object, or it has to be a call
933
	 * to a static method.  This method allows you to remove filters with a callback to a class
934
	 * you don't have access to.
935
	 *
936
	 * Works with WordPress 1.2 - 4.7+
937
	 *
938
	 * @param string $tag         Filter to remove
939
	 * @param string $class_name  Class name for the filter's callback
940
	 * @param string $method_name Method name for the filter's callback
941
	 * @param int    $priority    Priority of the filter (default 10)
942
	 *
943
	 * @return bool Whether the function is removed.
944
	 */
945
	function remove_class_filter( $tag, $class_name = '', $method_name = '', $priority = 10 ) {
946
		global $wp_filter;
947
		// Check that filter actually exists first
948
		if ( ! isset( $wp_filter[ $tag ] ) ) return FALSE;
949
		/**
950
		 * If filter config is an object, means we're using WordPress 4.7+ and the config is no longer
951
		 * a simple array, rather it is an object that implements the ArrayAccess interface.
952
		 *
953
		 * To be backwards compatible, we set $callbacks equal to the correct array as a reference (so $wp_filter is updated)
954
		 *
955
		 * @see https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/
956
		 */
957
		if ( is_object( $wp_filter[ $tag ] ) && isset( $wp_filter[ $tag ]->callbacks ) ) {
958
			$callbacks = &$wp_filter[ $tag ]->callbacks;
959
		} else {
960
			$callbacks = &$wp_filter[ $tag ];
961
		}
962
		// Exit if there aren't any callbacks for specified priority
963
		if ( ! isset( $callbacks[ $priority ] ) || empty( $callbacks[ $priority ] ) ) return FALSE;
964
		// Loop through each filter for the specified priority, looking for our class & method
965
		foreach( (array) $callbacks[ $priority ] as $filter_id => $filter ) {
966
			// Filter should always be an array - array( $this, 'method' ), if not goto next
967
			if ( ! isset( $filter[ 'function' ] ) || ! is_array( $filter[ 'function' ] ) ) continue;
968
			// If first value in array is not an object, it can't be a class
969
			if ( ! is_object( $filter[ 'function' ][ 0 ] ) ) continue;
970
			// Method doesn't match the one we're looking for, goto next
971
			if ( $filter[ 'function' ][ 1 ] !== $method_name ) continue;
972
			// Method matched, now let's check the Class
973
			if ( get_class( $filter[ 'function' ][ 0 ] ) === $class_name ) {
974
				// Now let's remove it from the array
975
				unset( $callbacks[ $priority ][ $filter_id ] );
976
				// and if it was the only filter in that priority, unset that priority
977
				if ( empty( $callbacks[ $priority ] ) ) unset( $callbacks[ $priority ] );
978
				// and if the only filter for that tag, set the tag to an empty array
979
				if ( empty( $callbacks ) ) $callbacks = array();
980
				// If using WordPress older than 4.7
981
				if ( ! is_object( $wp_filter[ $tag ] ) ) {
982
					// Remove this filter from merged_filters, which specifies if filters have been sorted
983
					unset( $GLOBALS[ 'merged_filters' ][ $tag ] );
984
				}
985
				return TRUE;
986
			}
987
		}
988
		return FALSE;
989
	}
990
} // End function exists
991
992
if ( ! function_exists ( 'remove_class_action' ) ) {
993
	/**
994
	 * Remove Class Action Without Access to Class Object
995
	 *
996
	 * In order to use the core WordPress remove_action() on an action added with the callback
997
	 * to a class, you either have to have access to that class object, or it has to be a call
998
	 * to a static method.  This method allows you to remove actions with a callback to a class
999
	 * you don't have access to.
1000
	 *
1001
	 * Works with WordPress 1.2 - 4.7+
1002
	 *
1003
	 * @param string $tag         Action to remove
1004
	 * @param string $class_name  Class name for the action's callback
1005
	 * @param string $method_name Method name for the action's callback
1006
	 * @param int    $priority    Priority of the action (default 10)
1007
	 *
1008
	 * @return bool               Whether the function is removed.
1009
	 */
1010
	function remove_class_action( $tag, $class_name = '', $method_name = '', $priority = 10 ) {
1011
		remove_class_filter( $tag, $class_name, $method_name, $priority );
1012
	}
1013
} // End function exists
1014
1015
/**
1016
 * Format a big number, instead of 1000000 you get 1.0M, works with billions also.
1017
 *
1018
 * @param int $number
1019
 * @param int $precision
1020
 *
1021
 * @return string
1022
 */
1023
function monsterinsights_round_number( $number, $precision = 2 ) {
1024
1025
	if ( $number < 1000000 ) {
1026
		// Anything less than a million
1027
		$number = number_format_i18n( $number );
1028
	} else if ( $number < 1000000000 ) {
1029
		// Anything less than a billion
1030
		$number = number_format_i18n( $number / 1000000, $precision ) . 'M';
1031
	} else {
1032
		// At least a billion
1033
		$number = number_format_i18n( $number / 1000000000, $precision ) . 'B';
1034
	}
1035
1036
	return $number;
1037
}
1038
1039
if ( ! function_exists( 'wp_get_jed_locale_data' ) ) {
1040
	/**
1041
	 * Returns Jed-formatted localization data. Added for backwards-compatibility.
1042
	 *
1043
	 * @param  string $domain Translation domain.
1044
	 *
1045
	 * @return array
1046
	 */
1047
	function wp_get_jed_locale_data( $domain ) {
1048
		$translations = get_translations_for_domain( $domain );
1049
1050
		$locale = array(
1051
			'' => array(
1052
				'domain' => $domain,
1053
				'lang'   => is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(),
1054
			),
1055
		);
1056
1057
		if ( ! empty( $translations->headers['Plural-Forms'] ) ) {
1058
			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
1059
		}
1060
1061
		foreach ( $translations->entries as $msgid => $entry ) {
1062
			$locale[ $msgid ] = $entry->translations;
1063
		}
1064
1065
		return $locale;
1066
	}
1067
}
1068
1069
function monsterinsights_get_inline_menu_icon() {
1070
	$scheme          = get_user_option( 'admin_color', get_current_user_id() );
1071
	$use_dark_scheme = $scheme === 'light';
1072
	if ( $use_dark_scheme ) {
1073
		return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAFQUlEQVRYha2Yb2hXZRTHP+c3nc6pm07NF0KWWUtSo0wqzBdiZRItTKMaEZXSi0zRNAsqTBKKSFOa0B8Jigqz2lSwLMtqRURgRuCCLLNmselyZups2+/04pzbnt3de3eTDlzufc5znvN8n+ec55zzXFFV8pKITANOqmpTP3JTgIKq7sutPCJVzfUABeAb4DSwMENuKdABNObV3Wv8fwB0C6DAUX8/67sQ9Q8ANsVk5v5vgIDKWHsvcAgYCWzzCbc6kFJgh/PqgVHAb8DnWTpzA3LzHARmeXuqT/Zo0L/eeZuAV/x7fbRrwJPOu9Dbc4EDgJwNoMmurAt4Bljt7cmBjACvOl+BzTEdVzj/EWAj0O3tC84G0AIf3BRMeDz0GZcbBvzqKy+L9Q30A6AxXTdmARqQcPAAyv29CBjjO1RU1SKAiIwGFgLX+MrbgBnAh5ECVe0UkUMO6nHgFLA70J1McacD5gHbfTXzg77qwBeOBysPn830PnnVwXety7wL1AAV/ZoM+MIHdQCfAdfF+s8H/koBEz0rU9xgLtAInHG5j/KYrNWf8ap6OmFD7w+2/Cugwd/NmOkqgbIUS+wEdorIEOAwFqv6UBKgihQwANNc0b2quh1ARIZi/nUqZUycOrDDcCSps5AAaJBPkkStwNVAs4i8JiLHgBPASRFpFZEGEZktIpIBqBIoIWWH4nZegtl3fIofjAKeoyemfAe8hZnu64D/NjAsRcdEl1mcx6lvc+HLU6L3O97/JXBlgszF9KSVvXhswkxUC6wLdKzIA2iWC1+fMNlK72sASlMjrQHf4LIvAw8B7fScwmNAZ7DDs7MARSmjNsYf7oqak0wBjAXuBlb5Lo9wE0Yg6rHAOdjlR2KB9Qc384o0QOe4giUx/u3OX5oA5gEsCoexqBnYAxTTfMXHlvuOF4F5SYBKHPGaGH+jTzQxxefSnnVpYAIdg9x0PwEDkwSOAHUx3hafoDzGP5AB5gQ56h/XU+NjauJxCCxRjo7xOvw9ImKISBUwIWF8RLtVtT2jP6SdWBKe1QuQiCwDLsKcNKSoqJ8e8BJTREAHc4JBVTuBn4Gx/wISkflYndyNOXdI2/29OOAd7mfSIXkBOZUDxTACt2A78SLQnmDnBszOiwLeraT70Ld5/Mf1jPMxqyLGWqxcnYoFMqVvBTgOK9y7gOVAifMfdF4SqJk5Aa3FLFMNduxagQbvvJOUfIb51/f0lKSrsROyHCtlIyDtrrMJqOoHzAysRvrA28wmSBfAtd7uk6u8vwwr/JOqxm4sl01wvZ3AfhJyo+taAPyJhYi/gekCPIXdNitV9YyIXIIFqptVdVsf13MSkVJgJlZF4rvSqKq/BzJzgNexcPEp8LFPXAHcAFzqoKcAddjR5z2Cay/m4Arcl9cp+zFJFfA0dslMOwB1wD1AewGrTw4Ei2/zVcSP/lmRqrap6irs8gAwid7xDOAuzNwlgmXxF1T14ahXRPZjtU1k3+g5Tk8pkUUFzCwVWC003N/DgGVYIXheIF/EfmQcFczDW4DnsVtBCxbUtmIOPAAzY6MPLgMG+/dlDrIADHWlYL4QpZuZWLjYgp3SOb7QMbFFFLF6LDNB7sGcri7FP7qwWmcX9t8oSWaDA6zCqomXUuZ6U1UpYDXxH5jfgKWET/y7zXfolIgkJeJMEpES/xwMXKWq3aq6CLu9PAH8Eog/Fn2UYnlkDWa2c719E3Y/f8NX0AL8GHuianAXtuXx/lZ6brR9/npgcWgHcEfEkyg6ZqyyBrt1ptE+X9SkDJl6VX0/cyKnfwBb6gwNaZ8ExgAAAABJRU5ErkJggg';
1074
	} else {
1075
		return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4AoEBjcfBsDvpwAABQBJREFUWMO1mGmollUQgJ9z79Vc01LLH0GLWRqlUhYV5o+LbRIVbVQSUSn9qJTKsqDCoqCINKUbtBEUFbbeDGyz1SIiaCHIINu18KZ1bbkuV+/Tj+arw8v7fvdVcuDjvGdmzsycM3Nm5nywE6BOVSfW4JukTmF3gtqifqJuVmc34ZunblFX7W6DzvYf2BDjPWpLRm9T7y/wzPw/DRhZmH+sfq/urb4YCp8JQwaqLwXuBXW0+pP6XjOZO+ueb9X2mE8OZTdl9MWBu199NL4XN05NvT1wh8R8prpGTbti0BEhbLt6t7ow5kdkPEl9zP/gkYKMowN/o7pU3RHzg3fFoHNj8epM4aY8ZoJvuPpj7HxwgTYgLoAFWac1091WgR8a4xxgH2Ah0JdS6gtlY4DZwAnADmAjMA14vSEgpdSrfg9sBm4BeoCVmex6gayepS6P3ZyT0SZksbDJcnikcPMmZN+zgud59Qx1RB2D3o9FW9R31ZMK9IPUP20O11XInqmuUrcG3xt1XNYVvwNSSptL+K/IjvxDoDPGteG6kcDgMkUppRXACnUIsA7YUNegERXGAEwNQZellJbHzodFfPXUjIwtwHDglzJiS4lBe4SSMugCjgfWqo+rvwF/AH+pXWqnOqOfXDMSaK06oaKf54Z/D6igj1bvzXLK5+rTYchHGf5ZdXiFjPHBc2Udg84P5qMqsvdzQf9APbaEZ2JWVj5u5KbIV7PURZmM+XUMag/mk0to1wWtUx3YT9lZErwPq9er3dkt/E3tzU54Rp2SMauA3zMErS1zhTpWvURdEKe8V7jQrOBOUwcF/97qbPWrcPP8KoP2DQFzC/gLAj+vZM1Vak8hF61V31L7msWKOjROvE89q4yhNSy+rYBfGorGV8RcFSyqESZ7hOu+UQeUMfyidhRwy0LB0AJ+TRNj/qjb/0QpUT2jpYS+ERhTkswA9sqEjALGNdGzMqXUXTNZrogi3F5sJ64GDgXGFhasjvGYDDe4HyXf1i3qKaVe4DtgbF6ZzwHuiZq0b2HN8hjzAF3Xj9IhO9mGDQX68gy8PpqoB9XuEj93hp/nZLjzmsTQZzvR9uwXaxY0EHdEuzo5EpklHeB+0bhvV69RWwN/beDKYHpNg+6I2z2hce261M4gXlRVz9RD1S+zlnRh3JBropVtQHfIXB3B38yYadEjvdZAzMjLhXpizI+tEDA4Gv+yrnFH1LJxIbdX/aKsNma9+++RIrapxyT1TmAeMDKltFU9HPgcODOl9GKTnQ0EpgMHBaobWJVS+jnjOQV4ItLFO8CbwDZgBHAqMAXoBSYBHcBm1JfzZ28EuOrl/9ODc5R6Vzwyq6BDvVTtbgHGA2sKiXFbydXfJUgpbUwpLQAateqwQj4DuDjSTWuKru+BlNIN2a6+ACYCv0dH2PhtCtfYjx0t4ZYR0a7uGeNw4GpgLnBgxt8HfAJsSOpWYD1wH7AqvocAz0Q2bgNGB62RoQfF95FhZAswLIQSZaBRbqYDPwHLogqcEhvdp7CJPqC9vwL5VtyUjor42B69zqvqXxU8S+IFOyq6iYcqdD3VONqngV8jbhol4e0sntqAnuIzumZAt8bnIOC4lNKOlNKceL3cCvyQsd/87/WNRuk29T51/5ifHu/zJ2MH69WvCz+zE+oroXdlL9pUkYdeUi/89xLU6VWAZn88fQoMjNtTBS+klF6pc6p/A2ye4OCYzm1lAAAAAElFTkSuQmCC';
1076
	}
1077
}
1078
1079
1080
function monsterinsights_get_shareasale_id() {
1081
	// Check if there's a constant.
1082
	$shareasale_id = '';
1083
	if ( defined( 'MONSTERINSIGHTS_SHAREASALE_ID' ) ) {
1084
		$shareasale_id = MONSTERINSIGHTS_SHAREASALE_ID;
0 ignored issues
show
Bug introduced by
The constant MONSTERINSIGHTS_SHAREASALE_ID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1085
	}
1086
1087
	// If there's no constant, check if there's an option.
1088
	if ( empty( $shareasale_id ) ) {
1089
		$shareasale_id = get_option( 'monsterinsights_shareasale_id', '' );
1090
	}
1091
1092
	// Whether we have an ID or not, filter the ID.
1093
	$shareasale_id = apply_filters( 'monsterinsights_shareasale_id', $shareasale_id );
1094
1095
	// Ensure it's a number
1096
	$shareasale_id = absint( $shareasale_id );
1097
1098
	return $shareasale_id;
1099
}
1100
1101
// Passed in with mandatory default redirect and shareasaleid from monsterinsights_get_upgrade_link
1102
function monsterinsights_get_shareasale_url( $shareasale_id, $shareasale_redirect ) {
1103
	// Check if there's a constant.
1104
	$custom = false;
1105
	if ( defined( 'MONSTERINSIGHTS_SHAREASALE_REDIRECT_URL' ) ) {
1106
		$shareasale_redirect = MONSTERINSIGHTS_SHAREASALE_REDIRECT_URL;
0 ignored issues
show
Bug introduced by
The constant MONSTERINSIGHTS_SHAREASALE_REDIRECT_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1107
		$custom              = true;
1108
	}
1109
1110
	// If there's no constant, check if there's an option.
1111
	if ( empty( $custom ) ) {
1112
		$shareasale_redirect = get_option( 'monsterinsights_shareasale_redirect_url', '' );
1113
		$custom              = true;
1114
	}
1115
1116
	// Whether we have an ID or not, filter the ID.
1117
	$shareasale_redirect = apply_filters( 'monsterinsights_shareasale_redirect_url', $shareasale_redirect, $custom );
1118
	$shareasale_url      = sprintf( 'https://www.shareasale.com/r.cfm?B=971799&U=%s&M=69975&urllink=%s', $shareasale_id, $shareasale_redirect );
1119
1120
	return $shareasale_url;
1121
}
1122
1123
/**
1124
 * Get a clean page title for archives.
1125
 */
1126
function monsterinsights_get_page_title() {
1127
1128
	$title = __( 'Archives' );
1129
1130
	if ( is_category() ) {
1131
		/* translators: Category archive title. %s: Category name */
1132
		$title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
1133
	} elseif ( is_tag() ) {
1134
		/* translators: Tag archive title. %s: Tag name */
1135
		$title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
1136
	} elseif ( is_author() ) {
1137
		/* translators: Author archive title. %s: Author name */
1138
		$title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
1139
	} elseif ( is_year() ) {
1140
		/* translators: Yearly archive title. %s: Year */
1141
		$title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
0 ignored issues
show
Bug introduced by
It seems like get_the_date(_x('Y', 'ye...archives date format')) can also be of type false; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1141
		$title = sprintf( __( 'Year: %s' ), /** @scrutinizer ignore-type */ get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
Loading history...
1142
	} elseif ( is_month() ) {
1143
		/* translators: Monthly archive title. %s: Month name and year */
1144
		$title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
1145
	} elseif ( is_day() ) {
1146
		/* translators: Daily archive title. %s: Date */
1147
		$title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
1148
	} elseif ( is_tax( 'post_format' ) ) {
1149
		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
1150
			$title = _x( 'Asides', 'post format archive title' );
1151
		} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
1152
			$title = _x( 'Galleries', 'post format archive title' );
1153
		} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
1154
			$title = _x( 'Images', 'post format archive title' );
1155
		} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
1156
			$title = _x( 'Videos', 'post format archive title' );
1157
		} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
1158
			$title = _x( 'Quotes', 'post format archive title' );
1159
		} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
1160
			$title = _x( 'Links', 'post format archive title' );
1161
		} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
1162
			$title = _x( 'Statuses', 'post format archive title' );
1163
		} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
1164
			$title = _x( 'Audio', 'post format archive title' );
1165
		} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
1166
			$title = _x( 'Chats', 'post format archive title' );
1167
		}
1168
	} elseif ( is_post_type_archive() ) {
1169
		/* translators: Post type archive title. %s: Post type name */
1170
		$title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
1171
	} elseif ( is_tax() ) {
1172
		$tax = get_taxonomy( get_queried_object()->taxonomy );
1173
		/* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
1174
		$title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
1175
	}
1176
1177
	return $title;
1178
1179
}
1180
1181
/**
1182
 * Make a request to the front page and check if the tracking code is present. Moved here from onboarding wizard
1183
 * to be used in the site health check.
1184
 *
1185
 * @return array
1186
 */
1187
function monsterinsights_is_code_installed_frontend() {
1188
		// Grab the front page html.
1189
	$request = wp_remote_request( home_url(), array(
1190
		'sslverify' => false,
1191
	) );
1192
	$errors  = array();
1193
1194
	if ( 200 === wp_remote_retrieve_response_code( $request ) ) {
0 ignored issues
show
Bug introduced by
It seems like $request can also be of type WP_Error; however, parameter $response of wp_remote_retrieve_response_code() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1194
	if ( 200 === wp_remote_retrieve_response_code( /** @scrutinizer ignore-type */ $request ) ) {
Loading history...
1195
1196
		$body            = wp_remote_retrieve_body( $request );
0 ignored issues
show
Bug introduced by
It seems like $request can also be of type WP_Error; however, parameter $response of wp_remote_retrieve_body() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1196
		$body            = wp_remote_retrieve_body( /** @scrutinizer ignore-type */ $request );
Loading history...
1197
		$current_ua_code = monsterinsights_get_ua_to_output();
1198
		$ua_limit        = 2;
1199
		// If the ads addon is installed another UA is added to the page.
1200
		if ( class_exists( 'MonsterInsights_Ads' ) ) {
1201
			$ua_limit = 3;
1202
		}
1203
		// Translators: The placeholders are for making the "We noticed you're using a caching plugin" text bold.
1204
		$cache_error = sprintf( esc_html__( '%1$sWe noticed you\'re using a caching plugin or caching from your hosting provider.%2$s Be sure to clear the cache to ensure the tracking appears on all pages and posts. %3$s(See this guide on how to clear cache)%4$s.', 'google-analytics-for-wordpress' ), '<b>', '</b>', ' <a href="https://www.wpbeginner.com/beginners-guide/how-to-clear-your-cache-in-wordpress/" target="_blank">', '</a>' );
1205
		// Translators: The placeholders are for making the "We have detected multiple tracking codes" text bold & adding a link to support.
1206
		$multiple_ua_error = sprintf( esc_html__( '%1$sWe have detected multiple tracking codes%2$s! You should remove non-MonsterInsights ones. If you need help finding them please %3$sread this article%4$s.', 'google-analytics-for-wordpress' ), '<b>', '</b>', '<a href="https://www.monsterinsights.com/docs/how-to-find-duplicate-google-analytics-tracking-codes-in-wordpress/" target="_blank">', '</a>' );
1207
1208
		// First, check if the tracking frontend code is present.
1209
		if ( false === strpos( $body, '__gaTracker' ) ) {
1210
			$errors[] = $cache_error;
1211
		} else {
1212
			// Check if the current UA code is actually present.
1213
			if ( $current_ua_code && false === strpos( $body, $current_ua_code ) ) {
1214
				// We have the tracking code but using another UA, so it's cached.
1215
				$errors[] = $cache_error;
1216
			}
1217
			// Grab all the UA codes from the page.
1218
			$pattern = '/UA-[0-9]+/m';
1219
			preg_match_all( $pattern, $body, $matches );
1220
			// If more than twice ( because MI has a ga-disable-UA also ), let them know to remove the others.
1221
			if ( ! empty( $matches[0] ) && is_array( $matches[0] ) && count( $matches[0] ) > $ua_limit ) {
1222
				$errors[] = $multiple_ua_error;
1223
			}
1224
		}
1225
	}
1226
1227
	return $errors;
1228
}
1229
1230
/**
1231
 * Returns a HEX color to highlight menu items based on the admin color scheme.
1232
 */
1233
function monsterinsights_menu_highlight_color() {
1234
1235
	$color_scheme = get_user_option( 'admin_color' );
1236
	$color        = '#7cc048';
1237
	if ( 'light' === $color_scheme || 'blue' === $color_scheme ) {
1238
		$color = '#5f3ea7';
1239
	}
1240
1241
	return $color;
1242
}
1243