/includes/helpers.php

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