Passed
Push — master ( 2bd1cf...bfbffa )
by
unknown
05:03
created

monsterinsights_date_is_between()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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

1152
		$title = sprintf( __( 'Year: %s' ), /** @scrutinizer ignore-type */ get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
Loading history...
1153
	} elseif ( is_month() ) {
1154
		/* translators: Monthly archive title. %s: Month name and year */
1155
		$title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
1156
	} elseif ( is_day() ) {
1157
		/* translators: Daily archive title. %s: Date */
1158
		$title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
1159
	} elseif ( is_tax( 'post_format' ) ) {
1160
		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
1161
			$title = _x( 'Asides', 'post format archive title' );
1162
		} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
1163
			$title = _x( 'Galleries', 'post format archive title' );
1164
		} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
1165
			$title = _x( 'Images', 'post format archive title' );
1166
		} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
1167
			$title = _x( 'Videos', 'post format archive title' );
1168
		} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
1169
			$title = _x( 'Quotes', 'post format archive title' );
1170
		} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
1171
			$title = _x( 'Links', 'post format archive title' );
1172
		} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
1173
			$title = _x( 'Statuses', 'post format archive title' );
1174
		} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
1175
			$title = _x( 'Audio', 'post format archive title' );
1176
		} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
1177
			$title = _x( 'Chats', 'post format archive title' );
1178
		}
1179
	} elseif ( is_post_type_archive() ) {
1180
		/* translators: Post type archive title. %s: Post type name */
1181
		$title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
1182
	} elseif ( is_tax() ) {
1183
		$tax = get_taxonomy( get_queried_object()->taxonomy );
0 ignored issues
show
Bug introduced by
The property taxonomy does not exist on WP_Post_Type. Did you mean taxonomies?
Loading history...
1184
		/* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
1185
		$title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
1186
	}
1187
1188
	return $title;
1189
1190
}
1191
1192
/**
1193
 * Count the number of occurrences of UA tags inserted by third-party plugins.
1194
 *
1195
 * @param $body
1196
 *
1197
 * @return int
1198
 */
1199
function monsterinsights_count_third_party_ua_codes( $body ) {
1200
	$count = 0;
1201
1202
	// Grab all potential google site verification tags
1203
	$pattern = '/content="UA-[0-9-]+"/';
1204
	if ( preg_match_all( $pattern, $body, $matches ) ) {
1205
		// Raise the number of UA limits
1206
		$count += count( $matches[0] );
1207
	}
1208
1209
	// Advanced Ads plugin (https://wpadvancedads.com)
1210
	// When `Ad blocker counter` setting is populated with an UA ID
1211
	if ( class_exists( 'Advanced_Ads' ) ) {
1212
		$options = Advanced_Ads::get_instance()->options();
0 ignored issues
show
Bug introduced by
The type Advanced_Ads 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...
1213
1214
		$pattern = '/UA-[0-9-]+/';
1215
		if ( isset( $options['ga-UID'] ) && preg_match( $pattern, $options['ga-UID'] ) ) {
1216
			++ $count;
1217
		}
1218
	}
1219
1220
	// WP Popups plugin (https://wppopups.com/)
1221
	// When `Google UA Code` setting is populated with an UA Id
1222
	if ( function_exists( 'wppopups_setting' ) ) {
1223
		$code = wppopups_setting( 'ua-code' );
1224
1225
		$pattern = '/UA-[0-9-]+/';
1226
		if ( ! empty( $code ) && preg_match( $pattern, $code ) ) {
1227
			++ $count;
1228
		}
1229
	}
1230
1231
	return $count;
1232
}
1233
1234
/**
1235
 * Make a request to the front page and check if the tracking code is present. Moved here from onboarding wizard
1236
 * to be used in the site health check.
1237
 *
1238
 * @return array
1239
 */
1240
function monsterinsights_is_code_installed_frontend() {
1241
	// Grab the front page html.
1242
	$request = wp_remote_request( home_url(), array(
1243
		'sslverify' => false,
1244
	) );
1245
	$errors  = array();
1246
1247
	$accepted_http_codes = array(
1248
		200,
1249
		503
1250
	);
1251
1252
	$response_code = wp_remote_retrieve_response_code( $request );
1253
1254
	if ( in_array( $response_code, $accepted_http_codes, true ) ) {
1255
1256
		$body            = wp_remote_retrieve_body( $request );
1257
		$current_ua_code = monsterinsights_get_ua_to_output();
1258
		$ua_limit        = 2;
1259
		// If the ads addon is installed another UA is added to the page.
1260
		if ( class_exists( 'MonsterInsights_Ads' ) ) {
1261
			$ua_limit = 3;
1262
		}
1263
		// Translators: The placeholders are for making the "We noticed you're using a caching plugin" text bold.
1264
		$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>' );
1265
1266
		// Translators: The placeholders are for making the "We have detected multiple tracking codes" text bold & adding a link to support.
1267
		$message           = 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' );
1268
		$url               = monsterinsights_get_url( 'site-health', 'comingsoon', 'https://www.monsterinsights.com/docs/how-to-find-duplicate-google-analytics-tracking-codes-in-wordpress/' );
1269
		$multiple_ua_error = sprintf(
1270
			$message,
1271
			'<b>',
1272
			'</b>',
1273
			'<a href="' . $url . '" target="_blank">',
1274
			'</a>'
1275
		);
1276
1277
		// First, check if the tracking frontend code is present.
1278
		if ( false === strpos( $body, '__gaTracker' ) ) {
1279
			$errors[] = $cache_error;
1280
		} else {
1281
			// Check if the current UA code is actually present.
1282
			if ( $current_ua_code && false === strpos( $body, $current_ua_code ) ) {
1283
				// We have the tracking code but using another UA, so it's cached.
1284
				$errors[] = $cache_error;
1285
			}
1286
1287
			$ua_limit += monsterinsights_count_third_party_ua_codes( $body );
1288
1289
			// Grab all the UA codes from the page.
1290
			$pattern = '/UA-[0-9]+/m';
1291
			preg_match_all( $pattern, $body, $matches );
1292
			// If more than twice ( because MI has a ga-disable-UA also ), let them know to remove the others.
1293
			if ( ! empty( $matches[0] ) && is_array( $matches[0] ) && count( $matches[0] ) > $ua_limit ) {
1294
				$errors[] = $multiple_ua_error;
1295
			}
1296
		}
1297
	}
1298
1299
	return $errors;
1300
}
1301
1302
/**
1303
 * Returns a HEX color to highlight menu items based on the admin color scheme.
1304
 */
1305
function monsterinsights_menu_highlight_color() {
1306
1307
	$color_scheme = get_user_option( 'admin_color' );
1308
	$color        = '#7cc048';
1309
	if ( 'light' === $color_scheme || 'blue' === $color_scheme ) {
1310
		$color = '#5f3ea7';
1311
	}
1312
1313
	return $color;
1314
}
1315
1316
/**
1317
 * Track Pretty Links redirects with MonsterInsights.
1318
 *
1319
 * @param string $url The url to which users get redirected.
1320
 */
1321
function monsterinsights_custom_track_pretty_links_redirect( $url ) {
1322
	if ( ! function_exists( 'monsterinsights_mp_track_event_call' ) ) {
1323
		return;
1324
	}
1325
	// Try to determine if click originated on the same site.
1326
	$referer = ! empty( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '';
1327
	if ( ! empty( $referer ) ) {
1328
		$current_site_url    = get_bloginfo( 'url' );
1329
		$current_site_parsed = wp_parse_url( $current_site_url );
1330
		$parsed_referer      = wp_parse_url( $referer );
1331
		if ( ! empty( $parsed_referer['host'] ) && ! empty( $current_site_parsed['host'] ) && $current_site_parsed['host'] === $parsed_referer['host'] ) {
1332
			// Don't track clicks originating from same site as those are tracked with JS.
1333
			return;
1334
		}
1335
	}
1336
	// Check if this is an affiliate link and use the appropriate category.
1337
	$ec            = 'outbound-link';
1338
	$inbound_paths = monsterinsights_get_option( 'affiliate_links', array() );
1339
	$path          = empty( $_SERVER['REQUEST_URI'] ) ? '' : $_SERVER['REQUEST_URI'];
1340
	if ( ! empty( $inbound_paths ) && is_array( $inbound_paths ) && ! empty( $path ) ) {
0 ignored issues
show
introduced by
The condition is_array($inbound_paths) is always false.
Loading history...
1341
		$found = false;
1342
		foreach ( $inbound_paths as $inbound_path ) {
1343
			if ( empty( $inbound_path['path'] ) ) {
1344
				continue;
1345
			}
1346
			if ( 0 === strpos( $path, trim( $inbound_path['path'] ) ) ) {
1347
				$label = ! empty( $inbound_path['label'] ) ? trim( $inbound_path['label'] ) : 'aff';
1348
				$ec   .= '-' . $label;
1349
				$found = true;
1350
				break;
1351
			}
1352
		}
1353
		if ( ! $found ) {
1354
			return;
1355
		}
1356
	} else {
1357
		// no paths setup in MonsterInsights settings
1358
		return;
1359
	}
1360
1361
	$track_args = array(
1362
		't'  => 'event',
1363
		'ec' => $ec,
1364
		'ea' => $url,
1365
		'el' => 'external-redirect',
1366
	);
1367
	monsterinsights_mp_track_event_call( $track_args );
1368
}
1369
add_action( 'prli_before_redirect', 'monsterinsights_custom_track_pretty_links_redirect' );
1370
1371
/**
1372
 * Get post type in admin side
1373
 *
1374
 */
1375
function monsterinsights_get_current_post_type() {
1376
	global $post, $typenow, $current_screen;
1377
1378
	if ( $post && $post->post_type ) {
1379
		return $post->post_type;
1380
	} elseif ( $typenow ) {
1381
		return $typenow;
1382
	} elseif ( $current_screen && $current_screen->post_type ) {
1383
		return $current_screen->post_type;
1384
	} elseif ( isset( $_REQUEST['post_type'] ) ) {
1385
		return sanitize_key( $_REQUEST['post_type'] );
1386
	}
1387
1388
	return null;
1389
}
1390
1391
/** Decode special characters, both alpha- (<) and numeric-based (').
1392
 *
1393
 * @since 7.10.5
1394
 *
1395
 * @param string $string Raw string to decode.
1396
 *
1397
 * @return string
1398
 */
1399
function monsterinsights_decode_string( $string ) {
1400
1401
	if ( ! is_string( $string ) ) {
0 ignored issues
show
introduced by
The condition is_string($string) is always true.
Loading history...
1402
		return $string;
1403
	}
1404
1405
	return wp_kses_decode_entities( html_entity_decode( $string, ENT_QUOTES ) );
1406
}
1407
1408
add_filter( 'monsterinsights_email_message', 'monsterinsights_decode_string' );
1409
1410
/**
1411
 * Sanitize a string, that can be a multiline.
1412
 * If WP core `sanitize_textarea_field()` exists (after 4.7.0) - use it.
1413
 * Otherwise - split onto separate lines, sanitize each one, merge again.
1414
 *
1415
 * @since 7.10.5
1416
 *
1417
 * @param string $string
1418
 *
1419
 * @return string If empty var is passed, or not a string - return unmodified. Otherwise - sanitize.
1420
 */
1421
function monsterinsights_sanitize_textarea_field( $string ) {
1422
1423
	if ( empty( $string ) || ! is_string( $string ) ) {
1424
		return $string;
1425
	}
1426
1427
	if ( function_exists( 'sanitize_textarea_field' ) ) {
1428
		$string = sanitize_textarea_field( $string );
1429
	} else {
1430
		$string = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $string ) ) );
1431
	}
1432
1433
	return $string;
1434
}
1435
1436
/**
1437
 * Trim a sentence
1438
 *
1439
 * @since 7.10.5
1440
 *
1441
 * @param string $string
1442
 * @param int $count
1443
 *
1444
 * @return trimed sentence
0 ignored issues
show
Bug introduced by
The type trimed 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...
1445
 */
1446
function monsterinsights_trim_text( $text, $count ){
1447
	$text 	= str_replace("  ", " ", $text);
1448
	$string = explode(" ", $text);
1449
	$trimed = "";
1450
1451
	for ( $wordCounter = 0; $wordCounter <= $count; $wordCounter++ ) {
1452
		$trimed .= isset( $string[$wordCounter] ) ? $string[$wordCounter] : '';
1453
1454
		if ( $wordCounter < $count ){
1455
			$trimed .= " ";
1456
		} else {
1457
			$trimed .= "...";
1458
		}
1459
	}
1460
1461
	$trimed = trim($trimed);
1462
1463
	return $trimed;
1464
}
1465
1466
/**
1467
 * Add newly generated builder URL to PrettyLinks &
1468
 * Clear localStorage key(MonsterInsightsURL) after saving PrettyLink
1469
 */
1470
function monsterinsights_tools_copy_url_to_prettylinks() {
1471
	global $pagenow;
1472
1473
	$post_type                 = isset( $_GET['post_type'] ) ? $_GET['post_type'] : '';
1474
	$monsterinsights_reference = isset( $_GET['monsterinsights_reference'] ) ? $_GET['monsterinsights_reference'] : '';
1475
1476
	if ( 'post-new.php' === $pagenow && 'pretty-link' === $post_type && 'url_builder' === $monsterinsights_reference ) { ?>
1477
        <script>
1478
            let targetTitleField = document.querySelector("input[name='post_title']");
1479
            let targetUrlField = document.querySelector("textarea[name='prli_url']");
1480
            let MonsterInsightsUrl = JSON.parse(localStorage.getItem('MonsterInsightsURL'));
1481
            if ( 'undefined' !== typeof targetUrlField && 'undefined' !== typeof MonsterInsightsUrl ) {
1482
                let url = MonsterInsightsUrl.value;
1483
                let postTitle = '';
1484
                let pathArray = url.split('?');
1485
                if ( pathArray.length <= 1 ) {
1486
                    pathArray = url.split('#');
1487
                }
1488
                let urlParams = new URLSearchParams(pathArray[1]);
1489
                if (urlParams.has('utm_campaign')) {
1490
                    let campaign_name = urlParams.get('utm_campaign');
1491
                    postTitle += campaign_name;
1492
                }
1493
                if (urlParams.has('utm_medium')) {
1494
                    let campaign_medium = urlParams.get('utm_medium');
1495
                    postTitle += ` ${campaign_medium}`;
1496
                }
1497
                if (urlParams.has('utm_source')) {
1498
                    let campaign_source = urlParams.get('utm_source');
1499
                    postTitle += ` on ${campaign_source}`;
1500
                }
1501
                if (urlParams.has('utm_term')) {
1502
                    let campaign_term = urlParams.get('utm_term');
1503
                    postTitle += ` for ${campaign_term}`;
1504
                }
1505
                if (urlParams.has('utm_content')) {
1506
                    let campaign_content = urlParams.get('utm_content');
1507
                    postTitle += ` - ${campaign_content}`;
1508
                }
1509
                if ( 'undefined' !== typeof targetTitleField && postTitle ) {
1510
                    targetTitleField.value = postTitle;
1511
                }
1512
                if( url ) {
1513
                    targetUrlField.value = url;
1514
                }
1515
            }
1516
            let form = document.getElementById('post');
1517
            form.addEventListener('submit', function(){
1518
                localStorage.removeItem('MonsterInsightsURL');
1519
            });
1520
        </script>
1521
	<?php }
1522
}
1523
add_action( 'admin_footer', 'monsterinsights_tools_copy_url_to_prettylinks' );
1524
1525
/**
1526
 * When click on 'Create New Pretty Link" button(on tools/prettylinks-flow page) after installing & activating prettylinks plugin
1527
 * it redirects to PrettyLinks welcome scree page instead of prettylinks add new page.
1528
 * This function will skip that welcome screen
1529
 */
1530
function monsterinsights_skip_prettylinks_welcome_screen() {
1531
	global $pagenow;
1532
1533
	$post_type                 = isset( $_GET['post_type'] ) ? $_GET['post_type'] : '';
1534
	$monsterinsights_reference = isset( $_GET['monsterinsights_reference'] ) ? $_GET['monsterinsights_reference'] : '';
1535
1536
	if ( 'post-new.php' === $pagenow && 'pretty-link' === $post_type && 'url_builder' === $monsterinsights_reference ) {
1537
		$onboard  = get_option( 'prli_onboard' );
1538
1539
		if ( $onboard == 'welcome' || $onboard == 'update' ) {
1540
			update_option( 'monsterinsights_backup_prli_onboard_value', $onboard );
1541
			delete_option( 'prli_onboard' );
1542
		}
1543
	}
1544
}
1545
add_action( 'wp_loaded', 'monsterinsights_skip_prettylinks_welcome_screen', 9 );
1546
1547
/**
1548
 * Restore the `prli_onboard` value after creating a prettylinks with monsterinsights prettylinks flow
1549
 * users will see the prettylinks welcome screen after fresh installation & creating prettylinks with monsterinsights prettylinks flow
1550
 */
1551
function monsterinsights_restore_prettylinks_onboard_value() {
1552
	global $pagenow;
1553
1554
	$post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : '';
1555
1556
	if ( 'edit.php' === $pagenow && 'pretty-link' === $post_type ) {
1557
		$onboard   = get_option( 'monsterinsights_backup_prli_onboard_value' );
1558
1559
		if ( class_exists( 'PrliBaseController' ) && ( $onboard == 'welcome' || $onboard == 'update' ) ) {
1560
			update_option( 'prli_onboard', $onboard );
1561
			delete_option( 'monsterinsights_backup_prli_onboard_value' );
1562
		}
1563
	}
1564
}
1565
add_action( 'wp_loaded', 'monsterinsights_restore_prettylinks_onboard_value', 15 );
1566
1567
/**
1568
 * Check WP version and include the compatible upgrader skin.
1569
 *
1570
 * @param bool $custom_upgrader If true it will include our custom upgrader, otherwise it will use the default WP one.
1571
 */
1572
function monsterinsights_require_upgrader( $custom_upgrader = true ) {
1573
1574
	global $wp_version;
1575
1576
	$base = MonsterInsights();
1577
1578
	if ( ! $custom_upgrader ) {
1579
		require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1580
	}
1581
1582
	// WP 5.3 changes the upgrader skin.
1583
	if ( version_compare( $wp_version, '5.3', '<' ) ) {
1584
		if ( $custom_upgrader ) {
1585
			require_once plugin_dir_path( $base->file ) . 'includes/admin/licensing/plugin-upgrader.php';
1586
		}
1587
		require_once plugin_dir_path( $base->file ) . '/includes/admin/licensing/skin-legacy.php';
1588
	} else {
1589
		if ( $custom_upgrader ) {
1590
			require_once plugin_dir_path( $base->file ) . 'includes/admin/licensing/plugin-upgrader.php';
1591
		}
1592
		require_once plugin_dir_path( $base->file ) . '/includes/admin/licensing/skin.php';
1593
	}
1594
1595
}
1596
1597
/**
1598
 * Load headline analyzer if wp version is higher than/equal to 5.4
1599
 *
1600
 * @return boolean
1601
 * @since 7.12.3
1602
 *
1603
 */
1604
function monsterinsights_load_gutenberg_app() {
1605
	global $wp_version;
1606
1607
	if ( version_compare( $wp_version, '5.4', '<' ) ) {
1608
		return false;
1609
	}
1610
1611
	return true;
1612
}
1613
1614
/**
1615
 * Helper function for frontend script attributes
1616
 *
1617
 * @return string
1618
 * @since 7.12.3
1619
 *
1620
 *
1621
 */
1622
function monsterinsights_get_frontend_analytics_script_atts() {
1623
	$attr_string = '';
1624
1625
	$attributes = apply_filters( 'monsterinsights_tracking_analytics_script_attributes', array(
1626
		'type'         => "text/javascript",
1627
		'data-cfasync' => 'false'
1628
	) );
1629
1630
	if ( ! empty( $attributes ) ) {
1631
		foreach ( $attributes as $attr_name => $attr_value ) {
1632
			if ( ! empty( $attr_name ) ) {
1633
				$attr_string .= ' ' . sanitize_key( $attr_name ) . '="' . esc_attr( $attr_value ) . '"';
1634
			} else {
1635
				$attr_string .= ' ' . sanitize_key( $attr_value );
1636
			}
1637
		}
1638
	}
1639
1640
	return $attr_string;
1641
}
1642
1643
/**
1644
 * Get native english speaking countries
1645
 *
1646
 * @return array
1647
 *
1648
 * @since 7.12.3
1649
 */
1650
function monsterinsights_get_english_speaking_countries() {
1651
	return array(
1652
		'AG' => __( 'Antigua and Barbuda', 'google-analytics-for-wordpress' ),
1653
		'AU' => __( 'Australia', 'google-analytics-for-wordpress' ),
1654
		'BS' => __( 'The Bahamas', 'google-analytics-for-wordpress' ),
1655
		'BB' => __( 'Barbados', 'google-analytics-for-wordpress' ),
1656
		'BZ' => __( 'Belize', 'google-analytics-for-wordpress' ),
1657
		'CA' => __( 'Canada', 'google-analytics-for-wordpress' ),
1658
		'DM' => __( 'Dominica', 'google-analytics-for-wordpress' ),
1659
		'GD' => __( 'Grenada', 'google-analytics-for-wordpress' ),
1660
		'GY' => __( 'Guyana', 'google-analytics-for-wordpress' ),
1661
		'IE' => __( 'Ireland', 'google-analytics-for-wordpress' ),
1662
		'JM' => __( 'Jamaica', 'google-analytics-for-wordpress' ),
1663
		'NZ' => __( 'New Zealand', 'google-analytics-for-wordpress' ),
1664
		'KN' => __( 'St Kitts and Nevis', 'google-analytics-for-wordpress' ),
1665
		'LC' => __( 'St Lucia', 'google-analytics-for-wordpress' ),
1666
		'VC' => __( 'St Vincent and the Grenadines', 'google-analytics-for-wordpress' ),
1667
		'TT' => __( 'Trinidad and Tobago', 'google-analytics-for-wordpress' ),
1668
		'GB' => __( 'United Kingdom', 'google-analytics-for-wordpress' ),
1669
		'US' => __( 'United States of America', 'google-analytics-for-wordpress' ),
1670
	);
1671
}
1672
1673
/**
1674
 * Helper function to check if the current user can install a plugin.
1675
 *
1676
 * @return bool
1677
 */
1678
function monsterinsights_can_install_plugins() {
1679
1680
	if ( ! current_user_can( 'install_plugins' ) ) {
1681
		return false;
1682
	}
1683
1684
	// Determine whether file modifications are allowed.
1685
	if ( function_exists( 'wp_is_file_mod_allowed' ) && ! wp_is_file_mod_allowed( 'monsterinsights_can_install' ) ) {
1686
		return false;
1687
	}
1688
1689
	return true;
1690
}
1691
1692
/**
1693
 * Check if current date is between given dates. Date format: Y-m-d.
1694
 *
1695
 * @since 7.13.2
1696
 *
1697
 * @param string $start_date Start Date. Eg: 2021-01-01.
1698
 * @param string $end_date   End Date. Eg: 2021-01-14.
1699
 *
1700
 * @return bool
1701
 */
1702
function monsterinsights_date_is_between( $start_date, $end_date ) {
1703
1704
	$current_date = current_time( 'Y-m-d' );
1705
1706
	$start_date = date( 'Y-m-d', strtotime( $start_date ) );
1707
	$end_date   = date( 'Y-m-d', strtotime( $end_date ) );
1708
1709
	if ( ( $current_date >= $start_date ) && ( $current_date <= $end_date ) ) {
1710
		return true;
1711
	}
1712
1713
	return false;
1714
}
1715