PluginProbe ʕ •ᴥ•ʔ
MonsterInsights – Google Analytics Dashboard for WordPress (Website Stats Made Easy) / 8.2.0
MonsterInsights – Google Analytics Dashboard for WordPress (Website Stats Made Easy) v8.2.0
10.2.2 10.2.1 10.2.0 10.1.3 trunk 10.0.0 10.0.1 10.0.2 10.0.3 10.1.1 10.1.2 8.1.0 8.10.0 8.10.1 8.11.0 8.12.0 8.12.1 8.13.0 8.13.1 8.14.0 8.14.1 8.15 8.16 8.17 8.18 8.19.0 8.2.0 8.20.0 8.20.1 8.21.0 8.22.0 8.23.0 8.23.1 8.24.0 8.25.0 8.26.0 8.27.0 8.28.0 8.3.0 8.3.1 8.3.2 8.3.3 8.3.4 8.4.0 8.5.0 8.5.1 8.5.2 8.5.3 8.6.0 8.7.0 8.8.0 8.8.1 8.8.2 8.9.0 8.9.1 9.0.0 9.0.1 9.1.0 9.1.1 9.10.0 9.10.1 9.11.0 9.11.1 9.2.0 9.2.1 9.2.2 9.2.3 9.2.4 9.3.0 9.3.1 9.4.0 9.4.1 9.5.1 9.5.2 9.5.3 9.6.0 9.6.1 9.7.0 9.8.0 9.9.0
google-analytics-for-wordpress / includes / install.php
google-analytics-for-wordpress / includes Last commit date
admin 4 years ago emails 4 years ago frontend 4 years ago gutenberg 4 years ago popular-posts 4 years ago api-request.php 4 years ago auth.php 4 years ago capabilities.php 4 years ago compatibility-check.php 4 years ago deprecated.php 4 years ago helpers.php 4 years ago index.php 4 years ago install.php 4 years ago measurement-protocol-v4.php 4 years ago measurement-protocol.php 4 years ago options.php 4 years ago
install.php
864 lines
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 /**
21 * MonsterInsights Install.
22 *
23 * This class handles a new MI install
24 * as well as automatic (non-user initiated)
25 * upgrade routines.
26 *
27 * @since 6.0.0
28 * @access public
29 */
30 class MonsterInsights_Install {
31
32 /**
33 * MI Settings.
34 *
35 * @since 6.0.0
36 * @access public
37 * @var array $new_settings When the init() function starts, initially
38 * contains the original settings. At the end
39 * of init() contains the settings to save.
40 */
41 public $new_settings = array();
42
43 /**
44 * Install/Upgrade routine.
45 *
46 * This function is what is called to actually install MI data on new installs and to do
47 * behind the scenes upgrades on MI upgrades. If this function contains a bug, the results
48 * can be catastrophic. This function gets the highest priority in all of MI for unit tests.
49 *
50 * @since 6.0.0
51 * @access public
52 *
53 * @return void
54 */
55 public function init() {
56
57 // Get a copy of the current MI settings.
58 $this->new_settings = get_option( monsterinsights_get_option_name() );
59
60 $version = get_option( 'monsterinsights_current_version', false );
61 $cachec = false; // have we forced an object cache to be cleared already (so we don't clear it unnecessarily)
62
63 // if new install or Yoast Era instal
64 if ( ! $version ) {
65 // See if from Yoast
66 $yoast = get_option( 'yst_ga', false );
67
68 // In case from Yoast, start from scratch
69 delete_option( 'yoast-ga-access_token' );
70 delete_option( 'yoast-ga-refresh_token' );
71 delete_option( 'yst_ga' );
72 delete_option( 'yst_ga_api' );
73
74 $this->new_install();
75
76 // set db version (Do not increment! See below large comment)
77 update_option( 'monsterinsights_db_version', '7.4.0' );
78
79 // Remove Yoast hook if present
80 if ( wp_next_scheduled( 'yst_ga_aggregate_data' ) ) {
81 wp_clear_scheduled_hook( 'yst_ga_aggregate_data' );
82 }
83
84 // Clear cache since coming from Yoast
85 if ( ! $cachec && ! empty( $yoast ) ) {
86 wp_cache_flush();
87 $cachec = true;
88 }
89 } else { // if existing install
90 if ( version_compare( $version, '6.0.11', '<' ) ) {
91 if ( ! $cachec ) {
92 wp_cache_flush();
93 $cachec = true;
94 }
95 }
96
97 if ( version_compare( $version, '7.0.0', '<' ) ) {
98 $this->v700_upgrades();
99 }
100
101 if ( version_compare( $version, '7.4.0', '<' ) ) {
102 $this->v740_upgrades();
103 // Do not increment! See below large comment
104 update_option( 'monsterinsights_db_version', '7.4.0' );
105 }
106
107 if ( version_compare( $version, '7.5.0', '<' ) ) {
108 $this->v750_upgrades();
109 }
110
111 if ( version_compare( $version, '7.6.0', '<' ) ) {
112 $this->v760_upgrades();
113 }
114
115 if ( version_compare( $version, '7.7.1', '<' ) ) {
116 $this->v771_upgrades();
117 }
118
119 if ( version_compare( $version, '7.8.0', '<' ) ) {
120 $this->v780_upgrades();
121 }
122
123 if ( version_compare( $version, '7.9.0', '<' ) ) {
124 $this->v790_upgrades();
125 }
126
127 if ( version_compare( $version, '7.10.0', '<' ) ) {
128 $this->v7100_upgrades();
129 }
130
131 if ( version_compare( $version, '7.11.0', '<' ) ) {
132 $this->v7110_upgrades();
133 }
134
135 if ( version_compare( $version, '7.12.0', '<' ) ) {
136 $this->v7120_upgrades();
137 }
138
139 if ( version_compare( $version, '7.13.0', '<' ) ) {
140 $this->v7130_upgrades();
141 }
142
143 if ( version_compare( $version, '7.13.1', '<' ) ) {
144 $this->v7131_upgrades();
145 }
146
147 if ( version_compare( $version, '7.14.0', '<' ) ) {
148 $this->v7140_upgrades();
149 }
150
151 if ( version_compare( $version, '7.15.0', '<' ) ) {
152 $this->v7150_upgrades();
153 }
154
155 // Do not use. See monsterinsights_after_install_routine comment below.
156 do_action( 'monsterinsights_after_existing_upgrade_routine', $version );
157 $version = get_option( 'monsterinsights_current_version', $version );
158 update_option( 'monsterinsights_version_upgraded_from', $version );
159 }
160
161 // This hook is used primarily by the Pro version to run some Pro
162 // specific install stuff. Please do not use this hook. It is not
163 // considered a public hook by MI's dev team and can/will be removed,
164 // relocated, and/or altered without warning at any time. You've been warned.
165 // As this hook is not for public use, we've intentionally not docbloc'd this
166 // hook to avoid developers seeing it future public dev docs.
167 do_action( 'monsterinsights_after_install_routine', $version );
168
169 // This is the version of MI installed
170 update_option( 'monsterinsights_current_version', MONSTERINSIGHTS_VERSION );
171
172 // This is where we save MI settings
173 update_option( monsterinsights_get_option_name(), $this->new_settings );
174
175 // There's no code for this function below this. Just an explanation
176 // of the MI core options.
177
178 /**
179 * Explanation of MonsterInsights core options
180 *
181 * By now your head is probably spinning trying to figure
182 * out what all of these version options are for. Note, I've abbreviated
183 * "monsterinsights" to "mi" in the options names to make this table easier
184 * to read.
185 *
186 * Here's a basic rundown:
187 *
188 * mi_current_version: This starts with the actual version MI was
189 * installed on. We use this version to
190 * determine whether or not a site needs
191 * to run one of the behind the scenes
192 * MI upgrade routines. This version is updated
193 * every time a minor or major background upgrade
194 * routine is run. Generally lags behind the
195 * MONSTERINSIGHTS_VERSION constant by at most a couple minor
196 * versions. Never lags behind by 1 major version
197 * or more generally.
198 *
199 * mi_db_version: This is different from mi_current_version.
200 * Unlike the former, this is used to determine
201 * if a site needs to run a *user* initiated
202 * upgrade routine (incremented in MI_Upgrade class). This
203 * value is only update when a user initiated
204 * upgrade routine is done. Because we do very
205 * few user initiated upgrades compared to
206 * automatic ones, this version can lag behind by
207 * 2 or even 3 major versions. Generally contains
208 * the current major version.
209 *
210 * mi_settings: Returned by monsterinsights_get_option_name(), this
211 * is actually "monsterinsights_settings" for both pro
212 * and lite version. However we use a helper function to
213 * retrieve the option name in case we ever decide down the
214 * road to maintain seperate options for the Lite and Pro versions.
215 * If you need to access MI's settings directly, (as opposed to our
216 * monsterinsights_get_option helper which uses the option name helper
217 * automatically), you should use this function to get the
218 * name of the option to retrieve.
219 *
220 * Therefore you should never increment mi_db_version in this file and always increment mi_current_version.
221 */
222 }
223
224
225 /**
226 * New MonsterInsights Install routine.
227 *
228 * This function installs all of the default
229 * things on new MI installs. Flight 5476 with
230 * non-stop service to a whole world of
231 * possibilities is now boarding.
232 *
233 * @since 6.0.0
234 * @access public
235 *
236 * @return void
237 */
238 public function new_install() {
239 $this->new_settings = $this->get_monsterinsights_default_values();
240
241 $this->maybe_import_thirstyaffiliates_options();
242
243 $data = array(
244 'installed_version' => MONSTERINSIGHTS_VERSION,
245 'installed_date' => time(),
246 'installed_pro' => monsterinsights_is_pro_version() ? time() : false,
247 'installed_lite' => monsterinsights_is_pro_version() ? false : time(),
248 );
249
250 update_option( 'monsterinsights_over_time', $data, false );
251
252 // Let addons + MI Pro/Lite hook in here. @todo: doc as nonpublic
253 do_action( 'monsterinsights_after_new_install_routine', MONSTERINSIGHTS_VERSION );
254 }
255
256 public function get_monsterinsights_default_values() {
257
258 $admin_email = get_option( 'admin_email' );
259 $admin_email_array = array(
260 array(
261 'email' => $admin_email,
262 ),
263 );
264
265 return array(
266 'enable_affiliate_links' => true,
267 'affiliate_links' => array(
268 array(
269 'path' => '/go/',
270 'label' => 'affiliate',
271 ),
272 array(
273 'path' => '/recommend/',
274 'label' => 'affiliate',
275 )
276 ),
277 'demographics' => 1,
278 'ignore_users' => array( 'administrator', 'editor' ),
279 'dashboards_disabled' => 0,
280 'anonymize_ips' => 0,
281 'extensions_of_files' => 'doc,pdf,ppt,zip,xls,docx,pptx,xlsx',
282 'subdomain_tracking' => '',
283 'link_attribution' => true,
284 'tag_links_in_rss' => true,
285 'allow_anchor' => 0,
286 'add_allow_linker' => 0,
287 'save_settings' => array( 'administrator' ),
288 'view_reports' => array( 'administrator', 'editor' ),
289 'events_mode' => 'js',
290 'tracking_mode' => 'gtag', // Default new users to gtag.
291 'email_summaries' => 'on',
292 'summaries_html_template' => 'yes',
293 'summaries_email_addresses' => $admin_email_array,
294 'automatic_updates' => 'none',
295 'popular_posts_inline_theme' => 'alpha',
296 'popular_posts_widget_theme' => 'alpha',
297 'popular_posts_products_theme' => 'alpha',
298 'popular_posts_inline_placement' => 'manual',
299 'popular_posts_widget_theme_columns' => '2',
300 'popular_posts_products_theme_columns' => '2',
301 'popular_posts_widget_count' => '4',
302 'popular_posts_products_count' => '4',
303 'popular_posts_widget_theme_meta_author' => 'on',
304 'popular_posts_widget_theme_meta_date' => 'on',
305 'popular_posts_widget_theme_meta_comments' => 'on',
306 'popular_posts_products_theme_meta_price' => 'on',
307 'popular_posts_products_theme_meta_rating' => 'on',
308 'popular_posts_products_theme_meta_image' => 'on',
309 'popular_posts_inline_after_count' => '150',
310 'popular_posts_inline_multiple_number' => '3',
311 'popular_posts_inline_multiple_distance' => '250',
312 'popular_posts_inline_multiple_min_words' => '100',
313 'popular_posts_inline_post_types' => array( 'post' ),
314 'popular_posts_widget_post_types' => array( 'post' ),
315 );
316 }
317
318 /**
319 * Check if ThirstyAffiliates plugin is installed and use the link prefix value in the affiliate settings.
320 *
321 * @return void
322 */
323 public function maybe_import_thirstyaffiliates_options() {
324
325 // Check if ThirstyAffiliates is installed.
326 if ( ! function_exists( 'ThirstyAffiliates' ) ) {
327 return;
328 }
329
330 $link_prefix = get_option( 'ta_link_prefix', 'recommends' );
331
332 if ( $link_prefix === 'custom' ) {
333 $link_prefix = get_option( 'ta_link_prefix_custom', 'recommends' );
334 }
335
336 if ( ! empty( $link_prefix ) ) {
337
338 // Check if prefix exists.
339 $prefix_set = false;
340 foreach ( $this->new_settings['affiliate_links'] as $affiliate_link ) {
341 if ( $link_prefix === trim( $affiliate_link['path'], '/' ) ) {
342 $prefix_set = true;
343 break;
344 }
345 }
346
347 if ( ! $prefix_set ) {
348 $this->new_settings['affiliate_links'][] = array(
349 'path' => '/' . $link_prefix . '/',
350 'label' => 'affiliate',
351 );
352 }
353 }
354 }
355
356 /**
357 * MonsterInsights Version 7.0 upgrades.
358 *
359 * This function does the
360 * upgrade routine from MonsterInsights 6.2->7.0.
361 *
362 * @since 7.0.0
363 * @access public
364 *
365 * @return void
366 */
367 public function v700_upgrades() {
368 // 1. Default all event tracking and tracking to GA + JS respectively
369 // 3a Set tracking_mode to use analytics.js
370 $this->new_settings['tracking_mode' ] = 'analytics';
371
372
373 // 3b Set events mode to use JS if the events mode is not set explicitly to none
374 if ( empty( $this->new_settings['events_mode' ] ) || $this->new_settings['events_mode' ] !== 'none' ) {
375 $this->new_settings['events_mode' ] = 'js';
376 }
377
378 // 2. Migrate manual UA codes
379 // 2a Manual UA has the lowest priority
380 if ( ! empty( $this->new_settings['manual_ua_code' ] ) ) {
381 // Set as manual UA code
382 is_network_admin() ? update_site_option( 'monsterinsights_network_profile', array( 'manual' => $this->new_settings['manual_ua_code' ] ) ) : update_option( 'monsterinsights_site_profile', array( 'manual' => $this->new_settings['manual_ua_code' ] ) );
383 }
384
385 // 2b Then try the oAuth UA code
386 if ( ! empty( $this->new_settings['analytics_profile_code' ] ) ) {
387 // Set as manual UA code
388 is_network_admin() ? update_site_option( 'monsterinsights_network_profile', array( 'manual' => $this->new_settings['analytics_profile_code' ] ) ) : update_option( 'monsterinsights_site_profile', array( 'manual' => $this->new_settings['analytics_profile_code' ] ) );
389 }
390
391 // 3. Migrate License keys
392 if ( is_multisite() ) {
393 $ms_license = get_site_option( 'monsterinsights_license', '' );
394 if ( $ms_license ) {
395 update_site_option( 'monsterinsights_network_license_updates', get_site_option( 'monsterinsights_license_updates', '' ) );
396 update_site_option( 'monsterinsights_network_license', $ms_license );
397 }
398 }
399 }
400
401 /**
402 * Upgrade routine for the new settings panel, onboarding wizard, and the internal-as-outbound v2 settings system.
403 */
404 public function v740_upgrades() {
405
406 // 1. Settings Conversions:
407 // Convert affiliate field to repeater format
408 if ( ! empty( $this->new_settings['track_internal_as_outbound'] ) ) {
409 $affiliate_old_paths = $this->new_settings['track_internal_as_outbound'];
410 $affiliate_old_label = isset( $this->new_settings['track_internal_as_label'] ) ? $this->new_settings['track_internal_as_label'] : '';
411
412 $new_paths = explode( ',', $affiliate_old_paths );
413
414 $this->new_settings['affiliate_links'] = array();
415 if ( ! empty( $new_paths ) ) {
416 $this->new_settings['enable_affiliate_links'] = true;
417 foreach ( $new_paths as $new_path ) {
418 $this->new_settings['affiliate_links'][] = array(
419 'path' => $new_path,
420 'label' => $affiliate_old_label,
421 );
422 }
423 }
424
425 $settings = array(
426 'track_internal_as_outbound',
427 'track_internal_as_label',
428 );
429 foreach ( $settings as $setting ) {
430 if ( ! empty( $this->new_settings[ $setting ] ) ) {
431 unset( $this->new_settings[ $setting ] );
432 }
433 }
434 }
435
436 // Update option to disable just reports or also the dashboard widget.
437 if ( isset( $this->new_settings['dashboards_disabled'] ) && $this->new_settings['dashboards_disabled'] ) {
438 $this->new_settings['dashboards_disabled'] = 'disabled';
439 }
440
441 $this->new_settings['tracking_mode'] = 'analytics';
442 $this->new_settings['events_mode'] = 'js';
443
444 // If opted in during allow_tracking era, move that over
445 if ( ! empty( $this->new_settings['allow_tracking'] ) ) {
446 $this->new_settings['anonymous_data'] = 1;
447 }
448
449 // 2. Remove Yoast stuff
450 delete_option( 'yoast-ga-access_token' );
451 delete_option( 'yoast-ga-refresh_token' );
452 delete_option( 'yst_ga' );
453 delete_option( 'yst_ga_api' );
454
455
456 // 3. Remove fake settings from other plugins using our key for some reason and old settings of ours
457 $settings = array(
458 'debug_mode',
459 'track_download_as',
460 'analytics_profile',
461 'analytics_profile_code',
462 'analytics_profile_name',
463 'manual_ua_code',
464 'track_outbound',
465 'track_download_as',
466 'enhanced_link_attribution',
467 'oauth_version',
468 'monsterinsights_oauth_status',
469 'firebug_lite',
470 'google_auth_code',
471 'allow_tracking',
472 );
473
474 foreach ( $settings as $setting ) {
475 if ( ! empty( $this->new_settings[ $setting ] ) ) {
476 unset( $this->new_settings[ $setting ] );
477 }
478 }
479
480 $settings = array(
481 '_repeated',
482 'ajax',
483 'asmselect0',
484 'bawac_force_nonce',
485 'icl_post_language',
486 'saved_values',
487 'mlcf_email',
488 'mlcf_name',
489 'cron_failed',
490 'undefined',
491 'cf_email',
492 'cf_message',
493 'cf_name',
494 'cf_number',
495 'cf_phone',
496 'cf_subject',
497 'content',
498 'credentials',
499 'cron_failed',
500 'cron_last_run',
501 'global-css',
502 'grids',
503 'page',
504 'punch-fonts',
505 'return_tab',
506 'skins',
507 'navigation-skins',
508 'title',
509 'type',
510 'wpcf_email',
511 'wpcf_your_name',
512 );
513
514 foreach ( $settings as $setting ) {
515 if ( ! empty( $this->new_settings[ $setting ] ) ) {
516 unset( $this->new_settings[ $setting ] );
517 }
518 }
519
520 // 4. Remove old crons
521 if ( wp_next_scheduled( 'monsterinsights_daily_cron' ) ) {
522 wp_clear_scheduled_hook( 'monsterinsights_daily_cron' );
523 }
524 if ( wp_next_scheduled( 'monsterinsights_send_tracking_data' ) ) {
525 wp_clear_scheduled_hook( 'monsterinsights_send_tracking_data' );
526 }
527
528 if ( wp_next_scheduled( 'monsterinsights_send_tracking_checkin' ) ) {
529 wp_clear_scheduled_hook( 'monsterinsights_send_tracking_checkin' );
530 }
531
532 if ( wp_next_scheduled( 'monsterinsights_weekly_cron' ) ) {
533 wp_clear_scheduled_hook( 'monsterinsights_weekly_cron' );
534 }
535
536 if ( wp_next_scheduled( 'yst_ga_aggregate_data' ) ) {
537 wp_clear_scheduled_hook( 'yst_ga_aggregate_data' );
538 }
539
540 delete_option( 'monsterinsights_tracking_last_send' );
541 delete_option( 'mi_tracking_last_send' );
542
543 // 5. Remove old option
544 delete_option( 'monsterinsights_settings_version' );
545 }
546
547
548 /**
549 * Upgrade routine
550 */
551 public function v750_upgrades() {
552 // 1. One time re-prompt for anonymous data (due to migration bug now fixed)
553 // if ( ! monsterinsights_is_pro_version() ) {
554 // if ( empty( $this->new_settings[ 'anonymous_data' ] ) ) {
555 // update_option( 'monsterinsights_tracking_notice', 0 );
556 // }
557 // }
558 //
559 // 2. Clear old settings ( 'tracking_mode','events_mode',)
560
561
562 // 3. Attempt to extract the cross-domain settings from the Custom Code area and use in the new option.
563 $custom_code = isset( $this->new_settings['custom_code'] ) ? $this->new_settings['custom_code'] : '';
564 if ( ! empty( $custom_code ) ) {
565 $pattern = '/(?:\'linker:autoLink\', )(?:\[)(.*)(?:\])/m';
566 preg_match_all( $pattern, $custom_code, $matches, PREG_SET_ORDER, 0 );
567 if ( ! empty( $matches ) && isset( $matches[0] ) && isset( $matches[0][1] ) ) {
568 $cross_domains = array();
569 $domains = explode( ',', $matches[0][1] );
570 foreach ( $domains as $key => $domain ) {
571 $domain = trim( $domain );
572 $cross_domains[] = array(
573 'domain' => trim( $domain, '\'\"' ),
574 );
575 }
576 $this->new_settings['add_allow_linker'] = true;
577 $this->new_settings['cross_domains'] = $cross_domains;
578
579 $notices = get_option( 'monsterinsights_notices' );
580 if ( ! is_array( $notices ) ) {
581 $notices = array();
582 }
583 $notices['monsterinsights_cross_domains_extracted'] = false;
584 update_option( 'monsterinsights_notices', $notices );
585 }
586 }
587 }
588
589 /**
590 * Upgrade routine for version 7.6.0
591 */
592 public function v760_upgrades() {
593
594 $cross_domains = isset( $this->new_settings['cross_domains'] ) ? $this->new_settings['cross_domains'] : array();
595
596 if ( ! empty( $cross_domains ) && is_array( $cross_domains ) ) {
597 $current_domain = wp_parse_url( home_url() );
598 $current_domain = isset( $current_domain['host'] ) ? $current_domain['host'] : '';
599 if ( ! empty( $current_domain ) ) {
600 $regex = '/^(?:' . $current_domain . '|(?:.+)\.' . $current_domain . ')$/m';
601 foreach ( $cross_domains as $key => $cross_domain ) {
602 if ( ! isset( $cross_domain['domain'] ) ) {
603 continue;
604 }
605 preg_match( $regex, $cross_domain['domain'], $matches );
606 if ( count( $matches ) > 0 ) {
607 unset( $this->new_settings['cross_domains'][ $key ] );
608 }
609 }
610 }
611 }
612
613 }
614
615 /**
616 * Upgrade routine for version 7.7.1
617 */
618 public function v771_upgrades() {
619
620 if ( ! monsterinsights_is_pro_version() ) {
621 // We only need to run this for the Pro version.
622 return;
623 }
624 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
625
626 $plugin = 'wp-scroll-depth/wp-scroll-depth.php';
627 // Check if wp-scroll-depth is active and deactivate to avoid conflicts with the pro scroll tracking feature.
628 if ( is_plugin_active( $plugin ) ) {
629 deactivate_plugins( $plugin );
630 }
631
632 }
633
634 /**
635 * Upgrade routine for version 7.8.0
636 */
637 public function v780_upgrades() {
638
639 if ( monsterinsights_get_ua() ) {
640 // If we have a UA, don't show the first run notice.
641 monsterinsights_update_option( 'monsterinsights_first_run_notice', true );
642
643 // If they are already tracking when they upgrade, mark connected time as now.
644 $over_time = get_option( 'monsterinsights_over_time', array() );
645 if ( empty( $over_time['connected_date'] ) ) {
646 $over_time['connected_date'] = time();
647 update_option( 'monsterinsights_over_time', $over_time, false );
648 }
649 }
650
651 }
652
653 /**
654 * Upgrade routine for version 7.9.0
655 */
656 public function v790_upgrades() {
657
658 // If they are already tracking, don't show the notice.
659 if ( monsterinsights_get_ua() ) {
660 update_option( 'monsterinsights_frontend_tracking_notice_viewed', true );
661
662 // If they are already tracking when they upgrade & not already marked mark connected time as now.
663 // Adding this here again as 7.8.0 upgrade didn't run for all users.
664 $over_time = get_option( 'monsterinsights_over_time', array() );
665 if ( empty( $over_time['connected_date'] ) ) {
666 $over_time['connected_date'] = time();
667 update_option( 'monsterinsights_over_time', $over_time, false );
668 }
669 }
670
671 }
672
673 /**
674 * Upgrade routine for version 8.0.0
675 */
676 public function v7100_upgrades() {
677
678 // Remove exe js and tgz from file downloads tracking.
679 $current_downloads = isset( $this->new_settings['extensions_of_files'] ) ? $this->new_settings['extensions_of_files'] : array();
680
681 if ( ! empty( $current_downloads ) ) {
682 $extensions_to_remove = array(
683 'exe',
684 'js',
685 'tgz'
686 );
687 $extensions_to_add = array(
688 'docx',
689 'pptx',
690 'xlsx',
691 );
692
693 $extensions = explode( ',', $current_downloads );
694 $updated_extensions = array();
695
696 if ( ! empty( $extensions ) && is_array( $extensions ) ) {
697 foreach ( $extensions as $extension ) {
698 if ( ! in_array( $extension, $extensions_to_remove ) ) {
699 $updated_extensions[] = $extension;
700 }
701 }
702 }
703
704 foreach ( $extensions_to_add as $extension_to_add ) {
705 if ( ! in_array( $extension_to_add, $updated_extensions ) ) {
706 $updated_extensions[] = $extension_to_add;
707 }
708 }
709 } else {
710 $updated_extensions = array(
711 'pdf',
712 'doc',
713 'ppt',
714 'xls',
715 'zip',
716 'docx',
717 'pptx',
718 'xlsx',
719 );
720 }
721
722 $updated_extensions = implode( ',', $updated_extensions );
723
724 $this->new_settings['extensions_of_files'] = $updated_extensions;
725
726 }
727
728 /**
729 * Upgrade routine for version 7.11.0
730 */
731 public function v7110_upgrades() {
732
733 if ( empty( $this->new_settings['email_summaries'] ) ) {
734 $admin_email = get_option( 'admin_email' );
735 $admin_email_array = array(
736 array(
737 'email' => $admin_email,
738 ),
739 );
740 $this->new_settings['email_summaries'] = 'on';
741 $this->new_settings['summaries_html_template'] = 'yes';
742 $this->new_settings['summaries_email_addresses'] = $admin_email_array; // Not using wp_json_encode for backwards compatibility.
743 }
744
745 }
746
747 /**
748 * Upgrade routine for version 7.12.0
749 */
750 public function v7120_upgrades() {
751
752 // Make sure the default for automatic updates is reflected correctly in the settings.
753 if ( empty( $this->new_settings['automatic_updates'] ) ) {
754 $this->new_settings['automatic_updates'] = 'none';
755 }
756
757 }
758
759 /**
760 * Upgrade routine for version 7.13.0
761 */
762 public function v7130_upgrades() {
763
764 // Set default values for popular posts.
765 $popular_posts_defaults = array(
766 'popular_posts_inline_theme' => 'alpha',
767 'popular_posts_widget_theme' => 'alpha',
768 'popular_posts_products_theme' => 'alpha',
769 'popular_posts_inline_placement' => 'manual',
770 'popular_posts_widget_theme_columns' => '2',
771 'popular_posts_products_theme_columns' => '2',
772 'popular_posts_widget_count' => '4',
773 'popular_posts_products_count' => '4',
774 'popular_posts_widget_theme_meta_author' => 'on',
775 'popular_posts_widget_theme_meta_date' => 'on',
776 'popular_posts_widget_theme_meta_comments' => 'on',
777 'popular_posts_products_theme_meta_price' => 'on',
778 'popular_posts_products_theme_meta_rating' => 'on',
779 'popular_posts_products_theme_meta_image' => 'on',
780 'popular_posts_inline_after_count' => '150',
781 'popular_posts_inline_multiple_number' => '3',
782 'popular_posts_inline_multiple_distance' => '250',
783 'popular_posts_inline_multiple_min_words' => '100',
784 'popular_posts_inline_post_types' => array( 'post' ),
785 'popular_posts_widget_post_types' => array( 'post' ),
786 );
787
788 foreach ( $popular_posts_defaults as $key => $value ) {
789 if ( empty( $this->new_settings[ $key ] ) ) {
790 $this->new_settings[ $key ] = $value;
791 }
792 }
793
794 // Contextual education cleanup.
795 $option_name = 'monsterinsights_notifications';
796 $notifications = get_option( $option_name, array() );
797 $dismissed_notifications = isset( $notifications['dismissed'] ) ? $notifications['dismissed'] : array();
798
799 if ( is_array( $dismissed_notifications ) && ! empty( $dismissed_notifications ) ) {
800 foreach ( $dismissed_notifications as $key => $dismiss_notification ) {
801 $title = isset( $dismiss_notification['title'] ) ? $dismiss_notification['title'] : '';
802 $content = isset( $dismiss_notification['content'] ) ? $dismiss_notification['content'] : '';
803
804 if ( empty( $title ) || empty( $content ) ) {
805 unset( $dismissed_notifications[ $key ] );
806 }
807 }
808
809 update_option(
810 $option_name,
811 array(
812 'update' => $notifications['update'],
813 'feed' => $notifications['feed'],
814 'events' => $notifications['events'],
815 'dismissed' => $dismissed_notifications,
816 )
817 );
818 }
819 }
820
821 /**
822 * Upgrade routine for version 7.13.1
823 */
824 public function v7131_upgrades() {
825
826 // Delete transient for GA data with wrong expiration date.
827 delete_transient( 'monsterinsights_popular_posts_ga_data' );
828
829 }
830
831 /**
832 * Upgrade routine for version 7.14.0
833 */
834 public function v7140_upgrades() {
835
836 // Clear notification cron events no longer used.
837 $cron = get_option( 'cron' );
838
839 foreach ( $cron as $timestamp => $cron_array ) {
840 if ( ! is_array( $cron_array ) ) {
841 continue;
842 }
843 foreach ( $cron_array as $cron_key => $cron_data ) {
844 if ( 0 === strpos( $cron_key, 'monsterinsights_notification_' ) ) {
845 wp_unschedule_event( $timestamp, $cron_key, array() );
846 }
847 }
848 }
849
850 // Delete existing year in review report option.
851 delete_option( 'monsterinsights_report_data_yearinreview' );
852 }
853
854 /**
855 * Upgrade routine for version 7.15.0
856 */
857 public function v7150_upgrades() {
858 // Enable gtag compatibility mode by default.
859 if ( empty( $this->new_settings['gtagtracker_compatibility_mode'] ) ) {
860 $this->new_settings['gtagtracker_compatibility_mode'] = true;
861 }
862 }
863 }
864