/includes/install.php

  1. <?php 
  2. /** 
  3. * MonsterInsights Installation and Automatic Upgrades. 
  4. * 
  5. * This file handles setting up new 
  6. * MonsterInsights installs as well as performing 
  7. * behind the scene upgrades between 
  8. * MonsterInsights versions. 
  9. * 
  10. * @package MonsterInsights 
  11. * @subpackage Install/Upgrade 
  12. * @since 6.0.0 
  13. */ 
  14.  
  15. // Exit if accessed directly 
  16. if ( ! defined( 'ABSPATH' ) ) {  
  17. exit; 
  18.  
  19. /** 
  20. * MonsterInsights Install. 
  21. * 
  22. * This class handles a new MI install 
  23. * as well as automatic (non-user initiated)  
  24. * upgrade routines. 
  25. * 
  26. * @since 6.0.0 
  27. * @access public 
  28. */ 
  29. class MonsterInsights_Install { 
  30.  
  31. /** 
  32. * MI Settings. 
  33. * 
  34. * @since 6.0.0 
  35. * @access public 
  36. * @var array $new_settings When the init() function starts, initially 
  37. * contains the original settings. At the end  
  38. * of init() contains the settings to save. 
  39. */  
  40. public $new_settings = array(); 
  41.  
  42. /** 
  43. * Install/Upgrade routine. 
  44. * 
  45. * This function is what is called to actually install MI data on new installs and to do 
  46. * behind the scenes upgrades on MI upgrades. If this function contains a bug, the results  
  47. * can be catastrophic. This function gets the highest priority in all of MI for unit tests. 
  48. * 
  49. * @since 6.0.0 
  50. * @access public 
  51. * 
  52. * @todo I'd like to add preflight checks here. 
  53. * @todo I'd like to add a recovery system here. 
  54. *  
  55. * @return void 
  56. */ 
  57. public function init() { 
  58.  
  59. // Get a copy of the current MI settings. 
  60. $this->new_settings = get_option( monsterinsights_get_option_name() ); 
  61.  
  62.  
  63. $version = get_option( 'monsterinsights_current_version', false ); 
  64. $yoast = get_option( 'yst_ga', false ); 
  65. $cachec = false; // have we forced an object cache to be cleared already (so we don't clear it unnecessarily) 
  66.  
  67. // if new install and have not used Yoast previously 
  68. if ( ! $version && ! $yoast ) { 
  69.  
  70. $this->new_install(); 
  71. // This is the version used for MI upgrade routines. 
  72. update_option( 'monsterinsights_db_version', '6.0.0' ); 
  73.  
  74. } else if ( ! $version && $yoast ) { // if new install and has used Yoast previously 
  75.  
  76. $this->upgrade_from_yoast(); 
  77. // This is the version used for MI upgrade routines. 
  78. update_option( 'monsterinsights_db_version', '6.0.0' ); 
  79.  
  80. if ( ! $cachec ) { 
  81. wp_cache_flush(); 
  82. $cachec = true; 
  83.  
  84. } else { // if existing install 
  85. if ( version_compare( $version, '6.0.2', '<' ) ) { 
  86. $this->v602_upgrades(); 
  87. if ( version_compare( $version, '6.0.11', '<' ) ) { 
  88. $this->v6011_upgrades(); 
  89.  
  90. if ( ! $cachec ) { 
  91. wp_cache_flush(); 
  92. $cachec = true; 
  93. // @todo: doc as nonpublic 
  94.  
  95. update_option( 'monsterinsights_version_upgraded_from', $version ); 
  96. do_action( 'monsterinsights_after_existing_upgrade_routine', $version ); 
  97.  
  98. // This hook is used primarily by the Pro version to run some Pro 
  99. // specific install stuff. Please do not use this hook. It is not  
  100. // considered a public hook by MI's dev team and can/will be removed,  
  101. // relocated, and/or altered without warning at any time. You've been warned. 
  102. // As this hook is not for public use, we've intentionally not docbloc'd this 
  103. // hook to avoid developers seeing it future public dev docs. 
  104. do_action( 'monsterinsights_after_install_routine', $version ); 
  105.  
  106. // This is the version of the MI settings themselves 
  107. update_option( 'monsterinsights_settings_version', '6.0.0' ); 
  108.  
  109. // This is the version of MI installed 
  110. update_option( 'monsterinsights_current_version', MONSTERINSIGHTS_VERSION ); 
  111.  
  112. // This is where we save MI settings 
  113. update_option( monsterinsights_get_option_name(), $this->new_settings ); 
  114.  
  115. // This is where we redirect to the MI welcome page 
  116. //set_transient( '_monsterinsights_activation_redirect', true, 30 ); @todo: Investigate 
  117.  
  118. // There's no code for this function below this. Just an explanation 
  119. // of the MI core options. 
  120.  
  121. /**  
  122. * Explanation of MonsterInsights core options 
  123. * 
  124. * By now your head is probably spinning trying to figure 
  125. * out what all of these version options are for. Note, I've abbreviated 
  126. * "monsterinsights" to "mi" in the options names to make this table easier 
  127. * to read. 
  128. * 
  129. * Here's a basic rundown: 
  130. * 
  131. * mi_settings_version: Used to store the version  
  132. * of the MI settings. We use this 
  133. * so we can do upgrade routines where 
  134. * we'd have to do different actions based 
  135. * on the version the settings were installed 
  136. * in. For example: if we made a mistake with  
  137. * the value we saved as the default for  
  138. * a select setting, we can detect the version 
  139. * containing this mistake and correct it. 
  140. * 
  141. * mi_current_version: This starts with the actual version MI was 
  142. * installed on. We use this version to  
  143. * determine whether or not a site needs 
  144. * to run one of the behind the scenes 
  145. * MI upgrade routines. This version is updated 
  146. * every time a minor or major background upgrade 
  147. * routine is run. Generally lags behind the  
  148. * MONSTERINSIGHTS_VERSION constant by at most a couple minor 
  149. * versions. Never lags behind by 1 major version 
  150. * or more. 
  151. * 
  152. * mi_db_version: This is different from mi_current_version. 
  153. * Unlike the former, this is used to determine 
  154. * if a site needs to run a *user* initiated 
  155. * upgrade routine (see MI_Upgrade class). This 
  156. * value is only update when a user initiated 
  157. * upgrade routine is done. Because we do very 
  158. * few user initiated upgrades compared to  
  159. * automatic ones, this version can lag behind by 
  160. * 2 or even 3 major versions. Generally contains 
  161. * the current major version. 
  162. * 
  163. * mi_settings: Returned by monsterinsights_get_option_name(), this 
  164. * is actually "monsterinsights_settings" for both pro 
  165. * and lite version. However we use a helper function to  
  166. * retrieve the option name in case we ever decide down the 
  167. * road to maintain seperate options for the Lite and Pro versions. 
  168. * If you need to access MI's settings directly, (as opposed to our 
  169. * monsterinsights_get_option helper which uses the option name helper 
  170. * automatically), you should use this function to get the  
  171. * name of the option to retrieve. 
  172. * 
  173. * yst_ga: Yoast's old settings option. We no longer use this, though 
  174. * for backwards compatibility reasons we store the updated settings 
  175. * in this just for a little while longer. These settings are migrated 
  176. * to the new settings option when you upgrade to MonsterInsights 
  177. * 6.0 or higher automatically. 
  178. * 
  179. * yst_* & yoast_*: These are options from when the plugin was developed by 
  180. * Yoast, and also of the few point releases we did after 
  181. * the acquisition. Note, while we currently do backcompat 
  182. * on some of these options so other plugins will continue working 
  183. * please realize there will be a point in the near future that we  
  184. * will no longer support them. Please do not use them anymore. 
  185. */  
  186.  
  187.  
  188. /** 
  189. * New MonsterInsights Install routine. 
  190. * 
  191. * This function installs all of the default 
  192. * things on new MI installs. Flight 5476 with  
  193. * non-stop service to a whole world of  
  194. * possibilities is now boarding. 
  195. * 
  196. * @since 6.0.0 
  197. * @access public 
  198. *  
  199. * @return void 
  200. */ 
  201. public function new_install() { 
  202.  
  203. // Add default settings values 
  204. $this->new_settings = $this->get_monsterinsights_default_values(); 
  205.  
  206. $data = array( 
  207. 'installed_version' => MONSTERINSIGHTS_VERSION,  
  208. 'installed_date' => time(),  
  209. 'installed_pro' => monsterinsights_is_pro_version(),  
  210. ); 
  211.  
  212. update_option( 'monsterinsights_over_time', $data ); 
  213.  
  214. // Add cron job 
  215. if ( ! wp_next_scheduled( 'monsterinsights_daily_cron' ) ) { 
  216. // Set the next event of fetching data 
  217. wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:05:00 ' ), 'daily', 'monsterinsights_daily_cron' ); 
  218.  
  219. // Let addons + MI Pro/Lite hook in here. @todo: doc as nonpublic 
  220. do_action( 'monsterinsights_after_new_install_routine', MONSTERINSIGHTS_VERSION ); 
  221.  
  222. /** 
  223. * Upgrade from Yoast. 
  224. * 
  225. * This function does the upgrade routine from Yoast to this plugin version. 
  226. * Includes all of Yoast's previous routines. 
  227. * 
  228. * @since 6.0.0 
  229. * @access public 
  230. *  
  231. * @return void 
  232. */ 
  233. public function upgrade_from_yoast() { 
  234. // Do Yoast's Old Routines 
  235. $options = get_option( 'yst_ga', array() ); 
  236. if ( ! empty( $options['ga_general'] ) ) { 
  237. $options = $options['ga_general']; 
  238.  
  239. $tracking_code = null; 
  240. if ( ! empty( $options['analytics_profile'] ) && ! empty( $options['analytics_profile_code'] ) ) { 
  241. $tracking_code = $options['analytics_profile_code']; 
  242. } else if ( ! empty( $options['analytics_profile'] ) && empty( $options['analytics_profile_code'] ) ) { 
  243. // Analytics profile is still holding the UA code 
  244. $tracking_code = $options['analytics_profile']; 
  245.  
  246. if ( ! empty( $options['manual_ua_code_field'] ) && ! empty( $options['manual_ua_code'] ) ) { 
  247. $tracking_code = $options['manual_ua_code_field']; 
  248.  
  249. if ( ! isset( $options['version'] ) && is_null( $tracking_code ) ) { 
  250. $old_options = get_option( 'Yoast_Google_Analytics' ); 
  251. if ( isset( $old_options ) && is_array( $old_options ) ) { 
  252. if ( isset( $old_options['uastring'] ) && '' !== trim( $old_options['uastring'] ) ) { 
  253. // Save UA as manual UA, instead of saving all the old GA crap 
  254. $options['manual_ua_code'] = 1; 
  255. $options['manual_ua_code_field'] = $old_options['uastring']; 
  256. // Other settings 
  257. $options['allow_anchor'] = $old_options['allowanchor']; 
  258. $options['add_allow_linker'] = $old_options['allowlinker']; 
  259. $options['anonymous_data'] = $old_options['anonymizeip']; 
  260. $options['track_outbound'] = $old_options['trackoutbound']; 
  261. $options['track_internal_as_outbound'] = $old_options['internallink']; 
  262. $options['track_internal_as_label'] = $old_options['internallinklabel']; 
  263. $options['extensions_of_files'] = $old_options['dlextensions']; 
  264. delete_option( 'Yoast_Google_Analytics' ); 
  265. // 5.0.0 to 5.0.1 fix of ignore users array 
  266. if ( ! isset( $options['version'] ) || version_compare( $options['version'], '5.0.1', '<' ) ) { 
  267. if ( isset( $options['ignore_users'] ) && ! is_array( $options['ignore_users'] ) ) { 
  268. $options['ignore_users'] = (array) $options['ignore_users']; 
  269. // 5.1.2+ Remove firebug_lite from options, if set 
  270. if ( ! isset ( $options['version'] ) || version_compare( $options['version'], '5.1.2', '<' ) ) { 
  271. if ( isset( $options['firebug_lite'] ) ) { 
  272. unset( $options['firebug_lite'] ); 
  273. // 5.2.8+ Add disabled dashboards option 
  274. if ( ! isset ( $options['dashboards_disabled'] ) || version_compare( $options['version'], '5.2.8', '>' ) ) { 
  275. $options['dashboards_disabled'] = 0; 
  276. // Check is API option already exists - if not add it 
  277. $yst_ga_api = get_option( 'yst_ga_api' ); 
  278. if ( $yst_ga_api === false ) { 
  279. add_option( 'yst_ga_api', array(), '', 'no' ); 
  280. // Fallback to make sure every default option has a value 
  281. $defaults = $this->get_yoast_default_values(); 
  282. if ( is_array( $defaults ) ) { 
  283. foreach ( $defaults[ 'ga_general' ] as $key => $value ) { 
  284. if ( ! isset( $options[ $key ] ) ) { 
  285. $options[ $key ] = $value; 
  286.  
  287. // Set to the current version now that we've done all needed upgrades 
  288. $options['version'] = '5.5.3'; // Last Yoast codebase version 
  289. $saved_options = get_option( 'yst_ga' ); 
  290. $saved_options[ 'ga_general' ] = $options; 
  291. update_option( 'yst_ga', $saved_options ); 
  292.  
  293.  
  294. // Do license key switchover  
  295. $key = ''; 
  296. $found = false; 
  297. $network = false; 
  298. // Try network active Premium 
  299. $is_key = get_site_option( 'google-analytics-by-yoast-premium_license', array() ); 
  300. if ( $is_key && ! empty( $is_key ) && is_array( $is_key ) && ! empty( $is_key['key'] ) && is_multisite() ) { 
  301. $key = $is_key['key']; 
  302. $found = true; 
  303. $network = true; 
  304.  
  305. // Try single site Premium 
  306. if ( ! $found ) { 
  307. $is_key = get_option( 'google-analytics-by-yoast-premium_license', array() ); 
  308. if ( $is_key && ! empty( $is_key ) && is_array( $is_key ) && ! empty( $is_key['key'] ) ) { 
  309. $key = $is_key['key']; 
  310. $found = true; 
  311. }  
  312.  
  313. // Try network active Premium 
  314. if ( ! $found ) { 
  315. $is_key = get_site_option( 'monsterinsights-pro_license', array() ); 
  316. if ( $is_key && ! empty( $is_key ) && is_array( $is_key ) && ! empty( $is_key['key'] ) && is_multisite() ) { 
  317. $key = $is_key['key']; 
  318. $found = true; 
  319. $network = true; 
  320. }  
  321.  
  322. // Try single site Premium 
  323. if ( ! $found ) { 
  324. $is_key = get_option( 'monsterinsights-pro_license', array() ); 
  325. if ( $is_key && ! empty( $is_key ) && is_array( $is_key ) && ! empty( $is_key['key'] ) ) { 
  326. $key = $is_key['key']; 
  327. $found = true; 
  328. }  
  329.  
  330. // Try network active ecommmerce 
  331. if ( ! $found ) { 
  332. $is_key = get_site_option( 'ecommerce-addon_license', array() ); 
  333. if ( $is_key && ! empty( $is_key ) && is_array( $is_key ) && ! empty( $is_key['key'] ) && is_multisite() ) { 
  334. $key = $is_key['key']; 
  335. $found = true; 
  336. $network = true; 
  337. // Try single site ecommerce 
  338. if ( ! $found ) { 
  339. $is_key = get_option( 'ecommerce-addon_license', array() ); 
  340. if ( $is_key && ! empty( $is_key ) && is_array( $is_key ) && ! empty( $is_key['key'] ) ) { 
  341. $key = $is_key['key']; 
  342. $found = true; 
  343. }  
  344.  
  345. // set as new key for monsterinsights 
  346. if ( $found && ! empty( $key ) ) { 
  347. // In pro, install custom dimensions + ads. In lite, just save the key 
  348. do_action( 'monsterinsights_upgrade_from_yoast', $key, $network ); 
  349.  
  350. // Next up: Settings Migration 
  351.  
  352. $options = get_option( 'yst_ga', array() ); 
  353. if ( ! empty( $options['ga_general'] ) ) { 
  354. $options = $options['ga_general']; 
  355.  
  356.  
  357. // Let's remove the defaults 
  358. if ( isset( $options['ga_general'] ) ) { 
  359. unset( $options['ga_general'] ); 
  360.  
  361. // Let's remove unused options 
  362. if ( isset( $options['yoast_ga_nonce'] ) ) { 
  363. unset( $options['yoast_ga_nonce'] ); 
  364. }  
  365. if ( isset( $options['ga-form-settings'] ) ) { 
  366. unset( $options['ga-form-settings'] ); 
  367. if ( isset( $options['string_error_custom_dimensions'] ) ) { 
  368. unset( $options['string_error_custom_dimensions'] ); 
  369. if ( isset( $options['custom_metrics'] ) ) { 
  370. unset( $options['custom_metrics'] ); 
  371. }  
  372. if ( isset( $options['track_full_url'] ) ) { 
  373. unset( $options['track_full_url'] ); 
  374. }  
  375. if ( isset( $options['version'] ) ) { 
  376. unset( $options['version'] ); 
  377.  
  378. // Migrate universal to tracking_mode 
  379. if ( isset( $options['enable_universal'] ) ) { 
  380. unset( $options['enable_universal'] ); 
  381. $options['tracking_mode'] = 'analytics'; 
  382. } else { 
  383. $options['tracking_mode'] = 'ga'; 
  384.  
  385. // Migrate events tracking 
  386. if ( isset( $options['track_outbound'] ) ) { 
  387. unset( $options['track_outbound'] ); 
  388. $options['events_mode'] = 'php'; 
  389. } else { 
  390. $options['events_mode'] = 'none'; 
  391.  
  392. // Migrate anonymous_data to allow tracking 
  393. if ( isset( $options['anonymous_data'] ) ) { 
  394. unset( $options['anonymous_data'] ); 
  395. $options['allow_tracking'] = 1; 
  396. } else { 
  397. $options['allow_tracking'] = 0; 
  398.  
  399.  
  400. // Migrate GA profile data if there 
  401. // first let's try to salvage the current profile 
  402. $access_token = get_option( 'yoast-ga-access_token', array() ); 
  403. $refresh_token = get_option( 'yoast-ga-refresh_token', array() ); 
  404. $profiles = get_option( 'yst_ga_api', array() ); 
  405.  
  406. $profile_name = ! empty( $options['analytics_profile'] ) ? $options['analytics_profile'] : '';  
  407.  
  408. if ( empty( $refresh_token ) && ! empty( $access_token['refresh_token'] ) ) { 
  409. $refresh_token = $access_token['refresh_token']; 
  410.  
  411. // We need a name and a profile 
  412. if ( ! empty( $refresh_token ) && ! empty( $options['analytics_profile'] ) && ! empty( $profiles['ga_api_response_accounts'] ) ) { 
  413. // See if we have an access token 
  414. if ( ! empty( $access_token['access_token'] ) ) { 
  415. if ( monsterinsights_is_pro_version() ) { 
  416. update_option( 'monsterinsights_pro_access_token', $access_token['access_token'] ); 
  417. } else { 
  418. update_option( 'monsterinsights_lite_access_token', $access_token['access_token'] ); 
  419.  
  420. // We need a refresh token 
  421. if ( monsterinsights_is_pro_version() ) { 
  422. update_option( 'monsterinsights_pro_refresh_token', $refresh_token ); 
  423. } else { 
  424. update_option( 'monsterinsights_lite_refresh_token', $refresh_token ); 
  425.  
  426. // If we can find the profile in the response save the name 
  427. if ( ! empty( $profiles['ga_api_response_accounts'] ) && is_array( $profiles['ga_api_response_accounts'] ) ) { 
  428. foreach ( $profiles['ga_api_response_accounts'] as $account ) { 
  429. foreach ( $account['items'] as $profile ) { 
  430. foreach ( $profile['items'] as $subprofile ) { 
  431. if ( isset( $subprofile['id'] ) && $subprofile['id'] == $profile_name ) { 
  432. $options['analytics_profile_name'] = $subprofile['name']; 
  433. if ( empty( $options['analytics_profile_code'] ) ) { 
  434. $options['analytics_profile_code'] = $subprofile['ua_code']; 
  435. break 3; 
  436. $options['cron_last_run'] = strtotime("-25 hours"); 
  437. } else { 
  438. // if UA in manual code field, remove analytics profile fields if set 
  439. if ( ! empty( $options['manual_ua_code_field' ] ) ) { 
  440. if ( isset( $options['analytics_profile_code'] ) ) { 
  441. unset( $options['analytics_profile_code'] ); 
  442. if ( isset( $options['analytics_profile'] ) ) { 
  443. unset( $options['analytics_profile'] ); 
  444. $options['manual_ua_code'] = $options['manual_ua_code_field']; 
  445. delete_option( 'yoast-ga-access_token' ); 
  446. delete_option( 'yoast-ga-refresh_token' ); 
  447. delete_option( 'yst_ga_api' ); 
  448. } else if ( ! empty( $options['analytics_profile_code' ] ) ) { 
  449. // if UA in profile fields, remove others and use that 
  450. $options['manual_ua_code'] = $options['analytics_profile_code']; 
  451. if ( isset( $options['analytics_profile_code'] ) ) { 
  452. unset( $options['analytics_profile_code'] ); 
  453. if ( isset( $options['analytics_profile'] ) ) { 
  454. unset( $options['analytics_profile'] ); 
  455. delete_option( 'yoast-ga-access_token' ); 
  456. delete_option( 'yoast-ga-refresh_token' ); 
  457. delete_option( 'yst_ga_api' ); 
  458. } else { 
  459. // if UA in profile profiles, remove others and use that 
  460. if ( ! empty( $options['analytics_profile' ] ) && ! empty( $profiles['ga_api_response_accounts'] ) && is_array( $profiles['ga_api_response_accounts'] ) ) { 
  461. foreach ( $profiles as $account ) { 
  462. foreach ( $account['items'] as $profile ) { 
  463. foreach ( $profile['items'] as $subprofile ) { 
  464. if ( isset( $subprofile['id'] ) && $subprofile['id'] == $options['analytics_profile' ] ) { 
  465. $options['manual_ua_code'] = $subprofile['ua_code']; 
  466. break 3; 
  467. delete_option( 'yoast-ga-access_token' ); 
  468. delete_option( 'yoast-ga-refresh_token' ); 
  469. delete_option( 'yst_ga_api' ); 
  470.  
  471. if ( isset( $options['manual_ua_code_field'] ) ) { 
  472. unset( $options['manual_ua_code_field'] ); 
  473.  
  474. // oAuth Stir Data Tank 
  475. // Will happen automatically as cron_last_run set to 25 hours ago 
  476.  
  477. // Add oAuth version  
  478. $options['oauth_version'] = '1.0.0'; 
  479.  
  480. $data = array( 
  481. 'installed_version' => MONSTERINSIGHTS_VERSION,  
  482. 'installed_date' => time(),  
  483. 'installed_pro' => monsterinsights_is_pro_version(),  
  484. ); 
  485.  
  486. update_option( 'monsterinsights_over_time', $data ); 
  487.  
  488. // Add the cron job 
  489. if ( ! wp_next_scheduled( 'monsterinsights_daily_cron' ) ) { 
  490. // Set the next event of fetching data 
  491. wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:05:00 ' ), 'daily', 'monsterinsights_daily_cron' ); 
  492.  
  493. // Finish up 
  494. // Save the new settings 
  495. $this->new_settings = $options; 
  496.  
  497. public function get_yoast_default_values() { 
  498. $options = array( 
  499. 'ga_general' => array( 
  500. 'analytics_profile' => null,  
  501. 'analytics_profile_code' => null,  
  502. 'manual_ua_code' => 0,  
  503. 'manual_ua_code_field' => null,  
  504. 'track_internal_as_outbound' => null,  
  505. 'track_internal_as_label' => null,  
  506. 'track_outbound' => 0,  
  507. 'anonymous_data' => 0,  
  508. 'enable_universal' => 1,  
  509. 'demographics' => 0,  
  510. 'ignore_users' => array( 'administrator', 'editor' ),  
  511. 'dashboards_disabled' => 0,  
  512. 'anonymize_ips' => 0,  
  513. 'track_download_as' => 'event',  
  514. 'extensions_of_files' => 'doc, exe, js, pdf, ppt, tgz, zip, xls',  
  515. 'track_full_url' => 'domain',  
  516. 'subdomain_tracking' => null,  
  517. 'tag_links_in_rss' => 0,  
  518. 'allow_anchor' => 0,  
  519. 'add_allow_linker' => 0,  
  520. 'enhanced_link_attribution' => 0,  
  521. 'custom_code' => null,  
  522. 'debug_mode' => 0,  
  523. ); 
  524. $options = apply_filters( 'yst_ga_default-ga-values', $options, 'ga_general' ); 
  525. return $options; 
  526.  
  527. public function get_monsterinsights_default_values() { 
  528. return array( 
  529. 'analytics_profile' => '',  
  530. 'analytics_profile_code' => '',  
  531. 'manual_ua_code' => '',  
  532. 'track_internal_as_outbound' => 0,  
  533. 'track_internal_as_label' => '',  
  534. 'track_outbound' => 1,  
  535. 'allow_tracking' => 0,  
  536. 'tracking_mode' => 'analytics',  
  537. 'events_mode' => 'js',  
  538. 'demographics' => 1,  
  539. 'ignore_users' => array( 'administrator', 'editor' ),  
  540. 'dashboards_disabled' => 0,  
  541. 'anonymize_ips' => 0,  
  542. 'track_download_as' => 'event',  
  543. 'extensions_of_files' => 'doc, exe, js, pdf, ppt, tgz, zip, xls',  
  544. 'subdomain_tracking' => '',  
  545. 'tag_links_in_rss' => 0,  
  546. 'allow_anchor' => 0,  
  547. 'add_allow_linker' => 0,  
  548. 'enhanced_link_attribution' => 1,  
  549. 'custom_code' => '',  
  550. 'debug_mode' => 0,  
  551. 'anonymous_data' => 0,  
  552. 'save_setings' => array(),  
  553. 'view_reports' => array(),  
  554. ); 
  555.  
  556. /** 
  557. * MonsterInsights Version 6.0.2 upgrades. 
  558. * 
  559. * This detects if a manual auth code is in the Yoast settings, and not 
  560. * in the MI settings, and that oAuth hasn't been performed (caused by the 
  561. * manual ua code not being transferred during the 6.0 upgrade routine) 
  562. * and automatically fixes it. 
  563. * 
  564. * @since 6.0.2 
  565. * @access public 
  566. *  
  567. * @return void 
  568. */ 
  569. public function v602_upgrades() { 
  570. $options = get_option( 'yst_ga', array() ); 
  571. if ( ( empty( $this->new_settings[ 'manual_ua_code'] ) || $this->new_settings[ 'manual_ua_code'] === '1' ) &&  
  572. empty( $this->new_settings[ 'analytics_profile_code'] ) && 
  573. ! empty( $options ) && 
  574. is_array( $options ) && 
  575. ! empty( $options['ga_general']['manual_ua_code_field'] ) 
  576. ) { 
  577. $this->new_settings['manual_ua_code'] = $options['ga_general']['manual_ua_code_field']; 
  578.  
  579. /** 
  580. * MonsterInsights Version 6.0.11 upgrades. 
  581. * 
  582. * This upgrade routine finds and removes the old crons if they exist. 
  583. * 
  584. * @since 6.0.11 
  585. * @access public 
  586. *  
  587. * @return void 
  588. */ 
  589. public function v6011_upgrades() { 
  590. // If old tracking checkin exists, remove it 
  591. if ( wp_next_scheduled( 'monsterinsights_send_tracking_checkin' ) ) { 
  592. wp_clear_scheduled_hook( 'monsterinsights_send_tracking_checkin' ); 
  593.  
  594. // Remove Weekly cron 
  595. if ( wp_next_scheduled( 'monsterinsights_weekly_cron' ) ) { 
  596. wp_clear_scheduled_hook( 'monsterinsights_weekly_cron' ); 
  597.  
  598. // Remove Yoast cron 
  599. if ( wp_next_scheduled( 'yst_ga_aggregate_data' ) ) { 
  600. wp_clear_scheduled_hook( 'yst_ga_aggregate_data' ); 
  601.  
  602. /** 
  603. * MonsterInsights Version 6.1 upgrades. 
  604. * 
  605. * This function does the 
  606. * upgrade routine from MonsterInsights 6.0->6.1. 
  607. * 
  608. * @since 6.1.0 
  609. * @access public 
  610. *  
  611. * @return void 
  612. */ 
  613. public function v610_upgrades() { 
  614. // Not in use yet. 
  615.  
  616. /** 
  617. * Running List of Things To Do In 6.1.0's Upgrade Routine 
  618. * 
  619. * 1. Drop Yoast yst_ga options if the upgraded from option === 6.0 or higher 
  620. * 2. Remove yst_ga support from helper options 
  621. * 3. Remove track_full_url 
  622. */ 
.