helpers.php 40 KB

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