googleanalytics.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. <?php
  2. /**
  3. * Plugin Name: Google Analytics for WordPress by MonsterInsights
  4. * Plugin URI: https://www.monsterinsights.com/?utm_source=liteplugin&utm_medium=pluginheader&utm_campaign=pluginurl&utm_content=7%2E0%2E0
  5. * Description: The best Google Analytics plugin for WordPress. See how visitors find and use your website, so you can keep them coming back.
  6. * Author: MonsterInsights
  7. * Author URI: https://www.monsterinsights.com/?utm_source=liteplugin&utm_medium=pluginheader&utm_campaign=authoruri&utm_content=7%2E0%2E0
  8. *
  9. * Version: 7.2.0
  10. * Requires at least: 3.8.0
  11. * Tested up to: 4.9
  12. *
  13. * License: GPL v3
  14. *
  15. * Text Domain: google-analytics-for-wordpress
  16. * Domain Path: /languages
  17. *
  18. * MonsterInsights Lite
  19. * Copyright (C) 2008-2018, MonsterInsights, support@monsterinsights.com
  20. *
  21. * This program is free software: you can redistribute it and/or modify
  22. * it under the terms of the GNU General Public License as published by
  23. * the Free Software Foundation, either version 3 of the License, or
  24. * (at your option) any later version.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU General Public License
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  33. *
  34. * @category Plugin
  35. * @copyright Copyright © 2018 Chris Christoff
  36. * @author Chris Christoff
  37. * @package MonsterInsights
  38. */
  39. // Exit if accessed directly.
  40. if ( ! defined( 'ABSPATH' ) ) {
  41. exit;
  42. }
  43. /**
  44. * Main plugin class.
  45. *
  46. * @since 6.0.0
  47. *
  48. * @package MonsterInsights
  49. * @author Chris Christoff
  50. * @access public
  51. */
  52. final class MonsterInsights_Lite {
  53. /**
  54. * Holds the class object.
  55. *
  56. * @since 6.0.0
  57. * @access public
  58. * @var object Instance of instantiated MonsterInsights class.
  59. */
  60. public static $instance;
  61. /**
  62. * Plugin version, used for cache-busting of style and script file references.
  63. *
  64. * @since 6.0.0
  65. * @access public
  66. * @var string $version Plugin version.
  67. */
  68. public $version = '7.2.0';
  69. /**
  70. * Plugin file.
  71. *
  72. * @since 6.0.0
  73. * @access public
  74. * @var string $file PHP File constant for main file.
  75. */
  76. public $file;
  77. /**
  78. * The name of the plugin.
  79. *
  80. * @since 6.0.0
  81. * @access public
  82. * @var string $plugin_name Plugin name.
  83. */
  84. public $plugin_name = 'MonsterInsights Lite';
  85. /**
  86. * Unique plugin slug identifier.
  87. *
  88. * @since 6.0.0
  89. * @access public
  90. * @var string $plugin_slug Plugin slug.
  91. */
  92. public $plugin_slug = 'monsterinsights-lite';
  93. /**
  94. * Holds instance of MonsterInsights License class.
  95. *
  96. * @since 6.0.0
  97. * @access public
  98. * @var MonsterInsights_License $license Instance of License class.
  99. */
  100. protected $license;
  101. /**
  102. * Holds instance of MonsterInsights License Actions class.
  103. *
  104. * @since 6.0.0
  105. * @access public
  106. * @var MonsterInsights_License_Actions $license_actions Instance of License Actions class.
  107. */
  108. public $license_actions;
  109. /**
  110. * Holds instance of MonsterInsights Admin Notice class.
  111. *
  112. * @since 6.0.0
  113. * @access public
  114. * @var MonsterInsights_Admin_Notice $notices Instance of Admin Notice class.
  115. */
  116. public $notices;
  117. /**
  118. * Holds instance of MonsterInsights Reporting class.
  119. *
  120. * @since 6.0.0
  121. * @access public
  122. * @var MonsterInsights_Reporting $reporting Instance of Reporting class.
  123. */
  124. public $reporting;
  125. /**
  126. * Holds instance of MonsterInsights Auth class.
  127. *
  128. * @since 7.0.0
  129. * @access public
  130. * @var MonsterInsights_Auth $auth Instance of Auth class.
  131. */
  132. protected $auth;
  133. /**
  134. * Holds instance of MonsterInsights API Auth class.
  135. *
  136. * @since 6.0.0
  137. * @access public
  138. * @var MonsterInsights_Auth $api_auth Instance of APIAuth class.
  139. */
  140. public $api_auth;
  141. /**
  142. * Primary class constructor.
  143. *
  144. * @since 6.0.0
  145. * @access public
  146. */
  147. public function __construct() {
  148. // We don't use this
  149. }
  150. /**
  151. * Returns the singleton instance of the class.
  152. *
  153. * @access public
  154. * @since 6.0.0
  155. *
  156. * @return object The MonsterInsights_Lite object.
  157. */
  158. public static function get_instance() {
  159. if ( ! isset( self::$instance ) && ! ( self::$instance instanceof MonsterInsights_Lite ) ) {
  160. self::$instance = new MonsterInsights_Lite();
  161. self::$instance->file = __FILE__;
  162. global $wp_version;
  163. // Detect non-supported WordPress version and return early
  164. if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) {
  165. add_action( 'admin_notices', array( self::$instance, 'monsterinsights_wp_notice' ) );
  166. return;
  167. }
  168. // Detect Pro version and return early
  169. if ( class_exists( 'MonsterInsights' ) && defined( 'GAWP_VERSION' ) ) {
  170. add_action( 'admin_notices', array( self::$instance, 'monsterinsights_pro_notice' ) );
  171. return;
  172. }
  173. if ( defined( 'GAWP_ECOMMERCE_PATH' ) ) {
  174. add_action( 'admin_notices', array( self::$instance, 'monsterinsights_old_ecommerce' ) );
  175. }
  176. // Define constants
  177. self::$instance->define_globals();
  178. // Load in settings
  179. self::$instance->load_settings();
  180. // Load in Licensing
  181. self::$instance->load_licensing();
  182. // Load in Auth
  183. self::$instance->load_auth();
  184. // Load files
  185. self::$instance->require_files();
  186. // This does the version to version background upgrade routines and initial install
  187. $mi_version = get_option( 'monsterinsights_current_version', '5.5.3' );
  188. if ( version_compare( $mi_version, '7.0.0', '<' ) ) {
  189. monsterinsights_lite_call_install_and_upgrade();
  190. }
  191. if ( is_admin() ) {
  192. new AM_Notification( 'mi-lite', self::$instance->version );
  193. new AM_Deactivation_Survey( 'MonsterInsights', basename( __DIR__ ) );
  194. }
  195. // Load the plugin textdomain.
  196. add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
  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_actions = new MonsterInsights_License_Actions();
  201. self::$instance->reporting = new MonsterInsights_Reporting();
  202. self::$instance->api_auth = new MonsterInsights_API_Auth();
  203. if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
  204. self::$instance->require_updater();
  205. } else {
  206. add_action( 'admin_init', array( self::$instance, 'require_updater' ) );
  207. }
  208. }
  209. if ( monsterinsights_is_pro_version() ) {
  210. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'pro/includes/load.php';
  211. } else {
  212. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/load.php';
  213. }
  214. // Run hook to load MonsterInsights addons.
  215. do_action( 'monsterinsights_load_plugins' ); // the updater class for each addon needs to be instantiated via `monsterinsights_updater`
  216. }
  217. return self::$instance;
  218. }
  219. /**
  220. * Throw error on object clone
  221. *
  222. * The whole idea of the singleton design pattern is that there is a single
  223. * object therefore, we don't want the object to be cloned.
  224. *
  225. * @since 6.0.0
  226. * @access public
  227. *
  228. * @return void
  229. */
  230. public function __clone() {
  231. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
  232. }
  233. /**
  234. * Disable unserializing of the class
  235. *
  236. * Attempting to wakeup an MonsterInsights instance will throw a doing it wrong notice.
  237. *
  238. * @since 6.0.0
  239. * @access public
  240. *
  241. * @return void
  242. */
  243. public function __wakeup() {
  244. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
  245. }
  246. /**
  247. * Magic get function.
  248. *
  249. * We use this to lazy load certain functionality. Right now used to lazyload
  250. * the API & Auth frontend, so it's only loaded if user is using a plugin
  251. * that requires it.
  252. *
  253. * @since 7.0.0
  254. * @access public
  255. *
  256. * @return void
  257. */
  258. public function __get( $key ) {
  259. if ( $key === 'auth' ) {
  260. if ( empty( self::$instance->auth ) ) {
  261. // LazyLoad Auth for Frontend
  262. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/auth.php';
  263. self::$instance->auth = new MonsterInsights_Auth();
  264. }
  265. return self::$instance->$key;
  266. } else if ( $key === 'license' ) {
  267. if ( empty( self::$instance->license ) ) {
  268. // LazyLoad Licensing for Frontend
  269. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/license.php';
  270. self::$instance->license = new MonsterInsights_License();
  271. }
  272. return self::$instance->$key;
  273. } else {
  274. return self::$instance->$key;
  275. }
  276. }
  277. /**
  278. * Define MonsterInsights constants.
  279. *
  280. * This function defines all of the MonsterInsights PHP constants.
  281. *
  282. * @since 6.0.0
  283. * @access public
  284. *
  285. * @return void
  286. */
  287. public function define_globals() {
  288. if ( ! defined( 'MONSTERINSIGHTS_VERSION' ) ) {
  289. define( 'MONSTERINSIGHTS_VERSION', $this->version );
  290. }
  291. if ( ! defined( 'MONSTERINSIGHTS_LITE_VERSION' ) ) {
  292. define( 'MONSTERINSIGHTS_LITE_VERSION', MONSTERINSIGHTS_VERSION );
  293. }
  294. if ( ! defined( 'GAWP_VERSION' ) ) {
  295. define( 'GAWP_VERSION', MONSTERINSIGHTS_VERSION );
  296. }
  297. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_NAME' ) ) {
  298. define( 'MONSTERINSIGHTS_PLUGIN_NAME', $this->plugin_name );
  299. }
  300. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_SLUG' ) ) {
  301. define( 'MONSTERINSIGHTS_PLUGIN_SLUG', $this->plugin_slug );
  302. }
  303. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_FILE' ) ) {
  304. define( 'MONSTERINSIGHTS_PLUGIN_FILE', $this->file );
  305. }
  306. if ( ! defined( 'GAWP_FILE' ) ) {
  307. define( 'GAWP_FILE', MONSTERINSIGHTS_PLUGIN_FILE );
  308. }
  309. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_DIR' ) ) {
  310. define( 'MONSTERINSIGHTS_PLUGIN_DIR', plugin_dir_path( $this->file ) );
  311. }
  312. if ( ! defined( 'GAWP_PATH' ) ) {
  313. define( 'GAWP_PATH', MONSTERINSIGHTS_PLUGIN_DIR );
  314. }
  315. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_URL' ) ) {
  316. define( 'MONSTERINSIGHTS_PLUGIN_URL', plugin_dir_url( $this->file ) );
  317. }
  318. if ( ! defined( 'GAWP_URL' ) ) {
  319. define( 'GAWP_URL', MONSTERINSIGHTS_PLUGIN_URL );
  320. }
  321. }
  322. /**
  323. * Loads the plugin textdomain for translation.
  324. *
  325. * @access public
  326. * @since 6.0.0
  327. *
  328. * @return void
  329. */
  330. public function load_plugin_textdomain() {
  331. $mi_locale = get_locale();
  332. if ( function_exists( 'get_user_locale' ) ) {
  333. $mi_locale = get_user_locale();
  334. }
  335. // Traditional WordPress plugin locale filter.
  336. $mi_locale = apply_filters( 'plugin_locale', $mi_locale, 'google-analytics-for-wordpress' );
  337. $mi_mofile = sprintf( '%1$s-%2$s.mo', 'google-analytics-for-wordpress', $mi_locale );
  338. // Look for wp-content/languages/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo
  339. $mi_mofile1 = WP_LANG_DIR . '/google-analytics-for-wordpress/' . $mi_mofile;
  340. // Look in wp-content/languages/plugins/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo
  341. $mi_mofile2 = WP_LANG_DIR . '/plugins/google-analytics-for-wordpress/' . $mi_mofile;
  342. // Look in wp-content/languages/plugins/google-analytics-for-wordpress-{lang}_{country}.mo
  343. $mi_mofile3 = WP_LANG_DIR . '/plugins/' . $mi_mofile;
  344. // Look in wp-content/plugins/google-analytics-for-wordpress/languages/google-analytics-for-wordpress-{lang}_{country}.mo
  345. $mi_mofile4 = dirname( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ) . '/languages/';
  346. $mi_mofile4 = apply_filters( 'monsterinsights_lite_languages_directory', $mi_mofile4 );
  347. if ( file_exists( $mi_mofile1 ) ) {
  348. load_textdomain( 'google-analytics-for-wordpress', $mi_mofile1 );
  349. } elseif ( file_exists( $mi_mofile2 ) ) {
  350. load_textdomain( 'google-analytics-for-wordpress', $mi_mofile2 );
  351. } elseif ( file_exists( $mi_mofile3 ) ) {
  352. load_textdomain( 'google-analytics-for-wordpress', $mi_mofile3 );
  353. } else {
  354. load_plugin_textdomain( 'google-analytics-for-wordpress', false, $mi_mofile4 );
  355. }
  356. }
  357. /**
  358. * Output notice to update eCommerce
  359. *
  360. * @access public
  361. * @since 6.0.0
  362. *
  363. * @return void
  364. */
  365. public function monsterinsights_old_ecommerce() {
  366. ?>
  367. <div class="error">
  368. <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>
  369. </div>
  370. <?php
  371. }
  372. /**
  373. * Output a nag notice if the user has an out of date WP version installed
  374. *
  375. * @access public
  376. * @since 6.0.0
  377. *
  378. * @return void
  379. */
  380. public function monsterinsights_wp_notice() {
  381. $url = admin_url( 'plugins.php' );
  382. // Check for MS dashboard
  383. if( is_network_admin() ) {
  384. $url = network_admin_url( 'plugins.php' );
  385. }
  386. ?>
  387. <div class="error">
  388. <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>
  389. </div>
  390. <?php
  391. }
  392. /**
  393. * Output a nag notice if the user has both Lite and Pro activated
  394. *
  395. * @access public
  396. * @since 6.0.0
  397. *
  398. * @return void
  399. */
  400. public function monsterinsights_pro_notice() {
  401. $url = admin_url( 'plugins.php' );
  402. // Check for MS dashboard
  403. if( is_network_admin() ) {
  404. $url = network_admin_url( 'plugins.php' );
  405. }
  406. ?>
  407. <div class="error">
  408. <p><?php echo sprintf( esc_html__( 'Please %1$suninstall%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>
  409. </div>
  410. <?php
  411. }
  412. /**
  413. * Loads MonsterInsights settings
  414. *
  415. * Adds the items to the base object, and adds the helper functions.
  416. *
  417. * @since 6.0.0
  418. * @access public
  419. *
  420. * @return void
  421. */
  422. public function load_settings() {
  423. global $monsterinsights_settings;
  424. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/options.php';
  425. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/helpers.php';
  426. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/deprecated.php';
  427. $monsterinsights_settings = monsterinsights_get_options();
  428. }
  429. /**
  430. * Loads MonsterInsights License
  431. *
  432. * Loads license class used by MonsterInsights
  433. *
  434. * @since 7.0.0
  435. * @access public
  436. *
  437. * @return void
  438. */
  439. public function load_licensing(){
  440. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  441. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/license.php';
  442. self::$instance->license = new MonsterInsights_License();
  443. }
  444. }
  445. /**
  446. * Loads MonsterInsights Auth
  447. *
  448. * Loads auth used by MonsterInsights
  449. *
  450. * @since 7.0.0
  451. * @access public
  452. *
  453. * @return void
  454. */
  455. public function load_auth() {
  456. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  457. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/auth.php';
  458. self::$instance->auth = new MonsterInsights_Auth();
  459. }
  460. }
  461. /**
  462. * Loads all files into scope.
  463. *
  464. * @access public
  465. * @since 6.0.0
  466. *
  467. * @return void
  468. */
  469. public function require_files() {
  470. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  471. // Lite and Pro files
  472. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-notification.php';
  473. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-deactivation-survey.php';
  474. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'assets/lib/pandora/class-am-dashboard-widget-extend-feed.php';
  475. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/ajax.php';
  476. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/admin.php';
  477. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/common.php';
  478. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notice.php';
  479. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/capabilities.php';
  480. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/license-actions.php';
  481. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/autoupdate.php';
  482. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/review.php';
  483. // Pages
  484. // Multisite
  485. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/network-settings.php';
  486. // Single Site
  487. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/settings.php';
  488. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/tracking.php';
  489. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/tools.php';
  490. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/reports.php';
  491. // Both
  492. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/addons.php';
  493. // Settings Tabs
  494. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-general.php';
  495. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-tracking.php';
  496. //require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-status.php';
  497. //require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-support.php';
  498. // Register Settings + Settings API
  499. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/settings-api.php';
  500. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/register-settings.php';
  501. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/api-auth.php';
  502. // Reports
  503. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/abstract-report.php';
  504. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/overview.php';
  505. // Reporting Functionality
  506. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reporting.php';
  507. }
  508. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/api-request.php';
  509. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  510. // Late loading classes (self instantiating)
  511. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/tracking.php';
  512. }
  513. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/frontend.php';
  514. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/measurement-protocol.php';
  515. }
  516. /**
  517. * Loads all updater related files and functions into scope.
  518. *
  519. * @access public
  520. * @since 6.0.0
  521. *
  522. * @return null Return early if the license key is not set or there are key errors.
  523. */
  524. public function require_updater() {
  525. // Retrieve the license key. If it is not set or if there are issues, return early.
  526. $key = self::$instance->license->get_valid_license_key();
  527. if ( ! $key ) {
  528. return;
  529. }
  530. // Load the updater class.
  531. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/updater.php';
  532. // Fire a hook for Addons to register their updater since we know the key is present.
  533. do_action( 'monsterinsights_updater', $key );
  534. }
  535. }
  536. /**
  537. * Fired when the plugin is activated.
  538. *
  539. * @access public
  540. * @since 6.0.0
  541. *
  542. * @global int $wp_version The version of WordPress for this install.
  543. * @global object $wpdb The WordPress database object.
  544. * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false otherwise.
  545. *
  546. * @return void
  547. */
  548. function monsterinsights_lite_activation_hook( $network_wide ) {
  549. global $wp_version;
  550. $url = admin_url( 'plugins.php' );
  551. // Check for MS dashboard
  552. if ( is_network_admin() ) {
  553. $url = network_admin_url( 'plugins.php' );
  554. }
  555. if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) {
  556. deactivate_plugins( plugin_basename( __FILE__ ) );
  557. 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>' ) );
  558. }
  559. if ( class_exists( 'MonsterInsights' ) ) {
  560. deactivate_plugins( plugin_basename( __FILE__ ) );
  561. wp_die( sprintf( esc_html__( 'Please uninstall and remove MonsterInsights Pro before activating Google Analytics for WordPress by MonsterInsights. 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>' ) );
  562. }
  563. }
  564. register_activation_hook( __FILE__, 'monsterinsights_lite_activation_hook' );
  565. /**
  566. * Fired when the plugin is uninstalled.
  567. *
  568. * @access public
  569. * @since 6.0.0
  570. *
  571. * @return void
  572. */
  573. function monsterinsights_lite_uninstall_hook( $network_wide ) {
  574. wp_cache_flush();
  575. // Note, if both MI Pro and Lite are active, this is an MI Pro instance
  576. // Therefore MI Lite can only use functions of the instance common to
  577. // both plugins. If it needs to be pro specific, then include a file that
  578. // has that method.
  579. $instance = MonsterInsights();
  580. if ( is_multisite() && $network_wide ) {
  581. // Delete network auth
  582. $instance->api_auth->delete_auth();
  583. // Delete network data
  584. $instance->reporting->delete_aggregate_data('network');
  585. // Delete network license
  586. $instance->license->delete_network_license();
  587. $site_list = get_sites();
  588. foreach ( (array) $site_list as $site ) {
  589. switch_to_blog( $site->blog_id );
  590. // Delete auth
  591. $instance->api_auth->delete_auth();
  592. // Delete data
  593. $instance->reporting->delete_aggregate_data('site');
  594. // Delete license
  595. $instance->license->delete_site_license();
  596. restore_current_blog();
  597. }
  598. } else {
  599. // Delete auth
  600. $instance->api_auth->delete_auth();
  601. // Delete data
  602. $instance->reporting->delete_aggregate_data('site');
  603. // Delete license
  604. $instance->license->delete_site_license();
  605. }
  606. }
  607. register_uninstall_hook( __FILE__, 'monsterinsights_lite_uninstall_hook' );
  608. /**
  609. * The main function responsible for returning the one true MonsterInsights_Lite
  610. * Instance to functions everywhere.
  611. *
  612. * Use this function like you would a global variable, except without needing
  613. * to declare the global.
  614. *
  615. * Example: <?php $monsterinsights = MonsterInsights_Lite(); ?>
  616. *
  617. * @since 6.0.0
  618. *
  619. * @uses MonsterInsights_Lite::get_instance() Retrieve MonsterInsights_Lite instance.
  620. *
  621. * @return MonsterInsights_Lite The singleton MonsterInsights_Lite instance.
  622. */
  623. function MonsterInsights_Lite() {
  624. return MonsterInsights_Lite::get_instance();
  625. }
  626. /**
  627. * MonsterInsights Install and Updates.
  628. *
  629. * This function is used install and upgrade MonsterInsights. This is used for upgrade routines
  630. * that can be done automatically, behind the scenes without the need for user interaction
  631. * (for example pagination or user input required), as well as the initial install.
  632. *
  633. * @since 6.0.0
  634. * @access public
  635. *
  636. * @global string $wp_version WordPress version (provided by WordPress core).
  637. * @uses MonsterInsights_Lite::load_settings() Loads MonsterInsights settings
  638. * @uses MonsterInsights_Install::init() Runs upgrade process
  639. *
  640. * @return void
  641. */
  642. function monsterinsights_lite_install_and_upgrade() {
  643. global $wp_version;
  644. // If the WordPress site doesn't meet the correct WP version requirements, don't activate MonsterInsights
  645. if ( version_compare( $wp_version, '3.8', '<' ) ) {
  646. if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
  647. return;
  648. }
  649. }
  650. // Don't run if MI Pro is installed
  651. if ( class_exists( 'MonsterInsights' ) ) {
  652. if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
  653. return;
  654. }
  655. }
  656. // Load settings and globals (so we can use/set them during the upgrade process)
  657. MonsterInsights_Lite()->define_globals();
  658. MonsterInsights_Lite()->load_settings();
  659. // Load in Licensing
  660. MonsterInsights()->load_licensing();
  661. // Load in Auth
  662. MonsterInsights()->load_auth();
  663. // Load upgrade file
  664. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/install.php';
  665. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/install.php'; // Lite only install stuff
  666. // Run the MonsterInsights upgrade routines
  667. $updates = new MonsterInsights_Install();
  668. $updates->init();
  669. }
  670. /**
  671. * MonsterInsights check for install and update processes.
  672. *
  673. * This function is used to call the MonsterInsights automatic upgrade class, which in turn
  674. * checks to see if there are any update procedures to be run, and if
  675. * so runs them. Also installs MonsterInsights for the first time.
  676. *
  677. * @since 6.0.0
  678. * @access public
  679. *
  680. * @uses MonsterInsights_Install() Runs install and upgrade process.
  681. *
  682. * @return void
  683. */
  684. function monsterinsights_lite_call_install_and_upgrade(){
  685. add_action( 'wp_loaded', 'monsterinsights_lite_install_and_upgrade' );
  686. }
  687. /**
  688. * Returns the MonsterInsights combined object that you can use for both
  689. * MonsterInsights Lite and Pro Users. When both plugins active, defers to the
  690. * more complete Pro object.
  691. *
  692. * Warning: Do not use this in Lite or Pro specific code (use the individual objects instead).
  693. * Also do not use in the MonsterInsights Lite/Pro upgrade and install routines.
  694. *
  695. * Use this function like you would a global variable, except without needing
  696. * to declare the global.
  697. *
  698. * Prevents the need to do conditional global object logic when you have code that you want to work with
  699. * both Pro and Lite.
  700. *
  701. * Example: <?php $monsterinsights = MonsterInsights(); ?>
  702. *
  703. * @since 6.0.0
  704. *
  705. * @uses MonsterInsights::get_instance() Retrieve MonsterInsights Pro instance.
  706. * @uses MonsterInsights_Lite::get_instance() Retrieve MonsterInsights Lite instance.
  707. *
  708. * @return MonsterInsights The singleton MonsterInsights instance.
  709. */
  710. if ( ! function_exists( 'MonsterInsights' ) ) {
  711. function MonsterInsights() {
  712. return ( class_exists( 'MonsterInsights' ) ? MonsterInsights_Pro() : MonsterInsights_Lite() );
  713. }
  714. add_action( 'plugins_loaded', 'MonsterInsights' );
  715. }