Passed
Branch master (82fe3a)
by Chris
04:08
created
googleanalytics.php 1 patch
Indentation   +596 added lines, -596 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
 // Exit if accessed directly.
41 41
 if ( ! defined( 'ABSPATH' ) ) {
42
-	exit;
42
+  exit;
43 43
 }
44 44
 
45 45
 /**
@@ -53,501 +53,501 @@  discard block
 block discarded – undo
53 53
  */
54 54
 final class MonsterInsights_Lite {
55 55
 
56
-	/**
57
-	 * Holds the class object.
58
-	 *
59
-	 * @since 6.0.0
60
-	 * @access public
61
-	 * @var object Instance of instantiated MonsterInsights class.
62
-	 */
63
-	public static $instance;
64
-
65
-	/**
66
-	 * Plugin version, used for cache-busting of style and script file references.
67
-	 *
68
-	 * @since 6.0.0
69
-	 * @access public
70
-	 * @var string $version Plugin version.
71
-	 */
72
-	public $version = '6.2.3';
73
-
74
-	/**
75
-	 * Plugin file.
76
-	 *
77
-	 * @since 6.0.0
78
-	 * @access public
79
-	 * @var string $file PHP File constant for main file.
80
-	 */
81
-	public $file = __FILE__;
82
-
83
-	/**
84
-	 * The name of the plugin.
85
-	 *
86
-	 * @since 6.0.0
87
-	 * @access public
88
-	 * @var string $plugin_name Plugin name.
89
-	 */
90
-	public $plugin_name = 'MonsterInsights Lite';
91
-
92
-	/**
93
-	 * Unique plugin slug identifier.
94
-	 *
95
-	 * @since 6.0.0
96
-	 * @access public
97
-	 * @var string $plugin_slug Plugin slug.
98
-	 */
99
-	public $plugin_slug = 'monsterinsights-lite';
100
-
101
-	/**
102
-	 * Holds instance of MonsterInsights Admin Notice class.
103
-	 *
104
-	 * @since 6.0.0
105
-	 * @access public
106
-	 * @var MonsterInsights_Admin_Notice $notices Instance of Admin Notice class.
107
-	 */
108
-	public $notices;
109
-
110
-	/**
111
-	 * Holds instance of MonsterInsights License class.
112
-	 *
113
-	 * @since 6.0.0
114
-	 * @access public
115
-	 * @var MonsterInsights_License $license Instance of License class.
116
-	 */
117
-	public $license;
118
-
119
-	/**
120
-	 * Holds instance of MonsterInsights GA class.
121
-	 *
122
-	 * @since 6.0.0
123
-	 * @access public
124
-	 * @var MonsterInsights_GA $ga Instance of GA class.
125
-	 */
126
-	protected $ga;
127
-
128
-	/**
129
-	 * Primary class constructor.
130
-	 *
131
-	 * @since 6.0.0
132
-	 * @access public
133
-	 */
134
-	public function __construct() {
135
-		// We don't use this
136
-	}
137
-
138
-	/**
139
-	 * Returns the singleton instance of the class.
140
-	 *
141
-	 * @access public
142
-	 * @since 6.0.0
143
-	 *
144
-	 * @return object The MonsterInsights_Lite object.
145
-	 */
146
-	public static function get_instance() {
147
-
148
-		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof MonsterInsights_Lite ) ) {
149
-			self::$instance = new MonsterInsights_Lite();
150
-
151
-			global $wp_version;
152
-
153
-			// Detect non-supported WordPress version and return early
154
-			if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) {
155
-				add_action( 'admin_notices', array( self::$instance, 'monsterinsights_wp_notice' ) );
156
-				return;
157
-			}
56
+  /**
57
+   * Holds the class object.
58
+   *
59
+   * @since 6.0.0
60
+   * @access public
61
+   * @var object Instance of instantiated MonsterInsights class.
62
+   */
63
+  public static $instance;
64
+
65
+  /**
66
+   * Plugin version, used for cache-busting of style and script file references.
67
+   *
68
+   * @since 6.0.0
69
+   * @access public
70
+   * @var string $version Plugin version.
71
+   */
72
+  public $version = '6.2.3';
73
+
74
+  /**
75
+   * Plugin file.
76
+   *
77
+   * @since 6.0.0
78
+   * @access public
79
+   * @var string $file PHP File constant for main file.
80
+   */
81
+  public $file = __FILE__;
82
+
83
+  /**
84
+   * The name of the plugin.
85
+   *
86
+   * @since 6.0.0
87
+   * @access public
88
+   * @var string $plugin_name Plugin name.
89
+   */
90
+  public $plugin_name = 'MonsterInsights Lite';
91
+
92
+  /**
93
+   * Unique plugin slug identifier.
94
+   *
95
+   * @since 6.0.0
96
+   * @access public
97
+   * @var string $plugin_slug Plugin slug.
98
+   */
99
+  public $plugin_slug = 'monsterinsights-lite';
100
+
101
+  /**
102
+   * Holds instance of MonsterInsights Admin Notice class.
103
+   *
104
+   * @since 6.0.0
105
+   * @access public
106
+   * @var MonsterInsights_Admin_Notice $notices Instance of Admin Notice class.
107
+   */
108
+  public $notices;
109
+
110
+  /**
111
+   * Holds instance of MonsterInsights License class.
112
+   *
113
+   * @since 6.0.0
114
+   * @access public
115
+   * @var MonsterInsights_License $license Instance of License class.
116
+   */
117
+  public $license;
118
+
119
+  /**
120
+   * Holds instance of MonsterInsights GA class.
121
+   *
122
+   * @since 6.0.0
123
+   * @access public
124
+   * @var MonsterInsights_GA $ga Instance of GA class.
125
+   */
126
+  protected $ga;
127
+
128
+  /**
129
+   * Primary class constructor.
130
+   *
131
+   * @since 6.0.0
132
+   * @access public
133
+   */
134
+  public function __construct() {
135
+    // We don't use this
136
+  }
137
+
138
+  /**
139
+   * Returns the singleton instance of the class.
140
+   *
141
+   * @access public
142
+   * @since 6.0.0
143
+   *
144
+   * @return object The MonsterInsights_Lite object.
145
+   */
146
+  public static function get_instance() {
147
+
148
+    if ( ! isset( self::$instance ) && ! ( self::$instance instanceof MonsterInsights_Lite ) ) {
149
+      self::$instance = new MonsterInsights_Lite();
150
+
151
+      global $wp_version;
152
+
153
+      // Detect non-supported WordPress version and return early
154
+      if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) {
155
+        add_action( 'admin_notices', array( self::$instance, 'monsterinsights_wp_notice' ) );
156
+        return;
157
+      }
158 158
 	
159
-			// Detect Pro version and return early
160
-			if ( class_exists( 'MonsterInsights' ) && defined( 'GAWP_VERSION' ) ) {
161
-				add_action( 'admin_notices', array( self::$instance, 'monsterinsights_pro_notice' ) );
162
-				return;
163
-			}
164
-
165
-			if ( defined( 'GAWP_ECOMMERCE_PATH' ) ) {
166
-				add_action( 'admin_notices', array( self::$instance, 'monsterinsights_old_ecommerce' ) );
167
-			}
159
+      // Detect Pro version and return early
160
+      if ( class_exists( 'MonsterInsights' ) && defined( 'GAWP_VERSION' ) ) {
161
+        add_action( 'admin_notices', array( self::$instance, 'monsterinsights_pro_notice' ) );
162
+        return;
163
+      }
164
+
165
+      if ( defined( 'GAWP_ECOMMERCE_PATH' ) ) {
166
+        add_action( 'admin_notices', array( self::$instance, 'monsterinsights_old_ecommerce' ) );
167
+      }
168 168
 			
169
-			// Define constants
170
-			self::$instance->define_globals();
171
-
172
-			// Load in settings
173
-			self::$instance->load_settings();
174
-
175
-			// Load files
176
-			self::$instance->require_files();
177
-
178
-			// This does the version to version background upgrade routines and initial install
179
-			$mi_version = get_option( 'monsterinsights_current_version', '5.5.3' );
180
-			if ( version_compare( $mi_version, '6.0.11', '<' ) ) {
181
-				monsterinsights_lite_call_install_and_upgrade();
182
-			}
183
-
184
-			if ( is_admin() ) {
185
-				new AM_Notification( 'mi-lite', self::$instance->version );
186
-				new AM_Deactivation_Survey( 'MonsterInsights', basename( __DIR__ ) );
187
-			}
188
-
189
-			// Load the plugin textdomain.
190
-			add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
191
-
192
-			// Load GA for admin, lazyload for frontend
193
-			if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
194
-				self::$instance->ga    		= new MonsterInsights_GA();
195
-			}
196
-
197
-			// Load admin only components.
198
-			if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
199
-				self::$instance->notices    = new MonsterInsights_Notice_Admin();
200
-				self::$instance->license    = new MonsterInsights_License();
201
-				self::$instance->reports 	= new MonsterInsights_Reporting();
202
-				if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
203
-					self::$instance->require_updater();
204
-				} else {
205
-					add_action( 'admin_init', array( self::$instance, 'require_updater' ) );
206
-				}
207
-			}
208
-
209
-			// Run hook to load MonsterInsights addons.
210
-			do_action( 'monsterinsights_load_plugins' ); // the updater class for each addon needs to be instantiated via `monsterinsights_updater`
211
-		}
212
-
213
-		return self::$instance;
214
-
215
-	}
216
-
217
-	/**
218
-	 * Throw error on object clone
219
-	 *
220
-	 * The whole idea of the singleton design pattern is that there is a single
221
-	 * object therefore, we don't want the object to be cloned.
222
-	 *
223
-	 * @since 6.0.0
224
-	 * @access public
225
-	 *
226
-	 * @return void
227
-	 */
228
-	public function __clone() {
229
-		_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
230
-	}
231
-
232
-	/**
233
-	 * Disable unserializing of the class
234
-	 *
235
-	 * Attempting to wakeup an MonsterInsights instance will throw a doing it wrong notice.
236
-	 * 
237
-	 * @since 6.0.0
238
-	 * @access public
239
-	 *
240
-	 * @return void
241
-	 */
242
-	public function __wakeup() {
243
-		_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
244
-	}
245
-
246
-	/**
247
-	 * Magic get function.
248
-	 *
249
-	 * We use this to lazy load certain functionality. Right now used to lazyload
250
-	 * the Google Object for frontend, so it's only loaded if user is using a plugin
251
-	 * that requires it.
252
-	 *
253
-	 * @since 6.0.10
254
-	 * @access public
255
-	 *
256
-	 * @return void
257
-	 */
258
-	public function __get( $key ) {
259
-		if ( $key === 'ga' ) {
260
-			if ( empty( self::$instance->ga ) ) {
261
-				// LazyLoad GA for Frontend
262
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php';
263
-				self::$instance->ga = new MonsterInsights_GA();
264
-			}
265
-			return self::$instance->$key;
266
-		} else {
267
-			return self::$instance->$key;
268
-		}
269
-	}
270
-
271
-	/**
272
-	 * Define MonsterInsights constants.
273
-	 *
274
-	 * This function defines all of the MonsterInsights PHP constants.
275
-	 *
276
-	 * @since 6.0.0
277
-	 * @access public
278
-	 *
279
-	 * @return void
280
-	 */
281
-	public function define_globals() {
282
-
283
-		if ( ! defined( 'MONSTERINSIGHTS_VERSION' ) ) {
284
-			define( 'MONSTERINSIGHTS_VERSION', $this->version );
285
-		}
286
-
287
-		if ( ! defined( 'MONSTERINSIGHTS_LITE_VERSION' ) ) {
288
-			define( 'MONSTERINSIGHTS_LITE_VERSION', MONSTERINSIGHTS_VERSION );
289
-		}
290
-
291
-		if ( ! defined( 'GAWP_VERSION' ) ) {
292
-			define( 'GAWP_VERSION', MONSTERINSIGHTS_VERSION );
293
-		}
294
-
295
-		if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_NAME' ) ) {
296
-			define( 'MONSTERINSIGHTS_PLUGIN_NAME', $this->plugin_name );
297
-		}
298
-
299
-		if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_SLUG' ) ) {
300
-			define( 'MONSTERINSIGHTS_PLUGIN_SLUG', $this->plugin_slug );
301
-		}
302
-
303
-		if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_FILE' ) ) {
304
-			define( 'MONSTERINSIGHTS_PLUGIN_FILE', $this->file );
305
-		}
306
-
307
-		if ( ! defined( 'GAWP_FILE' ) ) {
308
-			define( 'GAWP_FILE', MONSTERINSIGHTS_PLUGIN_FILE );
309
-		}
310
-
311
-		if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_DIR' ) ) {
312
-			define( 'MONSTERINSIGHTS_PLUGIN_DIR', plugin_dir_path( $this->file )  );
313
-		}
314
-
315
-		if ( ! defined( 'GAWP_PATH' ) ) {
316
-			define( 'GAWP_PATH', MONSTERINSIGHTS_PLUGIN_FILE  );
317
-		}
318
-
319
-		if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_URL' ) ) {
320
-			define( 'MONSTERINSIGHTS_PLUGIN_URL', plugin_dir_url( $this->file )  );
321
-		}
322
-
323
-		if ( ! defined( 'GAWP_URL' ) ) {
324
-			define( 'GAWP_URL', MONSTERINSIGHTS_PLUGIN_URL  );
325
-		}
326
-	}	
327
-
328
-	/**
329
-	 * Loads the plugin textdomain for translation.
330
-	 *
331
-	 * @access public
332
-	 * @since 6.0.0
333
-	 *
334
-	 * @return void
335
-	 */
336
-	public function load_plugin_textdomain() {
337
-
338
-		$mi_locale = get_locale();
339
-		if ( function_exists( 'get_user_locale' ) ) {
340
-			$mi_locale = get_user_locale();
341
-		}
342
-
343
-		// Traditional WordPress plugin locale filter.
344
-		$mi_locale  = apply_filters( 'plugin_locale',  $mi_locale, 'google-analytics-for-wordpress' );
345
-		$mi_mofile  = sprintf( '%1$s-%2$s.mo', 'google-analytics-for-wordpress', $mi_locale ); 
169
+      // Define constants
170
+      self::$instance->define_globals();
171
+
172
+      // Load in settings
173
+      self::$instance->load_settings();
174
+
175
+      // Load files
176
+      self::$instance->require_files();
177
+
178
+      // This does the version to version background upgrade routines and initial install
179
+      $mi_version = get_option( 'monsterinsights_current_version', '5.5.3' );
180
+      if ( version_compare( $mi_version, '6.0.11', '<' ) ) {
181
+        monsterinsights_lite_call_install_and_upgrade();
182
+      }
183
+
184
+      if ( is_admin() ) {
185
+        new AM_Notification( 'mi-lite', self::$instance->version );
186
+        new AM_Deactivation_Survey( 'MonsterInsights', basename( __DIR__ ) );
187
+      }
188
+
189
+      // Load the plugin textdomain.
190
+      add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
191
+
192
+      // Load GA for admin, lazyload for frontend
193
+      if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
194
+        self::$instance->ga    		= new MonsterInsights_GA();
195
+      }
196
+
197
+      // Load admin only components.
198
+      if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
199
+        self::$instance->notices    = new MonsterInsights_Notice_Admin();
200
+        self::$instance->license    = new MonsterInsights_License();
201
+        self::$instance->reports 	= new MonsterInsights_Reporting();
202
+        if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
203
+          self::$instance->require_updater();
204
+        } else {
205
+          add_action( 'admin_init', array( self::$instance, 'require_updater' ) );
206
+        }
207
+      }
208
+
209
+      // Run hook to load MonsterInsights addons.
210
+      do_action( 'monsterinsights_load_plugins' ); // the updater class for each addon needs to be instantiated via `monsterinsights_updater`
211
+    }
212
+
213
+    return self::$instance;
214
+
215
+  }
216
+
217
+  /**
218
+   * Throw error on object clone
219
+   *
220
+   * The whole idea of the singleton design pattern is that there is a single
221
+   * object therefore, we don't want the object to be cloned.
222
+   *
223
+   * @since 6.0.0
224
+   * @access public
225
+   *
226
+   * @return void
227
+   */
228
+  public function __clone() {
229
+    _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
230
+  }
231
+
232
+  /**
233
+   * Disable unserializing of the class
234
+   *
235
+   * Attempting to wakeup an MonsterInsights instance will throw a doing it wrong notice.
236
+   * 
237
+   * @since 6.0.0
238
+   * @access public
239
+   *
240
+   * @return void
241
+   */
242
+  public function __wakeup() {
243
+    _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
244
+  }
245
+
246
+  /**
247
+   * Magic get function.
248
+   *
249
+   * We use this to lazy load certain functionality. Right now used to lazyload
250
+   * the Google Object for frontend, so it's only loaded if user is using a plugin
251
+   * that requires it.
252
+   *
253
+   * @since 6.0.10
254
+   * @access public
255
+   *
256
+   * @return void
257
+   */
258
+  public function __get( $key ) {
259
+    if ( $key === 'ga' ) {
260
+      if ( empty( self::$instance->ga ) ) {
261
+        // LazyLoad GA for Frontend
262
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php';
263
+        self::$instance->ga = new MonsterInsights_GA();
264
+      }
265
+      return self::$instance->$key;
266
+    } else {
267
+      return self::$instance->$key;
268
+    }
269
+  }
270
+
271
+  /**
272
+   * Define MonsterInsights constants.
273
+   *
274
+   * This function defines all of the MonsterInsights PHP constants.
275
+   *
276
+   * @since 6.0.0
277
+   * @access public
278
+   *
279
+   * @return void
280
+   */
281
+  public function define_globals() {
282
+
283
+    if ( ! defined( 'MONSTERINSIGHTS_VERSION' ) ) {
284
+      define( 'MONSTERINSIGHTS_VERSION', $this->version );
285
+    }
286
+
287
+    if ( ! defined( 'MONSTERINSIGHTS_LITE_VERSION' ) ) {
288
+      define( 'MONSTERINSIGHTS_LITE_VERSION', MONSTERINSIGHTS_VERSION );
289
+    }
290
+
291
+    if ( ! defined( 'GAWP_VERSION' ) ) {
292
+      define( 'GAWP_VERSION', MONSTERINSIGHTS_VERSION );
293
+    }
294
+
295
+    if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_NAME' ) ) {
296
+      define( 'MONSTERINSIGHTS_PLUGIN_NAME', $this->plugin_name );
297
+    }
298
+
299
+    if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_SLUG' ) ) {
300
+      define( 'MONSTERINSIGHTS_PLUGIN_SLUG', $this->plugin_slug );
301
+    }
302
+
303
+    if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_FILE' ) ) {
304
+      define( 'MONSTERINSIGHTS_PLUGIN_FILE', $this->file );
305
+    }
306
+
307
+    if ( ! defined( 'GAWP_FILE' ) ) {
308
+      define( 'GAWP_FILE', MONSTERINSIGHTS_PLUGIN_FILE );
309
+    }
310
+
311
+    if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_DIR' ) ) {
312
+      define( 'MONSTERINSIGHTS_PLUGIN_DIR', plugin_dir_path( $this->file )  );
313
+    }
314
+
315
+    if ( ! defined( 'GAWP_PATH' ) ) {
316
+      define( 'GAWP_PATH', MONSTERINSIGHTS_PLUGIN_FILE  );
317
+    }
318
+
319
+    if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_URL' ) ) {
320
+      define( 'MONSTERINSIGHTS_PLUGIN_URL', plugin_dir_url( $this->file )  );
321
+    }
322
+
323
+    if ( ! defined( 'GAWP_URL' ) ) {
324
+      define( 'GAWP_URL', MONSTERINSIGHTS_PLUGIN_URL  );
325
+    }
326
+  }	
327
+
328
+  /**
329
+   * Loads the plugin textdomain for translation.
330
+   *
331
+   * @access public
332
+   * @since 6.0.0
333
+   *
334
+   * @return void
335
+   */
336
+  public function load_plugin_textdomain() {
337
+
338
+    $mi_locale = get_locale();
339
+    if ( function_exists( 'get_user_locale' ) ) {
340
+      $mi_locale = get_user_locale();
341
+    }
342
+
343
+    // Traditional WordPress plugin locale filter.
344
+    $mi_locale  = apply_filters( 'plugin_locale',  $mi_locale, 'google-analytics-for-wordpress' );
345
+    $mi_mofile  = sprintf( '%1$s-%2$s.mo', 'google-analytics-for-wordpress', $mi_locale ); 
346 346
 	
347
-		// Look for wp-content/languages/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo
348
-		$mi_mofile1 = WP_LANG_DIR . '/google-analytics-for-wordpress/' . $mi_mofile;
349
-
350
-		// Look in wp-content/languages/plugins/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo
351
-		$mi_mofile2 = WP_LANG_DIR . '/plugins/google-analytics-for-wordpress/' . $mi_mofile;
352
-
353
-		// Look in wp-content/languages/plugins/google-analytics-for-wordpress-{lang}_{country}.mo
354
-		$mi_mofile3 = WP_LANG_DIR . '/plugins/' . $mi_mofile;
355
-
356
-		// Look in wp-content/plugins/google-analytics-for-wordpress/languages/google-analytics-for-wordpress-{lang}_{country}.mo
357
-		$mi_mofile4 = dirname( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ) . '/languages/';
358
-		$mi_mofile4 = apply_filters( 'monsterinsights_lite_languages_directory', $mi_mofile4 );
359
-
360
-		if ( file_exists( $mi_mofile1 ) ) {
361
-			load_textdomain( 'google-analytics-for-wordpress', $mi_mofile1 );
362
-		} elseif ( file_exists( $mi_mofile2 ) ) {
363
-			load_textdomain( 'google-analytics-for-wordpress', $mi_mofile2 );
364
-		} elseif ( file_exists( $mi_mofile3 ) ) {
365
-			load_textdomain( 'google-analytics-for-wordpress', $mi_mofile3 );
366
-		} else {
367
-			load_plugin_textdomain( 'google-analytics-for-wordpress', false, $mi_mofile4 );
368
-		}
369
-
370
-	}
371
-
372
-
373
-	/**
374
-	 * Output notice to update eCommerce
375
-	 *
376
-	 * @access public
377
-	 * @since 6.0.0
378
-	 *
379
-	 * @return 	void
380
-	 */
381
-	public function monsterinsights_old_ecommerce() {
382
-		?>
347
+    // Look for wp-content/languages/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo
348
+    $mi_mofile1 = WP_LANG_DIR . '/google-analytics-for-wordpress/' . $mi_mofile;
349
+
350
+    // Look in wp-content/languages/plugins/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo
351
+    $mi_mofile2 = WP_LANG_DIR . '/plugins/google-analytics-for-wordpress/' . $mi_mofile;
352
+
353
+    // Look in wp-content/languages/plugins/google-analytics-for-wordpress-{lang}_{country}.mo
354
+    $mi_mofile3 = WP_LANG_DIR . '/plugins/' . $mi_mofile;
355
+
356
+    // Look in wp-content/plugins/google-analytics-for-wordpress/languages/google-analytics-for-wordpress-{lang}_{country}.mo
357
+    $mi_mofile4 = dirname( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ) . '/languages/';
358
+    $mi_mofile4 = apply_filters( 'monsterinsights_lite_languages_directory', $mi_mofile4 );
359
+
360
+    if ( file_exists( $mi_mofile1 ) ) {
361
+      load_textdomain( 'google-analytics-for-wordpress', $mi_mofile1 );
362
+    } elseif ( file_exists( $mi_mofile2 ) ) {
363
+      load_textdomain( 'google-analytics-for-wordpress', $mi_mofile2 );
364
+    } elseif ( file_exists( $mi_mofile3 ) ) {
365
+      load_textdomain( 'google-analytics-for-wordpress', $mi_mofile3 );
366
+    } else {
367
+      load_plugin_textdomain( 'google-analytics-for-wordpress', false, $mi_mofile4 );
368
+    }
369
+
370
+  }
371
+
372
+
373
+  /**
374
+   * Output notice to update eCommerce
375
+   *
376
+   * @access public
377
+   * @since 6.0.0
378
+   *
379
+   * @return 	void
380
+   */
381
+  public function monsterinsights_old_ecommerce() {
382
+    ?>
383 383
 		<div class="error">
384 384
 			<p><?php echo __( 'The version of MonsterInsights eCommerce addon you have is not compatible with the version of MonsterInsights installed. Please update the eCommerce addon as soon as possible', 'ga-premium' ); ?></p>
385 385
 		</div>
386 386
 		<?php
387 387
 
388
-	}
389
-
390
-	/**
391
-	 * Output a nag notice if the user has an out of date WP version installed
392
-	 *
393
-	 * @access public
394
-	 * @since 6.0.0
395
-	 *
396
-	 * @return 	void
397
-	 */
398
-	public function monsterinsights_wp_notice() {
399
-		$url = admin_url( 'plugins.php' );
400
-		// Check for MS dashboard
401
-		if( is_network_admin() ) {
402
-			$url = network_admin_url( 'plugins.php' );
403
-		}
404
-		?>
388
+  }
389
+
390
+  /**
391
+   * Output a nag notice if the user has an out of date WP version installed
392
+   *
393
+   * @access public
394
+   * @since 6.0.0
395
+   *
396
+   * @return 	void
397
+   */
398
+  public function monsterinsights_wp_notice() {
399
+    $url = admin_url( 'plugins.php' );
400
+    // Check for MS dashboard
401
+    if( is_network_admin() ) {
402
+      $url = network_admin_url( 'plugins.php' );
403
+    }
404
+    ?>
405 405
 		<div class="error">
406 406
 			<p><?php echo sprintf( esc_html__( 'Sorry, but your version of WordPress does not meet MonsterInsights\'s required version of %1$s3.8%2$s to run properly. The plugin not been activated. %3$sClick here to return to the Dashboard%4$s.', 'google-analytics-for-wordpress' ), '<strong>', '</strong>', '<a href="' . $url . '">', '</a>' ); ?></p>
407 407
 		</div>
408 408
 		<?php
409
-	}
409
+  }
410 410
 	
411
-	/**
412
-	 * Output a nag notice if the user has both Lite and Pro activated
413
-	 *
414
-	 * @access public
415
-	 * @since 6.0.0
416
-	 *
417
-	 * @return 	void
418
-	 */
419
-	public function monsterinsights_pro_notice() {
420
-		$url = admin_url( 'plugins.php' );
421
-		// Check for MS dashboard
422
-		if( is_network_admin() ) {
423
-			$url = network_admin_url( 'plugins.php' );
424
-		}
425
-		?>
411
+  /**
412
+   * Output a nag notice if the user has both Lite and Pro activated
413
+   *
414
+   * @access public
415
+   * @since 6.0.0
416
+   *
417
+   * @return 	void
418
+   */
419
+  public function monsterinsights_pro_notice() {
420
+    $url = admin_url( 'plugins.php' );
421
+    // Check for MS dashboard
422
+    if( is_network_admin() ) {
423
+      $url = network_admin_url( 'plugins.php' );
424
+    }
425
+    ?>
426 426
 		<div class="error">
427 427
 			<p><?php echo sprintf( esc_html__( 'Please %1$uninstall%2$s the MonsterInsights Lite Plugin. Your Pro version of MonsterInsights may not work as expected until the Lite version is uninstalled.', 'google-analytics-for-wordpress' ), '<a href="' . $url . '">', '</a>' ); ?></p>
428 428
 		</div>
429 429
 		<?php
430 430
 
431
-	}
432
-
433
-	/**
434
-	 * Loads MonsterInsights settings
435
-	 *
436
-	 * Adds the items to the base object, and adds the helper functions.
437
-	 *
438
-	 * @since 6.0.0
439
-	 * @access public
440
-	 * 
441
-	 * @return void
442
-	 */
443
-	public function load_settings() {
444
-		global $monsterinsights_settings;
445
-		require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/options.php';
446
-		require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/helpers.php';
447
-		require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/deprecated.php';
448
-		$monsterinsights_settings  = monsterinsights_get_options();
449
-	}
450
-
451
-	/**
452
-	 * Loads all files into scope.
453
-	 *
454
-	 * @access public
455
-	 * @since 6.0.0
456
-	 *
457
-	 * @return 	void
458
-	 */
459
-	public function require_files() {
460
-
461
-		if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
462
-
463
-			// Lite and Pro files
464
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-notification.php';
465
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-deactivation-survey.php';
466
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/ajax.php';
467
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/admin.php';
468
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/common.php';
469
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notice.php';
470
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/capabilities.php';
471
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/license.php';
472
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/autoupdate.php';
473
-
474
-			// Pages
475
-				// Multisite
476
-					require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/network-settings.php';
477
-
478
-				// Single Site
479
-					require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/dashboard.php';
480
-					require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/settings.php';
481
-					require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/tools.php';
482
-					require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/reports.php';
431
+  }
432
+
433
+  /**
434
+   * Loads MonsterInsights settings
435
+   *
436
+   * Adds the items to the base object, and adds the helper functions.
437
+   *
438
+   * @since 6.0.0
439
+   * @access public
440
+   * 
441
+   * @return void
442
+   */
443
+  public function load_settings() {
444
+    global $monsterinsights_settings;
445
+    require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/options.php';
446
+    require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/helpers.php';
447
+    require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/deprecated.php';
448
+    $monsterinsights_settings  = monsterinsights_get_options();
449
+  }
450
+
451
+  /**
452
+   * Loads all files into scope.
453
+   *
454
+   * @access public
455
+   * @since 6.0.0
456
+   *
457
+   * @return 	void
458
+   */
459
+  public function require_files() {
460
+
461
+    if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
462
+
463
+      // Lite and Pro files
464
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-notification.php';
465
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-deactivation-survey.php';
466
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/ajax.php';
467
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/admin.php';
468
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/common.php';
469
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notice.php';
470
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/capabilities.php';
471
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/license.php';
472
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/autoupdate.php';
473
+
474
+      // Pages
475
+        // Multisite
476
+          require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/network-settings.php';
477
+
478
+        // Single Site
479
+          require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/dashboard.php';
480
+          require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/settings.php';
481
+          require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/tools.php';
482
+          require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/reports.php';
483 483
 				
484
-				// Both	
485
-					require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/addons.php';
486
-
487
-			// Settings Tabs
488
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-general.php';
489
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-tracking.php';
490
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-status.php';
491
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-support.php';
484
+        // Both	
485
+          require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/addons.php';
486
+
487
+      // Settings Tabs
488
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-general.php';
489
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-tracking.php';
490
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-status.php';
491
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-support.php';
492 492
 			
493
-			// Register Settings + Settings API
494
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/settings-api.php';
495
-				require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/register-settings.php';	
496
-
497
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reporting.php';
498
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/abstract-report.php';
499
-		}
500
-
501
-		// Load Google Config
502
-		require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/google.php';
503
-
504
-		// Lazy Load for Frontend. Load for Admin.
505
-		if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
506
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php';
507
-		}
508
-
509
-		if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
510
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/googleauth.php';
511
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/addons.php';
512
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/tools.php';
513
-			//require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/tab-support.php';
493
+      // Register Settings + Settings API
494
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/settings-api.php';
495
+        require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/register-settings.php';	
496
+
497
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reporting.php';
498
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/abstract-report.php';
499
+    }
500
+
501
+    // Load Google Config
502
+    require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/google.php';
503
+
504
+    // Lazy Load for Frontend. Load for Admin.
505
+    if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
506
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php';
507
+    }
508
+
509
+    if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
510
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/googleauth.php';
511
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/addons.php';
512
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/tools.php';
513
+      //require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/tab-support.php';
514 514
 			
515
-			// Late loading classes (self instantiating)
516
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/overview.php';
517
-			require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/tracking.php';
518
-		}
519
-
520
-		require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/frontend.php';
521
-		require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/measurement-protocol.php';
522
-	}
523
-
524
-	/**
525
-	 * Loads all updater related files and functions into scope.
526
-	 *
527
-	 * @access public
528
-	 * @since 6.0.0
529
-	 *
530
-	 * @return null Return early if the license key is not set or there are key errors.
531
-	 */
532
-	public function require_updater() {
533
-
534
-		// Retrieve the license key. If it is not set, return early.
535
-		$key = monsterinsights_get_license_key();
536
-		if ( ! $key ) {
537
-			return;
538
-		}
539
-
540
-		// If there are any errors with the key itself, return early.
541
-		if ( monsterinsights_get_license_key_errors() ) {
542
-			return;
543
-		}
544
-
545
-		// Load the updater class.
546
-		require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/updater.php';
547
-
548
-		// Fire a hook for Addons to register their updater since we know the key is present.
549
-		do_action( 'monsterinsights_updater', $key );
550
-	}
515
+      // Late loading classes (self instantiating)
516
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/overview.php';
517
+      require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/tracking.php';
518
+    }
519
+
520
+    require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/frontend.php';
521
+    require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/measurement-protocol.php';
522
+  }
523
+
524
+  /**
525
+   * Loads all updater related files and functions into scope.
526
+   *
527
+   * @access public
528
+   * @since 6.0.0
529
+   *
530
+   * @return null Return early if the license key is not set or there are key errors.
531
+   */
532
+  public function require_updater() {
533
+
534
+    // Retrieve the license key. If it is not set, return early.
535
+    $key = monsterinsights_get_license_key();
536
+    if ( ! $key ) {
537
+      return;
538
+    }
539
+
540
+    // If there are any errors with the key itself, return early.
541
+    if ( monsterinsights_get_license_key_errors() ) {
542
+      return;
543
+    }
544
+
545
+    // Load the updater class.
546
+    require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/updater.php';
547
+
548
+    // Fire a hook for Addons to register their updater since we know the key is present.
549
+    do_action( 'monsterinsights_updater', $key );
550
+  }
551 551
 }
552 552
 
553 553
 /**
@@ -564,23 +564,23 @@  discard block
 block discarded – undo
564 564
  */
565 565
 function monsterinsights_lite_activation_hook( $network_wide ) {
566 566
 
567
-	global $wp_version;
567
+  global $wp_version;
568 568
 	
569
-	$url = admin_url( 'plugins.php' );
570
-	// Check for MS dashboard
571
-	if ( is_network_admin() ) {
572
-		$url = network_admin_url( 'plugins.php' );
573
-	}
569
+  $url = admin_url( 'plugins.php' );
570
+  // Check for MS dashboard
571
+  if ( is_network_admin() ) {
572
+    $url = network_admin_url( 'plugins.php' );
573
+  }
574 574
 	
575
-	if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) {
576
-		deactivate_plugins( plugin_basename( __FILE__ ) );
577
-		wp_die( sprintf( esc_html__( 'Sorry, but your version of WordPress does not meet MonsterInsight\'s required version of %1$s3.8%2$s to run properly. The plugin not been activated. %3$sClick here to return to the Dashboard%4$s.', 'google-analytics-by-wordpress' ), '<strong>', '</strong>', '<a href="' . $url . '">', '</a>' ) );
578
-	}
575
+  if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) {
576
+    deactivate_plugins( plugin_basename( __FILE__ ) );
577
+    wp_die( sprintf( esc_html__( 'Sorry, but your version of WordPress does not meet MonsterInsight\'s required version of %1$s3.8%2$s to run properly. The plugin not been activated. %3$sClick here to return to the Dashboard%4$s.', 'google-analytics-by-wordpress' ), '<strong>', '</strong>', '<a href="' . $url . '">', '</a>' ) );
578
+  }
579 579
 	
580
-	if ( class_exists( 'MonsterInsights' ) ) {
581
-		deactivate_plugins( plugin_basename( __FILE__ ) );
582
-		wp_die( sprintf( esc_html__( 'Please uninstall and remove MonsterInsights Pro before activating MonsterInsights Lite. The Lite version has not been activated. %1$sClick here to return to the Dashboard%2$s.', 'google-analytics-by-wordpress' ), '<a href="' . $url . '">', '</a>' ) );
583
-	}
580
+  if ( class_exists( 'MonsterInsights' ) ) {
581
+    deactivate_plugins( plugin_basename( __FILE__ ) );
582
+    wp_die( sprintf( esc_html__( 'Please uninstall and remove MonsterInsights Pro before activating MonsterInsights Lite. The Lite version has not been activated. %1$sClick here to return to the Dashboard%2$s.', 'google-analytics-by-wordpress' ), '<a href="' . $url . '">', '</a>' ) );
583
+  }
584 584
 }
585 585
 register_activation_hook( __FILE__, 'monsterinsights_lite_activation_hook' );
586 586
 
@@ -593,31 +593,31 @@  discard block
 block discarded – undo
593 593
  * @return 	void
594 594
  */
595 595
 function monsterinsights_lite_deactivation_hook( $network_wide ) {
596
-	// Note, if both MI Pro and Lite are active, this is an MI Pro instance
597
-	// Therefore MI Lite can only use functions of the instance common to
598
-	// both plugins. If it needs to be pro specific, then include a file that
599
-	// has that method.
600
-	$instance = MonsterInsights();
596
+  // Note, if both MI Pro and Lite are active, this is an MI Pro instance
597
+  // Therefore MI Lite can only use functions of the instance common to
598
+  // both plugins. If it needs to be pro specific, then include a file that
599
+  // has that method.
600
+  $instance = MonsterInsights();
601 601
 	
602
-	if ( is_multisite() && $network_wide ) {
603
-		$site_list = get_sites();
604
-		$options = array(
605
-			'cron_failed',
606
-			'cron_last_run',
607
-		);
608
-
609
-		foreach ( (array) $site_list as $site ) {
610
-			switch_to_blog( $site->blog_id );
611
-				monsterinsights_delete_options( $options );
612
-			restore_current_blog();
613
-		}
614
-	} else {
615
-		$options = array(
616
-			'cron_failed',
617
-			'cron_last_run',
618
-		);
619
-		monsterinsights_delete_options( $options );
620
-	}
602
+  if ( is_multisite() && $network_wide ) {
603
+    $site_list = get_sites();
604
+    $options = array(
605
+      'cron_failed',
606
+      'cron_last_run',
607
+    );
608
+
609
+    foreach ( (array) $site_list as $site ) {
610
+      switch_to_blog( $site->blog_id );
611
+        monsterinsights_delete_options( $options );
612
+      restore_current_blog();
613
+    }
614
+  } else {
615
+    $options = array(
616
+      'cron_failed',
617
+      'cron_last_run',
618
+    );
619
+    monsterinsights_delete_options( $options );
620
+  }
621 621
 }
622 622
 register_deactivation_hook( __FILE__, 'monsterinsights_lite_deactivation_hook' );
623 623
 
@@ -630,55 +630,55 @@  discard block
 block discarded – undo
630 630
  * @return 	void
631 631
  */
632 632
 function monsterinsights_lite_uninstall_hook( $network_wide ) {
633
-	wp_cache_flush();
634
-	$instance = MonsterInsights();
635
-
636
-	// Note, if both MI Pro and Lite are active, this is an MI Pro instance
637
-	// Therefore MI Lite can only use functions of the instance common to
638
-	// both plugins. If it needs to be pro specific, then include a file that
639
-	// has that method.
640
-	if ( is_multisite() && $network_wide ) {
641
-		$site_list = get_sites();
642
-
643
-		$options = array(
644
-			'analytics_profile_code',
645
-			'analytics_profile',
646
-			'analytics_profile_name',
647
-			'analytics_name',
648
-			'oauth_version',
649
-			'cron_failed',
650
-			'cron_last_run',
651
-		);
652
-
653
-		foreach ( (array) $site_list as $site ) {
654
-			switch_to_blog( $site->blog_id );
655
-			monsterinsights_delete_options( $options );
656
-			delete_option( 'monsterinsights_lite_access_token' );
657
-			delete_option( 'monsterinsights_lite_refresh_token' );
658
-
659
-			// Destroy the data
660
-			$instance->reports->delete_aggregate_data();			
661
-			restore_current_blog();
662
-		}
663
-	} else {
664
-		$options = array(
665
-			'analytics_profile_code',
666
-			'analytics_profile',
667
-			'analytics_profile_name',
668
-			'analytics_name',
669
-			'oauth_version',
670
-			'cron_failed',
671
-			'cron_last_run',
672
-		);
673
-		monsterinsights_delete_options( $options );
674
-		delete_option( 'monsterinsights_lite_access_token' );
675
-		delete_option( 'monsterinsights_lite_refresh_token' );
676
-
677
-		// Destroy the data
678
-		if ( isset( $instance->reports ) && method_exists( $instance->reports,'delete_aggregate_data' ) ) {
679
-			$instance->reports->delete_aggregate_data();
680
-		}
681
-	}
633
+  wp_cache_flush();
634
+  $instance = MonsterInsights();
635
+
636
+  // Note, if both MI Pro and Lite are active, this is an MI Pro instance
637
+  // Therefore MI Lite can only use functions of the instance common to
638
+  // both plugins. If it needs to be pro specific, then include a file that
639
+  // has that method.
640
+  if ( is_multisite() && $network_wide ) {
641
+    $site_list = get_sites();
642
+
643
+    $options = array(
644
+      'analytics_profile_code',
645
+      'analytics_profile',
646
+      'analytics_profile_name',
647
+      'analytics_name',
648
+      'oauth_version',
649
+      'cron_failed',
650
+      'cron_last_run',
651
+    );
652
+
653
+    foreach ( (array) $site_list as $site ) {
654
+      switch_to_blog( $site->blog_id );
655
+      monsterinsights_delete_options( $options );
656
+      delete_option( 'monsterinsights_lite_access_token' );
657
+      delete_option( 'monsterinsights_lite_refresh_token' );
658
+
659
+      // Destroy the data
660
+      $instance->reports->delete_aggregate_data();			
661
+      restore_current_blog();
662
+    }
663
+  } else {
664
+    $options = array(
665
+      'analytics_profile_code',
666
+      'analytics_profile',
667
+      'analytics_profile_name',
668
+      'analytics_name',
669
+      'oauth_version',
670
+      'cron_failed',
671
+      'cron_last_run',
672
+    );
673
+    monsterinsights_delete_options( $options );
674
+    delete_option( 'monsterinsights_lite_access_token' );
675
+    delete_option( 'monsterinsights_lite_refresh_token' );
676
+
677
+    // Destroy the data
678
+    if ( isset( $instance->reports ) && method_exists( $instance->reports,'delete_aggregate_data' ) ) {
679
+      $instance->reports->delete_aggregate_data();
680
+    }
681
+  }
682 682
 
683 683
 }
684 684
 register_uninstall_hook( __FILE__, 'monsterinsights_lite_uninstall_hook' );
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
  * @return MonsterInsights_Lite The singleton MonsterInsights_Lite instance.
700 700
  */
701 701
 function MonsterInsights_Lite() {
702
-	return MonsterInsights_Lite::get_instance();
702
+  return MonsterInsights_Lite::get_instance();
703 703
 }
704 704
 
705 705
 /**
@@ -719,34 +719,34 @@  discard block
 block discarded – undo
719 719
  * @return void
720 720
  */
721 721
 function monsterinsights_lite_install_and_upgrade() {
722
-	global $wp_version;
723
-
724
-	// If the WordPress site doesn't meet the correct WP version requirements, don't activate MonsterInsights
725
-	if ( version_compare( $wp_version, '3.8', '<' ) ) {
726
-		if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
727
-			return;
728
-		}
729
-	}
730
-
731
-	// Don't run if MI Pro is installed
732
-	if ( class_exists( 'MonsterInsights' ) ) {
733
-		if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
734
-			return;
735
-		}
736
-	}
737
-
738
-
739
-	// Load settings and globals (so we can use/set them during the upgrade process)
740
-	MonsterInsights_Lite()->define_globals();
741
-	MonsterInsights_Lite()->load_settings();
742
-
743
-	// Load upgrade file
744
-	require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/install.php';
745
-	require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/install.php'; // Lite only install stuff
746
-
747
-	// Run the MonsterInsights upgrade routines
748
-	$updates = new MonsterInsights_Install();
749
-	$updates->init();
722
+  global $wp_version;
723
+
724
+  // If the WordPress site doesn't meet the correct WP version requirements, don't activate MonsterInsights
725
+  if ( version_compare( $wp_version, '3.8', '<' ) ) {
726
+    if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
727
+      return;
728
+    }
729
+  }
730
+
731
+  // Don't run if MI Pro is installed
732
+  if ( class_exists( 'MonsterInsights' ) ) {
733
+    if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
734
+      return;
735
+    }
736
+  }
737
+
738
+
739
+  // Load settings and globals (so we can use/set them during the upgrade process)
740
+  MonsterInsights_Lite()->define_globals();
741
+  MonsterInsights_Lite()->load_settings();
742
+
743
+  // Load upgrade file
744
+  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/install.php';
745
+  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/install.php'; // Lite only install stuff
746
+
747
+  // Run the MonsterInsights upgrade routines
748
+  $updates = new MonsterInsights_Install();
749
+  $updates->init();
750 750
 }
751 751
 
752 752
 /**
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
  * @return void
765 765
  */
766 766
 function monsterinsights_lite_call_install_and_upgrade(){
767
-	add_action( 'wp_loaded', 'monsterinsights_lite_install_and_upgrade' );
767
+  add_action( 'wp_loaded', 'monsterinsights_lite_install_and_upgrade' );
768 768
 }
769 769
 
770 770
 /**
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
  * @return MonsterInsights The singleton MonsterInsights instance.
792 792
  */
793 793
 if ( ! function_exists( 'MonsterInsights' ) ) {
794
-	function MonsterInsights() {
795
-		return ( class_exists( 'MonsterInsights' ) ? MonsterInsights_Pro() : MonsterInsights_Lite() );
796
-	}
797
-	add_action( 'plugins_loaded', 'MonsterInsights' );
794
+  function MonsterInsights() {
795
+    return ( class_exists( 'MonsterInsights' ) ? MonsterInsights_Pro() : MonsterInsights_Lite() );
796
+  }
797
+  add_action( 'plugins_loaded', 'MonsterInsights' );
798 798
 }
799 799
\ No newline at end of file
Please login to merge, or discard this patch.
includes/deprecated.php 1 patch
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 // Exit if accessed directly
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+  exit;
19 19
 }
20 20
 
21 21
 /**
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
  * @param string $message     Optional. A message regarding the change. Default null.
40 40
  */
41 41
 function _monsterinsights_apply_filters_deprecated( $tag, $args, $version, $message = null ) {
42
-		if ( ! has_filter( $tag ) ) {
43
-				return $args[0];
44
-		}
42
+    if ( ! has_filter( $tag ) ) {
43
+        return $args[0];
44
+    }
45 45
 
46
-		_monsterinsights_deprecated_hook( $tag, $version, $message );
46
+    _monsterinsights_deprecated_hook( $tag, $version, $message );
47 47
 
48
-		return apply_filters_ref_array( $tag, $args );
48
+    return apply_filters_ref_array( $tag, $args );
49 49
 }
50 50
 
51 51
 /**
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
  * @param string $message     Optional. A message regarding the change.
70 70
  */
71 71
 function _monsterinsights_do_action_deprecated( $tag, $args, $version, $message = null ) {
72
-		if ( ! has_action( $tag ) ) {
73
-				return;
74
-		}
72
+    if ( ! has_action( $tag ) ) {
73
+        return;
74
+    }
75 75
 
76
-		_monsterinsights_deprecated_hook( $tag, $version, $message );
76
+    _monsterinsights_deprecated_hook( $tag, $version, $message );
77 77
 
78
-		do_action_ref_array( $tag, $args );
78
+    do_action_ref_array( $tag, $args );
79 79
 }
80 80
 
81 81
 /**
@@ -102,29 +102,29 @@  discard block
 block discarded – undo
102 102
  * @param string $message     Optional. A message regarding the change.
103 103
  */
104 104
 function _monsterinsights_deprecated_hook( $hook, $version, $message = null ) {
105
-	/**
106
-	 * Fires when a deprecated hook is called.
107
-	 *
108
-	 * @since 6.0.0
109
-	 *
110
-	 * @param string $hook        The hook that was called.
111
-	 * @param string $version     The version of MonsterInsights that deprecated the hook used.
112
-	 * @param string $message     A message regarding the change.
113
-	 */
114
-	do_action( 'deprecated_hook_run', $hook, $version, $message );
105
+  /**
106
+   * Fires when a deprecated hook is called.
107
+   *
108
+   * @since 6.0.0
109
+   *
110
+   * @param string $hook        The hook that was called.
111
+   * @param string $version     The version of MonsterInsights that deprecated the hook used.
112
+   * @param string $message     A message regarding the change.
113
+   */
114
+  do_action( 'deprecated_hook_run', $hook, $version, $message );
115 115
  
116
-	/**
117
-	 * Filters whether to trigger deprecated hook errors.
118
-	 *
119
-	 * @since 6.0.0
120
-	 *
121
-	 * @param bool $trigger Whether to trigger deprecated hook errors. Requires
122
-	 *                      `WP_DEBUG` to be defined true.
123
-	 */
124
-	if ( ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) || monsterinsights_is_debug_mode() ) {
125
-		$message = empty( $message ) ? '' : ' ' . $message;
126
-		trigger_error( sprintf( esc_html__( '%1$s is %3$sdeprecated%4$s since MonsterInsights version %2$s!', 'google-analytics-for-wordpress' ), $hook, $version, '<strong>', '</strong>' ) . esc_html ( $message ) );
127
-	}
116
+  /**
117
+   * Filters whether to trigger deprecated hook errors.
118
+   *
119
+   * @since 6.0.0
120
+   *
121
+   * @param bool $trigger Whether to trigger deprecated hook errors. Requires
122
+   *                      `WP_DEBUG` to be defined true.
123
+   */
124
+  if ( ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) || monsterinsights_is_debug_mode() ) {
125
+    $message = empty( $message ) ? '' : ' ' . $message;
126
+    trigger_error( sprintf( esc_html__( '%1$s is %3$sdeprecated%4$s since MonsterInsights version %2$s!', 'google-analytics-for-wordpress' ), $hook, $version, '<strong>', '</strong>' ) . esc_html ( $message ) );
127
+  }
128 128
 }
129 129
 
130 130
 /**
@@ -153,33 +153,33 @@  discard block
 block discarded – undo
153 153
  */
154 154
 function _monsterinsights_deprecated_function( $function, $version, $backtrace = null ) {
155 155
 
156
-	/**
157
-	 * Deprecated Function Action.
158
-	 *
159
-	 * Allow plugin run an action on the use of a 
160
-	 * deprecated function. This could be used to
161
-	 * feed into an error logging program or file.
162
-	 *
163
-	 * @since 6.0.0
164
-	 * 
165
-	 * @param string  $function    The function that was called.
166
-	 * @param string  $version     The version of WordPress that deprecated the function.
167
-	 * @param array   $backtrace   Optional. Contains stack backtrace of deprecated function.
168
-	 */	
169
-	do_action( 'deprecated_function_run', $function, $version, $backtrace );
156
+  /**
157
+   * Deprecated Function Action.
158
+   *
159
+   * Allow plugin run an action on the use of a 
160
+   * deprecated function. This could be used to
161
+   * feed into an error logging program or file.
162
+   *
163
+   * @since 6.0.0
164
+   * 
165
+   * @param string  $function    The function that was called.
166
+   * @param string  $version     The version of WordPress that deprecated the function.
167
+   * @param array   $backtrace   Optional. Contains stack backtrace of deprecated function.
168
+   */	
169
+  do_action( 'deprecated_function_run', $function, $version, $backtrace );
170 170
 
171
-	/**
172
-	 * Filters whether to trigger an error for deprecated functions.
173
-	 *
174
-	 * @since 6.0.0
175
-	 *
176
-	 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
177
-	 */
178
-	if ( ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) || monsterinsights_is_debug_mode() ) {
179
-		trigger_error( sprintf( esc_html__( '%1$s is %3$sdeprecated%4$s since MonsterInsights version %2$s.', 'google-analytics-for-wordpress' ), $function, $version, '<strong>', '</strong>' ) );
180
-		trigger_error( print_r( $backtrace, 1 ) );// Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine.
181
-		// Alternatively we could dump this to a file.
182
-	}
171
+  /**
172
+   * Filters whether to trigger an error for deprecated functions.
173
+   *
174
+   * @since 6.0.0
175
+   *
176
+   * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
177
+   */
178
+  if ( ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) || monsterinsights_is_debug_mode() ) {
179
+    trigger_error( sprintf( esc_html__( '%1$s is %3$sdeprecated%4$s since MonsterInsights version %2$s.', 'google-analytics-for-wordpress' ), $function, $version, '<strong>', '</strong>' ) );
180
+    trigger_error( print_r( $backtrace, 1 ) );// Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine.
181
+    // Alternatively we could dump this to a file.
182
+  }
183 183
 }
184 184
 
185 185
 /**
@@ -198,32 +198,32 @@  discard block
 block discarded – undo
198 198
  */
199 199
 function _monsterinsights_deprecated( $message ) {
200 200
 
201
-	/**
202
-	 * Deprecated Message Filter.
203
-	 *
204
-	 * Allow plugin to filter the deprecated message.
205
-	 *
206
-	 * @since 6.0.0
207
-	 * 
208
-	 * @param string $message Error message.
209
-	 */	
210
-	do_action( 'monsterinsights_deprecated_run', $message );
201
+  /**
202
+   * Deprecated Message Filter.
203
+   *
204
+   * Allow plugin to filter the deprecated message.
205
+   *
206
+   * @since 6.0.0
207
+   * 
208
+   * @param string $message Error message.
209
+   */	
210
+  do_action( 'monsterinsights_deprecated_run', $message );
211 211
 
212
-	$show_errors = current_user_can( 'manage_options' );
212
+  $show_errors = current_user_can( 'manage_options' );
213 213
 
214
-	/**
215
-	 * Deprecated Error Trigger.
216
-	 *
217
-	 * Allow plugin to filter the output error trigger.
218
-	 *
219
-	 * @since 6.0.0
220
-	 * 
221
-	 * @param bool $show_errors Whether to show errors.
222
-	 */
223
-	$show_errors = apply_filters( 'monsterinsights_deprecated_trigger_error', $show_errors );
224
-	if ( ( WP_DEBUG && $show_errors ) || monsterinsights_is_debug_mode() ) {
225
-		trigger_error( esc_html( $message ) );
226
-	}
214
+  /**
215
+   * Deprecated Error Trigger.
216
+   *
217
+   * Allow plugin to filter the output error trigger.
218
+   *
219
+   * @since 6.0.0
220
+   * 
221
+   * @param bool $show_errors Whether to show errors.
222
+   */
223
+  $show_errors = apply_filters( 'monsterinsights_deprecated_trigger_error', $show_errors );
224
+  if ( ( WP_DEBUG && $show_errors ) || monsterinsights_is_debug_mode() ) {
225
+    trigger_error( esc_html( $message ) );
226
+  }
227 227
 }
228 228
 
229 229
 
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
  * @return int Number of rows to request at most in API calls.
245 245
  */
246 246
 function monsterinsights_yst_ga_filter_api_limit( $limit ) {
247
-	$message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_reporting_get_max_api_limit</code>' );
248
-	return _monsterinsights_apply_filters_deprecated( 'yst-ga-filter-api-limit', array( $limit ), '6.0.0', $message );
247
+  $message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_reporting_get_max_api_limit</code>' );
248
+  return _monsterinsights_apply_filters_deprecated( 'yst-ga-filter-api-limit', array( $limit ), '6.0.0', $message );
249 249
 }
250 250
 add_filter( 'monsterinsights_reporting_get_max_api_limit', 'monsterinsights_yst_ga_filter_api_limit' );
251 251
 
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
  * @return bool Whether to track super admins. Default false.
259 259
  */
260 260
 function monsterinsights_yst_ga_track_super_admin( $track ) {
261
-	$track = ! $track; // invert track as in Yoast it defaulted to track super admins
262
-	$message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_track_super_admins</code>' );
263
-	return _monsterinsights_apply_filters_deprecated( 'yst_ga_track_super_admin', array( $track ), '6.0.0', $message );
261
+  $track = ! $track; // invert track as in Yoast it defaulted to track super admins
262
+  $message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_track_super_admins</code>' );
263
+  return _monsterinsights_apply_filters_deprecated( 'yst_ga_track_super_admin', array( $track ), '6.0.0', $message );
264 264
 }
265 265
 add_filter( 'monsterinsights_track_super_admins', 'monsterinsights_yst_ga_track_super_admin' );
266 266
 
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
  * Allows output before the analytics and ga.js tracking output.
272 272
  */
273 273
 function monsterinsights_yst_tracking() {
274
-	$message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_tracking_before{_$mode}</code>' );
275
-	_monsterinsights_do_action_deprecated( 'yst_tracking', array(), '6.0.0', $message );
274
+  $message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_tracking_before{_$mode}</code>' );
275
+  _monsterinsights_do_action_deprecated( 'yst_tracking', array(), '6.0.0', $message );
276 276
 }
277 277
 add_action( 'monsterinsights_tracking_before_ga', 'monsterinsights_yst_tracking' );
278 278
 add_action( 'monsterinsights_tracking_before_analytics', 'monsterinsights_yst_tracking' );
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
  * @return array GA.js options.
287 287
  */
288 288
 function monsterinsights_yoast_ga_push_array_ga_js( $options ) {
289
-	$message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_frontend_tracking_options_analytics_end</code>' );
290
-	return _monsterinsights_apply_filters_deprecated( 'yoast-ga-push-array-ga-js', array( $options ), '6.0.0', $message );
289
+  $message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_frontend_tracking_options_analytics_end</code>' );
290
+  return _monsterinsights_apply_filters_deprecated( 'yoast-ga-push-array-ga-js', array( $options ), '6.0.0', $message );
291 291
 }
292 292
 add_filter( 'monsterinsights_frontend_tracking_options_ga_end', 'monsterinsights_yoast_ga_push_array_ga_js' );
293 293
 
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
  * @return array Analytics.js options.
301 301
  */
302 302
 function monsterinsights_yoast_ga_push_array_universal( $options ) {
303
-	$message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_frontend_tracking_options_analytics_end</code>' );
304
-	return _monsterinsights_apply_filters_deprecated( 'yoast-ga-push-array-universal', array( $options ), '6.0.0', $message );
303
+  $message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_frontend_tracking_options_analytics_end</code>' );
304
+  return _monsterinsights_apply_filters_deprecated( 'yoast-ga-push-array-universal', array( $options ), '6.0.0', $message );
305 305
 }
306 306
 add_filter( 'monsterinsights_frontend_tracking_options_analytics_end', 'monsterinsights_yoast_ga_push_array_universal' );
307 307
 
@@ -314,23 +314,23 @@  discard block
 block discarded – undo
314 314
  * @return array Analytics.js options.
315 315
  */
316 316
 function monsterinsights_yst_ga_filter_push_vars( $options ) {
317
-	if ( ! has_filter('yst_ga_filter_push_vars' ) ) {
318
-		return $options;
319
-	} else {
320
-		$message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_frontend_tracking_options_analytics_before_scripts</code>' );
321
-		_monsterinsights_deprecated_hook( 'yst_ga_filter_push_vars', '6.0.0', $message );
317
+  if ( ! has_filter('yst_ga_filter_push_vars' ) ) {
318
+    return $options;
319
+  } else {
320
+    $message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_frontend_tracking_options_analytics_before_scripts</code>' );
321
+    _monsterinsights_deprecated_hook( 'yst_ga_filter_push_vars', '6.0.0', $message );
322 322
 
323
-		$i = 0;
324
-		while ( true ) {
325
-			if ( empty( $options[ 'yst_ga_filter_push_vars_' . $i ] ) ) {
326
-				$options[ 'yst_ga_filter_push_vars_' . $i ] = apply_filters( 'yst_ga_filter_push_vars', $options ); 
327
-				break;
328
-			} else {
329
-				$i++;
330
-			}
331
-		}
332
-		return $options;
333
-	}
323
+    $i = 0;
324
+    while ( true ) {
325
+      if ( empty( $options[ 'yst_ga_filter_push_vars_' . $i ] ) ) {
326
+        $options[ 'yst_ga_filter_push_vars_' . $i ] = apply_filters( 'yst_ga_filter_push_vars', $options ); 
327
+        break;
328
+      } else {
329
+        $i++;
330
+      }
331
+    }
332
+    return $options;
333
+  }
334 334
 }
335 335
 add_filter( 'monsterinsights_frontend_tracking_options_analytics_before_scripts', 'monsterinsights_yst_ga_filter_push_vars' );
336 336
 
@@ -344,12 +344,12 @@  discard block
 block discarded – undo
344 344
  * @return array GA App config.
345 345
  */
346 346
 function monsterinsights_yst_ga_filter_ga_config( $config ) {
347
-	$message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_{lite/pro}_google_app_config</code>' );
348
-	return _monsterinsights_apply_filters_deprecated( 'yst-ga-filter-ga-config', array( $config ), '6.0.0', $message );
347
+  $message = sprintf( __( 'Use %s instead.', 'google-analytics-for-wordpress' ), '<code>monsterinsights_{lite/pro}_google_app_config</code>' );
348
+  return _monsterinsights_apply_filters_deprecated( 'yst-ga-filter-ga-config', array( $config ), '6.0.0', $message );
349 349
 }
350 350
 add_filter( 'monsterinsights_lite_google_app_config', 'monsterinsights_yst_ga_filter_ga_config' );
351 351
 add_filter( 'monsterinsights_pro_google_app_config', 'monsterinsights_yst_ga_filter_ga_config' );
352 352
 
353 353
 function monsterinsights_disabled_user_group(){
354
-	return ! monsterinsights_track_user();
354
+  return ! monsterinsights_track_user();
355 355
 }
356 356
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/licensing/updater.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -267,12 +267,12 @@
 block discarded – undo
267 267
         $description                = isset( $this->info->description )    ? $this->info->description     : '';
268 268
 
269 269
         if ( ! empty( $changelog ) ) {
270
-             if ( ! empty( $description ) ) {
270
+              if ( ! empty( $description ) ) {
271 271
                 $api->sections['description'] = $description;
272 272
                 $api->sections['changelog']   = $changelog;
273
-             } else {
273
+              } else {
274 274
                 $api->sections['changelog']   = $changelog;
275
-             }
275
+              }
276 276
         } else if ( ! empty( $description ) ) {
277 277
             $api->sections['description'] = $description;
278 278
         } else {
Please login to merge, or discard this patch.
includes/admin/licensing/license.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -186,9 +186,9 @@
 block discarded – undo
186 186
         // Only run every 12 hours.
187 187
         $timestamp = get_option( 'monsterinsights_license_updates' );
188 188
         if ( ! $timestamp ) {
189
-             $timestamp = strtotime( '+8 hours' );
190
-             update_option( 'monsterinsights_license_updates', $timestamp );
191
-             $this->validate_key();
189
+              $timestamp = strtotime( '+8 hours' );
190
+              update_option( 'monsterinsights_license_updates', $timestamp );
191
+              $this->validate_key();
192 192
         } else {
193 193
             $current_timestamp = time();
194 194
             if ( $current_timestamp < $timestamp ) {
Please login to merge, or discard this patch.
includes/admin/capabilities.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             }
59 59
             
60 60
             break;
61
-         case 'monsterinsights_save_settings' :
61
+          case 'monsterinsights_save_settings' :
62 62
             $roles = monsterinsights_get_option( 'save_settings', array() );
63 63
 
64 64
             $user_can_via_settings = false;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                     }
73 73
                 }
74 74
             } else if ( ! empty( $roles ) && is_string( $roles ) ) {
75
-                 if ( user_can( $user_id, $roles ) ) {
75
+                  if ( user_can( $user_id, $roles ) ) {
76 76
                     $user_can_via_settings = true;
77 77
                 }
78 78
             }
Please login to merge, or discard this patch.
includes/admin/tracking.php 1 patch
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 // Exit if accessed directly
12 12
 if ( ! defined( 'ABSPATH' ) ) {
13
-	exit;
13
+  exit;
14 14
 }
15 15
 
16 16
 /**
@@ -22,308 +22,308 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class MonsterInsights_Tracking {
24 24
 
25
-	/**
26
-	 * The data to send to the EDD site
27
-	 *
28
-	 * @access private
29
-	 */
30
-	private $data;
31
-
32
-	/**
33
-	 * Get things going
34
-	 *
35
-	 * @access public
36
-	 */
37
-	public function __construct() {
38
-
39
-		add_action( 'init', array( $this, 'schedule_send' ) );
40
-		add_action( 'monsterinsights_settings_save_general_end', array( $this, 'check_for_settings_optin' ) );
41
-		add_action( 'admin_head', array( $this, 'check_for_optin' ) );
42
-		add_action( 'admin_head', array( $this, 'check_for_optout' ) );
43
-		add_action( 'admin_notices', array( $this, 'monsterinsights_admin_notice' ),7 );
44
-		add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
45
-		add_action( 'monsterinsights_daily_cron', array( $this, 'send_checkin' ) );
46
-	}
47
-
48
-	/**
49
-	 * Check if the user has opted into tracking
50
-	 *
51
-	 * @access private
52
-	 * @return bool
53
-	 */
54
-	private function tracking_allowed() {
55
-		return (bool) monsterinsights_get_option( 'anonymous_data', false );
56
-	}
57
-
58
-	/**
59
-	 * Setup the data that is going to be tracked
60
-	 *
61
-	 * @access private
62
-	 * @return void
63
-	 */
64
-	private function setup_data() {
65
-		$data = array();
66
-
67
-		// Retrieve current theme info
68
-		$theme_data    = wp_get_theme();
69
-		$theme         = $theme_data->Name . ' ' . $theme_data->Version;
70
-		$tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' );
71
-		$events_mode   = monsterinsights_get_option( 'events_mode', 'none' );
72
-		$update_mode   = monsterinsights_get_option( 'automatic_updates', false );
73
-
74
-		if ( $tracking_mode === false ) {
75
-			$tracking_mode = 'analytics';
76
-		}
77
-
78
-		if ( $events_mode === false ) {
79
-			$events_mode = 'none';
80
-		}
81
-
82
-		if ( $update_mode === false ) {
83
-			$update_mode = 'none';
84
-		}
85
-
86
-		$data['php_version'] = phpversion();
87
-		$data['mi_version']  = MONSTERINSIGHTS_VERSION;
88
-		$data['wp_version']  = get_bloginfo( 'version' );
89
-		$data['server']      = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
90
-		$data['over_time']   = get_option( 'monsterinsights_over_time', array() );
91
-		$data['multisite']   = is_multisite();
92
-		$data['url']         = home_url();
93
-		$data['theme']       = $theme;
94
-		$data['email']       = get_bloginfo( 'admin_email' );
95
-		$data['key']         = monsterinsights_get_license();
96
-		$data['sas']         = monsterinsights_get_shareasale_id();
97
-		$data['setttings']     = monsterinsights_get_options();
98
-		$data['tracking_mode'] = $tracking_mode;
99
-		$data['events_mode']   = $events_mode;
100
-		$data['autoupdate']    = $update_mode;
101
-
102
-		// Retrieve current plugin information
103
-		if( ! function_exists( 'get_plugins' ) ) {
104
-			include ABSPATH . '/wp-admin/includes/plugin.php';
105
-		}
106
-
107
-		$plugins        = array_keys( get_plugins() );
108
-		$active_plugins = get_option( 'active_plugins', array() );
109
-
110
-		foreach ( $plugins as $key => $plugin ) {
111
-			if ( in_array( $plugin, $active_plugins ) ) {
112
-				// Remove active plugins from list so we can show active and inactive separately
113
-				unset( $plugins[ $key ] );
114
-			}
115
-		}
116
-
117
-		$data['active_plugins']   = $active_plugins;
118
-		$data['inactive_plugins'] = $plugins;
119
-		$data['locale']           = get_locale();
120
-
121
-		$this->data = $data;
122
-	}
123
-
124
-	/**
125
-	 * Send the data to the EDD server
126
-	 *
127
-	 * @access private
128
-	 * @return void
129
-	 */
130
-	public function send_checkin( $override = false, $ignore_last_checkin = false ) {
131
-
132
-		$home_url = trailingslashit( home_url() );
133
-		if ( $home_url === 'https://www.monsterinsights.com/'     || 
134
-			 $home_url === 'https://beta.monsterinsights.com/'    ||
135
-			 $home_url === 'https://staging.monsterinsights.com/' ||
136
-			 $home_url === 'https://testing.monsterinsights.com/'
137
-		) {
138
-			return false;
139
-		}
140
-
141
-		if( ! $this->tracking_allowed() && ! $override ) {
142
-			return false;
143
-		}
144
-
145
-		// Send a maximum of once per week
146
-		$last_send = $this->get_last_send();
147
-		if( is_numeric( $last_send ) && $last_send > strtotime( '-1 week' ) && ! $ignore_last_checkin ) {
148
-			return false;
149
-		}
150
-
151
-		$this->setup_data();
152
-
153
-		$request = wp_remote_post( 'https://www.monsterinsights.com/?edd_action=checkin', array(
154
-			'method'      => 'POST',
155
-			'timeout'     => 20,
156
-			'redirection' => 5,
157
-			'httpversion' => '1.1',
158
-			'blocking'    => true,
159
-			'body'        => $this->data,
160
-			'user-agent'  => 'MI/' . MONSTERINSIGHTS_VERSION . '; ' . get_bloginfo( 'url' )
161
-		) );
162
-
163
-		if( is_wp_error( $request ) ) {
164
-			return $request;
165
-		}
166
-
167
-		update_option( 'mi_tracking_last_send', time() );
168
-
169
-		return true;
170
-
171
-	}
172
-
173
-	/**
174
-	 * Check for a new opt-in on settings save
175
-	 *
176
-	 * This runs during the sanitation of General settings, thus the return
177
-	 *
178
-	 * @access public
179
-	 * @return array
180
-	 */
181
-	public function check_for_settings_optin() {
182
-		if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
183
-			return;
184
-		}
185
-
186
-		// Send an intial check in on settings save
187
-		$anonymous_data = isset( $_POST['anonymous_data'] ) ? 1 : 0;
188
-		if ( $anonymous_data ) {
189
-			$this->send_checkin( true );
190
-		}
191
-
192
-	}
193
-
194
-	/**
195
-	 * Check for a new opt-in via the admin notice
196
-	 *
197
-	 * @access public
198
-	 * @return void
199
-	 */
200
-	public function check_for_optin() {
201
-		if ( ! ( ! empty( $_REQUEST['mi_action'] ) && 'opt_into_tracking' === $_REQUEST['mi_action'] ) ) {
202
-			return;
203
-		}
204
-
205
-		if ( monsterinsights_get_option( 'anonymous_data', false ) ) {
206
-			return;
207
-		}
208
-
209
-		if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
210
-			return;
211
-		}
25
+  /**
26
+   * The data to send to the EDD site
27
+   *
28
+   * @access private
29
+   */
30
+  private $data;
31
+
32
+  /**
33
+   * Get things going
34
+   *
35
+   * @access public
36
+   */
37
+  public function __construct() {
38
+
39
+    add_action( 'init', array( $this, 'schedule_send' ) );
40
+    add_action( 'monsterinsights_settings_save_general_end', array( $this, 'check_for_settings_optin' ) );
41
+    add_action( 'admin_head', array( $this, 'check_for_optin' ) );
42
+    add_action( 'admin_head', array( $this, 'check_for_optout' ) );
43
+    add_action( 'admin_notices', array( $this, 'monsterinsights_admin_notice' ),7 );
44
+    add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
45
+    add_action( 'monsterinsights_daily_cron', array( $this, 'send_checkin' ) );
46
+  }
47
+
48
+  /**
49
+   * Check if the user has opted into tracking
50
+   *
51
+   * @access private
52
+   * @return bool
53
+   */
54
+  private function tracking_allowed() {
55
+    return (bool) monsterinsights_get_option( 'anonymous_data', false );
56
+  }
57
+
58
+  /**
59
+   * Setup the data that is going to be tracked
60
+   *
61
+   * @access private
62
+   * @return void
63
+   */
64
+  private function setup_data() {
65
+    $data = array();
66
+
67
+    // Retrieve current theme info
68
+    $theme_data    = wp_get_theme();
69
+    $theme         = $theme_data->Name . ' ' . $theme_data->Version;
70
+    $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' );
71
+    $events_mode   = monsterinsights_get_option( 'events_mode', 'none' );
72
+    $update_mode   = monsterinsights_get_option( 'automatic_updates', false );
73
+
74
+    if ( $tracking_mode === false ) {
75
+      $tracking_mode = 'analytics';
76
+    }
77
+
78
+    if ( $events_mode === false ) {
79
+      $events_mode = 'none';
80
+    }
81
+
82
+    if ( $update_mode === false ) {
83
+      $update_mode = 'none';
84
+    }
85
+
86
+    $data['php_version'] = phpversion();
87
+    $data['mi_version']  = MONSTERINSIGHTS_VERSION;
88
+    $data['wp_version']  = get_bloginfo( 'version' );
89
+    $data['server']      = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
90
+    $data['over_time']   = get_option( 'monsterinsights_over_time', array() );
91
+    $data['multisite']   = is_multisite();
92
+    $data['url']         = home_url();
93
+    $data['theme']       = $theme;
94
+    $data['email']       = get_bloginfo( 'admin_email' );
95
+    $data['key']         = monsterinsights_get_license();
96
+    $data['sas']         = monsterinsights_get_shareasale_id();
97
+    $data['setttings']     = monsterinsights_get_options();
98
+    $data['tracking_mode'] = $tracking_mode;
99
+    $data['events_mode']   = $events_mode;
100
+    $data['autoupdate']    = $update_mode;
101
+
102
+    // Retrieve current plugin information
103
+    if( ! function_exists( 'get_plugins' ) ) {
104
+      include ABSPATH . '/wp-admin/includes/plugin.php';
105
+    }
106
+
107
+    $plugins        = array_keys( get_plugins() );
108
+    $active_plugins = get_option( 'active_plugins', array() );
109
+
110
+    foreach ( $plugins as $key => $plugin ) {
111
+      if ( in_array( $plugin, $active_plugins ) ) {
112
+        // Remove active plugins from list so we can show active and inactive separately
113
+        unset( $plugins[ $key ] );
114
+      }
115
+    }
116
+
117
+    $data['active_plugins']   = $active_plugins;
118
+    $data['inactive_plugins'] = $plugins;
119
+    $data['locale']           = get_locale();
120
+
121
+    $this->data = $data;
122
+  }
123
+
124
+  /**
125
+   * Send the data to the EDD server
126
+   *
127
+   * @access private
128
+   * @return void
129
+   */
130
+  public function send_checkin( $override = false, $ignore_last_checkin = false ) {
131
+
132
+    $home_url = trailingslashit( home_url() );
133
+    if ( $home_url === 'https://www.monsterinsights.com/'     || 
134
+       $home_url === 'https://beta.monsterinsights.com/'    ||
135
+       $home_url === 'https://staging.monsterinsights.com/' ||
136
+       $home_url === 'https://testing.monsterinsights.com/'
137
+    ) {
138
+      return false;
139
+    }
140
+
141
+    if( ! $this->tracking_allowed() && ! $override ) {
142
+      return false;
143
+    }
144
+
145
+    // Send a maximum of once per week
146
+    $last_send = $this->get_last_send();
147
+    if( is_numeric( $last_send ) && $last_send > strtotime( '-1 week' ) && ! $ignore_last_checkin ) {
148
+      return false;
149
+    }
150
+
151
+    $this->setup_data();
152
+
153
+    $request = wp_remote_post( 'https://www.monsterinsights.com/?edd_action=checkin', array(
154
+      'method'      => 'POST',
155
+      'timeout'     => 20,
156
+      'redirection' => 5,
157
+      'httpversion' => '1.1',
158
+      'blocking'    => true,
159
+      'body'        => $this->data,
160
+      'user-agent'  => 'MI/' . MONSTERINSIGHTS_VERSION . '; ' . get_bloginfo( 'url' )
161
+    ) );
162
+
163
+    if( is_wp_error( $request ) ) {
164
+      return $request;
165
+    }
166
+
167
+    update_option( 'mi_tracking_last_send', time() );
168
+
169
+    return true;
170
+
171
+  }
172
+
173
+  /**
174
+   * Check for a new opt-in on settings save
175
+   *
176
+   * This runs during the sanitation of General settings, thus the return
177
+   *
178
+   * @access public
179
+   * @return array
180
+   */
181
+  public function check_for_settings_optin() {
182
+    if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
183
+      return;
184
+    }
185
+
186
+    // Send an intial check in on settings save
187
+    $anonymous_data = isset( $_POST['anonymous_data'] ) ? 1 : 0;
188
+    if ( $anonymous_data ) {
189
+      $this->send_checkin( true );
190
+    }
191
+
192
+  }
193
+
194
+  /**
195
+   * Check for a new opt-in via the admin notice
196
+   *
197
+   * @access public
198
+   * @return void
199
+   */
200
+  public function check_for_optin() {
201
+    if ( ! ( ! empty( $_REQUEST['mi_action'] ) && 'opt_into_tracking' === $_REQUEST['mi_action'] ) ) {
202
+      return;
203
+    }
204
+
205
+    if ( monsterinsights_get_option( 'anonymous_data', false ) ) {
206
+      return;
207
+    }
208
+
209
+    if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
210
+      return;
211
+    }
212 212
 		
213
-		monsterinsights_update_option( 'anonymous_data', 1 );
214
-		$this->send_checkin( true );
215
-		update_option( 'monsterinsights_tracking_notice', 1 );
216
-	}
217
-
218
-	/**
219
-	 * Check for a new opt-in via the admin notice
220
-	 *
221
-	 * @access public
222
-	 * @return void
223
-	 */
224
-	public function check_for_optout() {
225
-		if ( ! ( ! empty( $_REQUEST['mi_action'] ) && 'opt_out_of_tracking' === $_REQUEST['mi_action'] ) ) {
226
-			return;
227
-		}
228
-
229
-		if ( monsterinsights_get_option( 'anonymous_data', false ) ) {
230
-			return;
231
-		}
232
-
233
-		if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
234
-			return;
235
-		}
236
-
237
-		monsterinsights_update_option( 'anonymous_data', 0 );
238
-		update_option( 'monsterinsights_tracking_notice', 1 );
239
-	}
240
-
241
-	/**
242
-	 * Get the last time a checkin was sent
243
-	 *
244
-	 * @access private
245
-	 * @return false|string
246
-	 */
247
-	private function get_last_send() {
248
-		return get_option( 'monsterinsights_tracking_last_send' );
249
-	}
250
-
251
-	/**
252
-	 * Schedule a weekly checkin
253
-	 *
254
-	 * @access public
255
-	 * @return void
256
-	 */
257
-	public function schedule_send() {
258
-		// We send once a day (while tracking is allowed) to check in, which can be used to determine active sites
259
-		if ( ! wp_next_scheduled( 'monsterinsights_daily_cron' ) ) {
260
-			// Set the next event of fetching data
261
-			wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:01:00 ' ), 'daily', 'monsterinsights_daily_cron' );
262
-		}
263
-	}
264
-
265
-	/**
266
-	 * Display the admin notice to users that have not opted-in or out
267
-	 *
268
-	 * @access public
269
-	 * @return void
270
-	 */
271
-	public function monsterinsights_admin_notice() {
272
-
273
-		$hide_notice = get_option( 'monsterinsights_tracking_notice' );
274
-
275
-		if ( $hide_notice ) {
276
-			return;
277
-		}
278
-
279
-		if ( monsterinsights_get_option( 'anonymous_data', false ) ) {
280
-			return;
281
-		}
282
-
283
-		if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
284
-			return;
285
-		}
286
-
287
-		if ( defined( 'MONSTERINSIGHTS_SHOWING_EMPTY_CONFIG_NOTICE' ) && MONSTERINSIGHTS_SHOWING_EMPTY_CONFIG_NOTICE ) {
288
-			return;
289
-		}
213
+    monsterinsights_update_option( 'anonymous_data', 1 );
214
+    $this->send_checkin( true );
215
+    update_option( 'monsterinsights_tracking_notice', 1 );
216
+  }
217
+
218
+  /**
219
+   * Check for a new opt-in via the admin notice
220
+   *
221
+   * @access public
222
+   * @return void
223
+   */
224
+  public function check_for_optout() {
225
+    if ( ! ( ! empty( $_REQUEST['mi_action'] ) && 'opt_out_of_tracking' === $_REQUEST['mi_action'] ) ) {
226
+      return;
227
+    }
228
+
229
+    if ( monsterinsights_get_option( 'anonymous_data', false ) ) {
230
+      return;
231
+    }
232
+
233
+    if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
234
+      return;
235
+    }
236
+
237
+    monsterinsights_update_option( 'anonymous_data', 0 );
238
+    update_option( 'monsterinsights_tracking_notice', 1 );
239
+  }
240
+
241
+  /**
242
+   * Get the last time a checkin was sent
243
+   *
244
+   * @access private
245
+   * @return false|string
246
+   */
247
+  private function get_last_send() {
248
+    return get_option( 'monsterinsights_tracking_last_send' );
249
+  }
250
+
251
+  /**
252
+   * Schedule a weekly checkin
253
+   *
254
+   * @access public
255
+   * @return void
256
+   */
257
+  public function schedule_send() {
258
+    // We send once a day (while tracking is allowed) to check in, which can be used to determine active sites
259
+    if ( ! wp_next_scheduled( 'monsterinsights_daily_cron' ) ) {
260
+      // Set the next event of fetching data
261
+      wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:01:00 ' ), 'daily', 'monsterinsights_daily_cron' );
262
+    }
263
+  }
264
+
265
+  /**
266
+   * Display the admin notice to users that have not opted-in or out
267
+   *
268
+   * @access public
269
+   * @return void
270
+   */
271
+  public function monsterinsights_admin_notice() {
272
+
273
+    $hide_notice = get_option( 'monsterinsights_tracking_notice' );
274
+
275
+    if ( $hide_notice ) {
276
+      return;
277
+    }
278
+
279
+    if ( monsterinsights_get_option( 'anonymous_data', false ) ) {
280
+      return;
281
+    }
282
+
283
+    if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
284
+      return;
285
+    }
286
+
287
+    if ( defined( 'MONSTERINSIGHTS_SHOWING_EMPTY_CONFIG_NOTICE' ) && MONSTERINSIGHTS_SHOWING_EMPTY_CONFIG_NOTICE ) {
288
+      return;
289
+    }
290 290
 		
291
-		if (
292
-			stristr( network_site_url( '/' ), 'dev'       ) !== false ||
293
-			stristr( network_site_url( '/' ), 'localhost' ) !== false ||
294
-			stristr( network_site_url( '/' ), ':8888'     ) !== false // This is common with MAMP on OS X
295
-		) {
296
-			update_option( 'monsterinsights_tracking_notice', '1' );
297
-		} else {
298
-			if ( ! defined( 'MONSTERINSIGHTS_SHOWING_OPTIN_TRACKING_NOTICE' ) ) {
299
-				define( 'MONSTERINSIGHTS_SHOWING_OPTIN_TRACKING_NOTICE', true );
300
-			}
301
-			$optin_url  = add_query_arg( 'mi_action', 'opt_into_tracking' );
302
-			$optout_url = add_query_arg( 'mi_action', 'opt_out_of_tracking' );
303
-			echo '<div class="updated"><p>';
304
-			echo esc_html__( 'Allow MonsterInsights to track plugin usage? Opt-in to tracking and our newsletter to stay informed of the latest changes to MonsterInsights and help us ensure compatibility.', 'google-analytics-for-wordpress' );
305
-			echo '&nbsp;<a href="' . esc_url( $optin_url ) . '" class="button-secondary">' . __( 'Allow', 'google-analytics-for-wordpress' ) . '</a>';
306
-			echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary">' . __( 'Do not allow', 'google-analytics-for-wordpress' ) . '</a>';
307
-			echo '</p></div>';
308
-		}
309
-	}
310
-
311
-	/**
312
-	 * Registers new cron schedules
313
-	 *
314
-	 * @since 6.0.0
315
-	 *
316
-	 * @param array $schedules
317
-	 * @return array
318
-	 */
319
-	public function add_schedules( $schedules = array() ) {
320
-		// Adds once weekly to the existing schedules.
321
-		$schedules['weekly'] = array(
322
-			'interval' => 604800,
323
-			'display'  => __( 'Once Weekly', 'google-analytics-for-wordpress' )
324
-		);
325
-		return $schedules;
326
-	}
291
+    if (
292
+      stristr( network_site_url( '/' ), 'dev'       ) !== false ||
293
+      stristr( network_site_url( '/' ), 'localhost' ) !== false ||
294
+      stristr( network_site_url( '/' ), ':8888'     ) !== false // This is common with MAMP on OS X
295
+    ) {
296
+      update_option( 'monsterinsights_tracking_notice', '1' );
297
+    } else {
298
+      if ( ! defined( 'MONSTERINSIGHTS_SHOWING_OPTIN_TRACKING_NOTICE' ) ) {
299
+        define( 'MONSTERINSIGHTS_SHOWING_OPTIN_TRACKING_NOTICE', true );
300
+      }
301
+      $optin_url  = add_query_arg( 'mi_action', 'opt_into_tracking' );
302
+      $optout_url = add_query_arg( 'mi_action', 'opt_out_of_tracking' );
303
+      echo '<div class="updated"><p>';
304
+      echo esc_html__( 'Allow MonsterInsights to track plugin usage? Opt-in to tracking and our newsletter to stay informed of the latest changes to MonsterInsights and help us ensure compatibility.', 'google-analytics-for-wordpress' );
305
+      echo '&nbsp;<a href="' . esc_url( $optin_url ) . '" class="button-secondary">' . __( 'Allow', 'google-analytics-for-wordpress' ) . '</a>';
306
+      echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary">' . __( 'Do not allow', 'google-analytics-for-wordpress' ) . '</a>';
307
+      echo '</p></div>';
308
+    }
309
+  }
310
+
311
+  /**
312
+   * Registers new cron schedules
313
+   *
314
+   * @since 6.0.0
315
+   *
316
+   * @param array $schedules
317
+   * @return array
318
+   */
319
+  public function add_schedules( $schedules = array() ) {
320
+    // Adds once weekly to the existing schedules.
321
+    $schedules['weekly'] = array(
322
+      'interval' => 604800,
323
+      'display'  => __( 'Once Weekly', 'google-analytics-for-wordpress' )
324
+    );
325
+    return $schedules;
326
+  }
327 327
 
328 328
 }
329 329
 new MonsterInsights_Tracking();
330 330
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/reporting.php 1 patch
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -14,172 +14,172 @@
 block discarded – undo
14 14
 
15 15
 // Exit if accessed directly
16 16
 if ( ! defined( 'ABSPATH' ) ) {
17
-	exit;
17
+  exit;
18 18
 }
19 19
 
20 20
 final class MonsterInsights_Reporting {
21 21
 
22
-	/**
23
-	 * Holds the base object.
24
-	 *
25
-	 * @access public
26
-	 * @since 6.0.0
27
-	 * @var MonsterInsights $base MonsterInsights Base object.
28
-	 */
29
-	public $base;
30
-
31
-	/**
32
-	 * Holds the GA client object if using oAuth.
33
-	 *
34
-	 * @access public
35
-	 * @since 6.0.0
36
-	 * @var MonsterInsights_GA_Client $client GA client object.
37
-	 */
38
-	public $client;
39
-
40
-	/**
41
-	 * Is the dashboard/reporting pages disabled?
42
-	 *
43
-	 * @access public
44
-	 * @since 6.0.0
45
-	 * @var bool $dashboard_disabled If the dashboard is disabled.
46
-	 */
47
-	public $dashboard_disabled;
48
-
49
-	/**
50
-	 * Dashboard report
51
-	 *
52
-	 * @access public
53
-	 * @since 6.0.0
54
-	 * @var string $dashboard_report Report hook name of dashboard report.
55
-	 */
56
-	public $dashboard_report;
57
-
58
-	/**
59
-	 * Primary class constructor.
60
-	 *
61
-	 * @access public
62
-	 * @since 6.0.0
63
-	 */
64
-	public function __construct( ) {
65
-
66
-		// Get object 
67
-		$this->base        		  = MonsterInsights();
68
-		$this->client       	  = $this->base->ga;
69
-		$this->dashboard_disabled = monsterinsights_get_option( 'dashboards_disabled', false );
70
-		$this->dashboard_report   = monsterinsights_get_option( 'dashboard_report', 'overview' );
71
-
72
-		if ( isset( $this->client->status ) && $this->client->status === 'valid' ) {
73
-			// Cron actions
74
-				// Add cron if its not there
75
-				add_action( 'wp', array( $this, 'schedule_cron' ) );
22
+  /**
23
+   * Holds the base object.
24
+   *
25
+   * @access public
26
+   * @since 6.0.0
27
+   * @var MonsterInsights $base MonsterInsights Base object.
28
+   */
29
+  public $base;
30
+
31
+  /**
32
+   * Holds the GA client object if using oAuth.
33
+   *
34
+   * @access public
35
+   * @since 6.0.0
36
+   * @var MonsterInsights_GA_Client $client GA client object.
37
+   */
38
+  public $client;
39
+
40
+  /**
41
+   * Is the dashboard/reporting pages disabled?
42
+   *
43
+   * @access public
44
+   * @since 6.0.0
45
+   * @var bool $dashboard_disabled If the dashboard is disabled.
46
+   */
47
+  public $dashboard_disabled;
48
+
49
+  /**
50
+   * Dashboard report
51
+   *
52
+   * @access public
53
+   * @since 6.0.0
54
+   * @var string $dashboard_report Report hook name of dashboard report.
55
+   */
56
+  public $dashboard_report;
57
+
58
+  /**
59
+   * Primary class constructor.
60
+   *
61
+   * @access public
62
+   * @since 6.0.0
63
+   */
64
+  public function __construct( ) {
65
+
66
+    // Get object 
67
+    $this->base        		  = MonsterInsights();
68
+    $this->client       	  = $this->base->ga;
69
+    $this->dashboard_disabled = monsterinsights_get_option( 'dashboards_disabled', false );
70
+    $this->dashboard_report   = monsterinsights_get_option( 'dashboard_report', 'overview' );
71
+
72
+    if ( isset( $this->client->status ) && $this->client->status === 'valid' ) {
73
+      // Cron actions
74
+        // Add cron if its not there
75
+        add_action( 'wp', array( $this, 'schedule_cron' ) );
76 76
 				
77
-				// Collect analytics data on cron event
78
-				add_action( 'monsterinsights_daily_cron', array( $this, 'run_cron' ) );
79
-
80
-				// If cron did not run for some reason (no users visited site), run it now
81
-				if ( filter_input( INPUT_GET, 'page' ) === 'monsterinsights_dashboard' || filter_input( INPUT_GET, 'page' ) === 'monsterinsights_reports' ) {
82
-					add_action( 'admin_init', array( $this, 'maybe_get_data' ) );
83
-				}
84
-		}
85
-
86
-
87
-		// Dashboard disabled setting
88
-		add_action( 'monsterinsights_settings_save_general', array( $this, 'dashboard_disabled' ), 9 );
89
-	}
90
-
91
-	public function dashboard_disabled( ) {
92
-		$dashboards_disabled     = isset( $_POST['dashboards_disabled'] ) ? 1 : 0;
93
-		$dashboards_disabled_old = monsterinsights_get_option( 'dashboards_disabled', false );
94
-
95
-		// We only care if the switch is going on or off
96
-		if ( $dashboards_disabled && ! $dashboards_disabled_old ) {
97
-			// The dashboards are now being disabled
98
-				// Clear data + last run + failed
99
-				$this->delete_aggregate_data();
100
-
101
-		} else if ( ! $dashboards_disabled && $dashboards_disabled_old ){
102
-			// The dashboards are now being enabled
103
-				// Refresh data + schedule cron
104
-				$this->refresh_aggregate_data();
105
-				$this->schedule_cron();
106
-		}
107
-	}
108
-
109
-	public function schedule_cron() {
110
-		if ( ! wp_next_scheduled( 'monsterinsights_daily_cron' ) ) {
111
-			// Set the next event of fetching data
112
-			wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:01:00 ' ), 'daily', 'monsterinsights_daily_cron' );
113
-		}
114
-	}
115
-
116
-	public function maybe_get_data() {
117
-		if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
118
-			return false;
119
-		}
120
-
121
-		$last_run = monsterinsights_get_option( 'cron_last_run', false );
122
-
123
-		// See if issue connecting or expired
124
-		if ( $last_run === false || monsterinsights_hours_between( $last_run ) >= 24 || date( 'Ymd', $last_run ) !== date('Ymd', time() ) ) { 
125
-			$this->run_cron();
126
-		}
127
-	}
128
-
129
-	public function run_cron() {
130
-		if ( $this->dashboard_disabled ) {
131
-			return;
132
-		}
133
-
134
-		if ( is_numeric( (int) $this->client->profile ) && $this->client->status === 'valid' ) {
135
-			// Profile is set
136
-			$this->add_aggregate_data();
137
-		}
138
-	}
139
-
140
-	public function refresh_aggregate_data() {
141
-		if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
142
-			return false;
143
-		}
144
-
145
-		$this->delete_aggregate_data();
146
-		$this->add_aggregate_data();
147
-	}
148
-
149
-	private function add_aggregate_data() {
150
-		if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
151
-			return false;
152
-		}
153
-		/** 
154
-		 * Developer Alert:
155
-		 *
156
-		 * Per the README, this is considered an internal hook and should
157
-		 * not be used by other developers. This hook's behavior may be modified
158
-		 * or the hook may be removed at any time, without warning.
159
-		 */
160
-		do_action( 'monsterinsights_add_aggregate_data', $this->client, $this->client->profile );
161
-		monsterinsights_update_option( 'cron_last_run', time() );
162
-		monsterinsights_delete_option( 'cron_failed' );
163
-	}
164
-
165
-	public function delete_aggregate_data() {
166
-		if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
167
-			return false;
168
-		}
169
-		/** 
170
-		 * Developer Alert:
171
-		 *
172
-		 * Per the README, this is considered an internal hook and should
173
-		 * not be used by other developers. This hook's behavior may be modified
174
-		 * or the hook may be removed at any time, without warning.
175
-		 */
176
-		if ( ! empty( $this->client ) && ! empty( $this->client->profile ) ) {
177
-			do_action( 'monsterinsights_delete_aggregate_data', $this->client, $this->client->profile );
178
-		}
179
-		$options = array(
180
-			'cron_failed',
181
-			'cron_last_run',
182
-		);
183
-		monsterinsights_delete_options( $options );
184
-	}
77
+        // Collect analytics data on cron event
78
+        add_action( 'monsterinsights_daily_cron', array( $this, 'run_cron' ) );
79
+
80
+        // If cron did not run for some reason (no users visited site), run it now
81
+        if ( filter_input( INPUT_GET, 'page' ) === 'monsterinsights_dashboard' || filter_input( INPUT_GET, 'page' ) === 'monsterinsights_reports' ) {
82
+          add_action( 'admin_init', array( $this, 'maybe_get_data' ) );
83
+        }
84
+    }
85
+
86
+
87
+    // Dashboard disabled setting
88
+    add_action( 'monsterinsights_settings_save_general', array( $this, 'dashboard_disabled' ), 9 );
89
+  }
90
+
91
+  public function dashboard_disabled( ) {
92
+    $dashboards_disabled     = isset( $_POST['dashboards_disabled'] ) ? 1 : 0;
93
+    $dashboards_disabled_old = monsterinsights_get_option( 'dashboards_disabled', false );
94
+
95
+    // We only care if the switch is going on or off
96
+    if ( $dashboards_disabled && ! $dashboards_disabled_old ) {
97
+      // The dashboards are now being disabled
98
+        // Clear data + last run + failed
99
+        $this->delete_aggregate_data();
100
+
101
+    } else if ( ! $dashboards_disabled && $dashboards_disabled_old ){
102
+      // The dashboards are now being enabled
103
+        // Refresh data + schedule cron
104
+        $this->refresh_aggregate_data();
105
+        $this->schedule_cron();
106
+    }
107
+  }
108
+
109
+  public function schedule_cron() {
110
+    if ( ! wp_next_scheduled( 'monsterinsights_daily_cron' ) ) {
111
+      // Set the next event of fetching data
112
+      wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:01:00 ' ), 'daily', 'monsterinsights_daily_cron' );
113
+    }
114
+  }
115
+
116
+  public function maybe_get_data() {
117
+    if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
118
+      return false;
119
+    }
120
+
121
+    $last_run = monsterinsights_get_option( 'cron_last_run', false );
122
+
123
+    // See if issue connecting or expired
124
+    if ( $last_run === false || monsterinsights_hours_between( $last_run ) >= 24 || date( 'Ymd', $last_run ) !== date('Ymd', time() ) ) { 
125
+      $this->run_cron();
126
+    }
127
+  }
128
+
129
+  public function run_cron() {
130
+    if ( $this->dashboard_disabled ) {
131
+      return;
132
+    }
133
+
134
+    if ( is_numeric( (int) $this->client->profile ) && $this->client->status === 'valid' ) {
135
+      // Profile is set
136
+      $this->add_aggregate_data();
137
+    }
138
+  }
139
+
140
+  public function refresh_aggregate_data() {
141
+    if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
142
+      return false;
143
+    }
144
+
145
+    $this->delete_aggregate_data();
146
+    $this->add_aggregate_data();
147
+  }
148
+
149
+  private function add_aggregate_data() {
150
+    if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
151
+      return false;
152
+    }
153
+    /** 
154
+     * Developer Alert:
155
+     *
156
+     * Per the README, this is considered an internal hook and should
157
+     * not be used by other developers. This hook's behavior may be modified
158
+     * or the hook may be removed at any time, without warning.
159
+     */
160
+    do_action( 'monsterinsights_add_aggregate_data', $this->client, $this->client->profile );
161
+    monsterinsights_update_option( 'cron_last_run', time() );
162
+    monsterinsights_delete_option( 'cron_failed' );
163
+  }
164
+
165
+  public function delete_aggregate_data() {
166
+    if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
167
+      return false;
168
+    }
169
+    /** 
170
+     * Developer Alert:
171
+     *
172
+     * Per the README, this is considered an internal hook and should
173
+     * not be used by other developers. This hook's behavior may be modified
174
+     * or the hook may be removed at any time, without warning.
175
+     */
176
+    if ( ! empty( $this->client ) && ! empty( $this->client->profile ) ) {
177
+      do_action( 'monsterinsights_delete_aggregate_data', $this->client, $this->client->profile );
178
+    }
179
+    $options = array(
180
+      'cron_failed',
181
+      'cron_last_run',
182
+    );
183
+    monsterinsights_delete_options( $options );
184
+  }
185 185
 }
186 186
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/pages/settings.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     }
212 212
     
213 213
     if ( empty( $nonce ) ) {
214
-         return;
214
+          return;
215 215
     }
216 216
     
217 217
     if ( ! wp_verify_nonce( $_REQUEST[$nonce], 'monsterinsights-switch-to-analyticsjs-nonce' ) ) {
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
     }
267 267
     
268 268
     if ( empty( $nonce ) ) {
269
-         return;
269
+          return;
270 270
     }
271 271
     
272 272
     if ( ! wp_verify_nonce( $_REQUEST[$nonce], 'monsterinsights-switch-to-jsevents-nonce' ) ) {
Please login to merge, or discard this patch.
includes/admin/pages/tools.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit;
4
+  exit;
5 5
 }
6 6
 
7 7
 /**
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
13 13
  * @return void
14 14
  */
15 15
 function monsterinsights_tools_page() {
16
-	/** 
17
-	 * Developer Alert:
18
-	 *
19
-	 * Per the README, this is considered an internal hook and should
20
-	 * not be used by other developers. This hook's behavior may be modified
21
-	 * or the hook may be removed at any time, without warning.
22
-	 */
23
-	do_action( 'monsterinsights_head' );
24
-	?>
16
+  /** 
17
+   * Developer Alert:
18
+   *
19
+   * Per the README, this is considered an internal hook and should
20
+   * not be used by other developers. This hook's behavior may be modified
21
+   * or the hook may be removed at any time, without warning.
22
+   */
23
+  do_action( 'monsterinsights_head' );
24
+  ?>
25 25
 	<?php echo monsterinsights_ublock_notice(); ?>
26 26
 
27 27
 	<!-- Tabs -->
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 }
53 53
 
54 54
 function monsterinsights_tools_url_builder_tab(){
55
-	do_action( 'monsterinsights_tools_url_builder_tab' );
55
+  do_action( 'monsterinsights_tools_url_builder_tab' );
56 56
 }
57 57
 
58 58
 function monsterinsights_tools_settings_tab() {
59
-	ob_start();?>
59
+  ob_start();?>
60 60
 	<h2><?php echo esc_html__( 'Setting Tools', 'google-analytics-for-wordpress' );?></h2>
61 61
 	<p><?php echo esc_html__( 'You can use the below tools to import settings from other MonsterInsights websites or export settings to import into another MonsterInsights install.', 'google-analytics-for-wordpress' ); ?> </p>
62 62
 	<br />
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 				</th>
71 71
 				<td>
72 72
 					<?php 
73
-					if ( ! empty( $_REQUEST['action'] ) && ! empty( $_REQUEST['result'] ) && $_REQUEST['action'] === 'import' && $_REQUEST['result'] === 'success' ){
74
-						echo MonsterInsights()->notices->display_inline_notice( 'monsterinsights_standard_notice', '', __( 'Successfully imported settings!','google-analytics-for-wordpress'), 'success', false, array() );
75
-					}
76
-					?>
73
+          if ( ! empty( $_REQUEST['action'] ) && ! empty( $_REQUEST['result'] ) && $_REQUEST['action'] === 'import' && $_REQUEST['result'] === 'success' ){
74
+            echo MonsterInsights()->notices->display_inline_notice( 'monsterinsights_standard_notice', '', __( 'Successfully imported settings!','google-analytics-for-wordpress'), 'success', false, array() );
75
+          }
76
+          ?>
77 77
 					<form method="post" enctype="multipart/form-data">
78 78
 						<p>
79 79
 							<input type="file" name="import_file"/>
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		</tbody>
114 114
 	</table>
115 115
 	<?php
116
-	echo ob_get_clean();
116
+  echo ob_get_clean();
117 117
 }
118 118
 
119 119
 /**
@@ -125,105 +125,105 @@  discard block
 block discarded – undo
125 125
  * @return void
126 126
  */
127 127
 function monsterinsights_process_export_settings() {
128
-	if ( !isset( $_POST['monsterinsights_action'] ) || empty( $_POST['monsterinsights_action'] ) ) {
129
-		return;
130
-	}
128
+  if ( !isset( $_POST['monsterinsights_action'] ) || empty( $_POST['monsterinsights_action'] ) ) {
129
+    return;
130
+  }
131 131
 
132
-	if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
133
-		return;
134
-	}
132
+  if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
133
+    return;
134
+  }
135 135
 
136
-	if ( $_POST['monsterinsights_action'] !== 'monsterinsights_export_settings' ){
137
-		return;
138
-	}
136
+  if ( $_POST['monsterinsights_action'] !== 'monsterinsights_export_settings' ){
137
+    return;
138
+  }
139 139
 
140
-	if ( empty( $_POST['monsterinsights_export_settings'] ) || ! wp_verify_nonce( $_POST['monsterinsights_export_settings'], 'monsterinsights_export_settings' ) ) {
141
-		return;
142
-	}
140
+  if ( empty( $_POST['monsterinsights_export_settings'] ) || ! wp_verify_nonce( $_POST['monsterinsights_export_settings'], 'monsterinsights_export_settings' ) ) {
141
+    return;
142
+  }
143 143
 	
144
-	$settings = monsterinsights_export_settings();
145
-	ignore_user_abort( true );
144
+  $settings = monsterinsights_export_settings();
145
+  ignore_user_abort( true );
146 146
 
147
-	nocache_headers();
148
-	header( 'Content-Type: application/json; charset=utf-8' );
149
-	header( 'Content-Disposition: attachment; filename=monsterinsights-settings-export-' . date( 'm-d-Y' ) . '.json' );
150
-	header( "Expires: 0" );
147
+  nocache_headers();
148
+  header( 'Content-Type: application/json; charset=utf-8' );
149
+  header( 'Content-Disposition: attachment; filename=monsterinsights-settings-export-' . date( 'm-d-Y' ) . '.json' );
150
+  header( "Expires: 0" );
151 151
 
152
-	echo $settings;
153
-	exit;
152
+  echo $settings;
153
+  exit;
154 154
 }
155 155
 add_action( 'admin_init', 'monsterinsights_process_export_settings' );
156 156
 
157 157
 function monsterinsights_import_settings() {
158 158
 
159
-	if ( !isset( $_POST['monsterinsights_action'] ) || empty( $_POST['monsterinsights_action'] ) ) {
160
-		return;
161
-	}
162
-
163
-	if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
164
-		return;
165
-	}
166
-
167
-	if ( $_POST['monsterinsights_action'] !== 'monsterinsights_import_settings' ){
168
-		return;
169
-	}
170
-
171
-	if ( !wp_verify_nonce( $_POST['monsterinsights_import_settings'], 'monsterinsights_import_settings' ) ) {
172
-		return;
173
-	}
174
-
175
-	$extension = explode( '.', $_FILES['import_file']['name'] );
176
-	$extension = end( $extension );
177
-
178
-	if ( $extension != 'json' ) {
179
-		wp_die( __( 'Please upload a valid .json file', 'google-analytics-for-wordpress' ) );
180
-	}
181
-
182
-	$import_file = $_FILES['import_file']['tmp_name'];
183
-
184
-	if ( empty( $import_file ) ) {
185
-		wp_die( __( 'Please upload a file to import', 'google-analytics-for-wordpress' ) );
186
-	}
187
-
188
-	$file     = file_get_contents( $import_file );
189
-	if ( empty( $file ) ) {
190
-		wp_die( __( 'Please upload a real settings export file to import', 'google-analytics-for-wordpress' ) );
191
-	}
192
-
193
-	// Retrieve the settings from the file and convert the json object to an array.
194
-	$new_settings = json_decode( wp_json_encode( json_decode( $file ) ), true );
195
-	$settings     = monsterinsights_get_options();
196
-	$exclude      = array( 
197
-						'analytics_profile',
198
-						'analytics_profile_code',
199
-						'analytics_profile_name',
200
-						'oauth_version',
201
-						'cron_last_run',
202
-						'monsterinsights_oauth_status',
203
-	);
204
-
205
-	foreach ( $exclude as $e ) {
206
-		if ( ! empty( $new_settings[ $e ] ) ) {
207
-			unset( $new_settings[ $e ] );
208
-		}
209
-	}
210
-
211
-	if ( ! is_super_admin() ) {
212
-		if ( ! empty( $new_settings[ 'custom_code' ] ) ) {
213
-			unset( $new_settings[ 'custom_code' ] );
214
-		}
215
-	}
216
-
217
-	foreach ( $exclude as $e ) {
218
-		if ( ! empty( $settings[ $e ] ) ) {
219
-			$new_settings = $settings[ $e ];
220
-		}
221
-	}
222
-
223
-	global $monsterinsights_settings;
224
-	$monsterinsights_settings = $new_settings;
225
-
226
-	update_option( monsterinsights_get_option_name(), $new_settings );
227
-	wp_safe_redirect( admin_url( 'admin.php?page=monsterinsights_tools&action=import&result=success#monsterinsights-main-tab-settings' ) ); exit;
159
+  if ( !isset( $_POST['monsterinsights_action'] ) || empty( $_POST['monsterinsights_action'] ) ) {
160
+    return;
161
+  }
162
+
163
+  if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
164
+    return;
165
+  }
166
+
167
+  if ( $_POST['monsterinsights_action'] !== 'monsterinsights_import_settings' ){
168
+    return;
169
+  }
170
+
171
+  if ( !wp_verify_nonce( $_POST['monsterinsights_import_settings'], 'monsterinsights_import_settings' ) ) {
172
+    return;
173
+  }
174
+
175
+  $extension = explode( '.', $_FILES['import_file']['name'] );
176
+  $extension = end( $extension );
177
+
178
+  if ( $extension != 'json' ) {
179
+    wp_die( __( 'Please upload a valid .json file', 'google-analytics-for-wordpress' ) );
180
+  }
181
+
182
+  $import_file = $_FILES['import_file']['tmp_name'];
183
+
184
+  if ( empty( $import_file ) ) {
185
+    wp_die( __( 'Please upload a file to import', 'google-analytics-for-wordpress' ) );
186
+  }
187
+
188
+  $file     = file_get_contents( $import_file );
189
+  if ( empty( $file ) ) {
190
+    wp_die( __( 'Please upload a real settings export file to import', 'google-analytics-for-wordpress' ) );
191
+  }
192
+
193
+  // Retrieve the settings from the file and convert the json object to an array.
194
+  $new_settings = json_decode( wp_json_encode( json_decode( $file ) ), true );
195
+  $settings     = monsterinsights_get_options();
196
+  $exclude      = array( 
197
+            'analytics_profile',
198
+            'analytics_profile_code',
199
+            'analytics_profile_name',
200
+            'oauth_version',
201
+            'cron_last_run',
202
+            'monsterinsights_oauth_status',
203
+  );
204
+
205
+  foreach ( $exclude as $e ) {
206
+    if ( ! empty( $new_settings[ $e ] ) ) {
207
+      unset( $new_settings[ $e ] );
208
+    }
209
+  }
210
+
211
+  if ( ! is_super_admin() ) {
212
+    if ( ! empty( $new_settings[ 'custom_code' ] ) ) {
213
+      unset( $new_settings[ 'custom_code' ] );
214
+    }
215
+  }
216
+
217
+  foreach ( $exclude as $e ) {
218
+    if ( ! empty( $settings[ $e ] ) ) {
219
+      $new_settings = $settings[ $e ];
220
+    }
221
+  }
222
+
223
+  global $monsterinsights_settings;
224
+  $monsterinsights_settings = $new_settings;
225
+
226
+  update_option( monsterinsights_get_option_name(), $new_settings );
227
+  wp_safe_redirect( admin_url( 'admin.php?page=monsterinsights_tools&action=import&result=success#monsterinsights-main-tab-settings' ) ); exit;
228 228
 }
229 229
 add_action( 'admin_init', 'monsterinsights_import_settings' );
230 230
\ No newline at end of file
Please login to merge, or discard this patch.