MonsterInsights_Install

MonsterInsights Install.

Defined (1)

The class is defined in the following location(s).

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