MonsterInsights_Lite

Main plugin class.

Defined (1)

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

/googleanalytics.php  
  1. final class MonsterInsights_Lite { 
  2.  
  3. /** 
  4. * Holds the class object. 
  5. * @since 6.0.0 
  6. * @access public 
  7. * @var object Instance of instantiated MonsterInsights class. 
  8. */ 
  9. public static $instance; 
  10.  
  11. /** 
  12. * Plugin version, used for cache-busting of style and script file references. 
  13. * @since 6.0.0 
  14. * @access public 
  15. * @var string $version Plugin version. 
  16. */ 
  17. public $version = '6.1.7'; 
  18.  
  19. /** 
  20. * Plugin file. 
  21. * @since 6.0.0 
  22. * @access public 
  23. * @var string $file PHP File constant for main file. 
  24. */ 
  25. public $file = __FILE__; 
  26.  
  27. /** 
  28. * The name of the plugin. 
  29. * @since 6.0.0 
  30. * @access public 
  31. * @var string $plugin_name Plugin name. 
  32. */ 
  33. public $plugin_name = 'MonsterInsights Lite'; 
  34.  
  35. /** 
  36. * Unique plugin slug identifier. 
  37. * @since 6.0.0 
  38. * @access public 
  39. * @var string $plugin_slug Plugin slug. 
  40. */ 
  41. public $plugin_slug = 'monsterinsights-lite'; 
  42.  
  43. /** 
  44. * Holds instance of MonsterInsights Admin Notice class. 
  45. * @since 6.0.0 
  46. * @access public 
  47. * @var MonsterInsights_Admin_Notice $notices Instance of Admin Notice class. 
  48. */ 
  49. public $notices; 
  50.  
  51. /** 
  52. * Holds instance of MonsterInsights License class. 
  53. * @since 6.0.0 
  54. * @access public 
  55. * @var MonsterInsights_License $license Instance of License class. 
  56. */ 
  57. public $license; 
  58.  
  59. /** 
  60. * Holds instance of MonsterInsights GA class. 
  61. * @since 6.0.0 
  62. * @access public 
  63. * @var MonsterInsights_GA $ga Instance of GA class. 
  64. */ 
  65. protected $ga; 
  66.  
  67. /** 
  68. * Primary class constructor. 
  69. * @since 6.0.0 
  70. * @access public 
  71. */ 
  72. public function __construct() { 
  73. // We don't use this 
  74.  
  75. /** 
  76. * Returns the singleton instance of the class. 
  77. * @access public 
  78. * @since 6.0.0 
  79. * @return object The MonsterInsights_Lite object. 
  80. */ 
  81. public static function get_instance() { 
  82.  
  83. if ( ! isset( self::$instance ) && ! ( self::$instance instanceof MonsterInsights_Lite ) ) { 
  84. self::$instance = new MonsterInsights_Lite(); 
  85.  
  86. global $wp_version; 
  87.  
  88. // Detect non-supported WordPress version and return early 
  89. if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'MONSTERINSIGHTS_FORCE_ACTIVATION' ) || ! MONSTERINSIGHTS_FORCE_ACTIVATION ) ) { 
  90. add_action( 'admin_notices', array( self::$instance, 'monsterinsights_wp_notice' ) ); 
  91. return; 
  92.  
  93. // Detect Pro version and return early 
  94. if ( class_exists( 'MonsterInsights' ) && defined( 'GAWP_VERSION' ) ) { 
  95. add_action( 'admin_notices', array( self::$instance, 'monsterinsights_pro_notice' ) ); 
  96. return; 
  97.  
  98. if ( defined( 'GAWP_ECOMMERCE_PATH' ) ) { 
  99. add_action( 'admin_notices', array( self::$instance, 'monsterinsights_old_ecommerce' ) ); 
  100.  
  101. // Define constants 
  102. self::$instance->define_globals(); 
  103.  
  104. // Load in settings 
  105. self::$instance->load_settings(); 
  106.  
  107. // Load files 
  108. self::$instance->require_files(); 
  109.  
  110. // This does the version to version background upgrade routines and initial install 
  111. $mi_version = get_option( 'monsterinsights_current_version', '5.5.3' ); 
  112. if ( version_compare( $mi_version, '6.0.11', '<' ) ) { 
  113. monsterinsights_lite_call_install_and_upgrade(); 
  114.  
  115. // Load the plugin textdomain. 
  116. add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) ); 
  117.  
  118. // Load GA for admin, lazyload for frontend 
  119. if ( is_admin() ) { 
  120. self::$instance->ga = new MonsterInsights_GA(); 
  121.  
  122. // Load admin only components. 
  123. if ( is_admin() ) { 
  124. self::$instance->notices = new MonsterInsights_Notice_Admin(); 
  125. self::$instance->license = new MonsterInsights_License(); 
  126. self::$instance->reports = new MonsterInsights_Reporting(); 
  127. add_action( 'admin_init', array( self::$instance, 'require_updater' ) ); 
  128.  
  129. // Run hook to load MonsterInsights addons. 
  130. do_action( 'monsterinsights_load_plugins' ); // the updater class for each addon needs to be instantiated via `monsterinsights_updater` 
  131.  
  132. return self::$instance; 
  133.  
  134.  
  135. /** 
  136. * Throw error on object clone 
  137. * The whole idea of the singleton design pattern is that there is a single 
  138. * object therefore, we don't want the object to be cloned. 
  139. * @since 6.0.0 
  140. * @access public 
  141. * @return void 
  142. */ 
  143. public function __clone() { 
  144. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'google-analytics-for-wordpress' ), '6.0.0' ); 
  145.  
  146. /** 
  147. * Disable unserializing of the class 
  148. * Attempting to wakeup an MonsterInsights instance will throw a doing it wrong notice. 
  149. *  
  150. * @since 6.0.0 
  151. * @access public 
  152. * @return void 
  153. */ 
  154. public function __wakeup() { 
  155. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'google-analytics-for-wordpress' ), '6.0.0' ); 
  156.  
  157. /** 
  158. * Magic get function. 
  159. * We use this to lazy load certain functionality. Right now used to lazyload 
  160. * the Google Object for frontend, so it's only loaded if user is using a plugin 
  161. * that requires it. 
  162. * @since 6.0.10 
  163. * @access public 
  164. * @return void 
  165. */ 
  166. public function __get( $key ) { 
  167. if ( $key === 'ga' ) { 
  168. if ( empty( self::$instance->ga ) ) { 
  169. // LazyLoad GA for Frontend 
  170. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php'; 
  171. self::$instance->ga = new MonsterInsights_GA(); 
  172. return self::$instance->$key; 
  173. } else { 
  174. return self::$instance->$key; 
  175.  
  176. /** 
  177. * Define MonsterInsights constants. 
  178. * This function defines all of the MonsterInsights PHP constants. 
  179. * @since 6.0.0 
  180. * @access public 
  181. * @return void 
  182. */ 
  183. public function define_globals() { 
  184.  
  185. if ( ! defined( 'MONSTERINSIGHTS_VERSION' ) ) { 
  186. define( 'MONSTERINSIGHTS_VERSION', $this->version ); 
  187.  
  188. if ( ! defined( 'MONSTERINSIGHTS_LITE_VERSION' ) ) { 
  189. define( 'MONSTERINSIGHTS_LITE_VERSION', MONSTERINSIGHTS_VERSION ); 
  190.  
  191. if ( ! defined( 'GAWP_VERSION' ) ) { 
  192. define( 'GAWP_VERSION', MONSTERINSIGHTS_VERSION ); 
  193.  
  194. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_NAME' ) ) { 
  195. define( 'MONSTERINSIGHTS_PLUGIN_NAME', $this->plugin_name ); 
  196.  
  197. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_SLUG' ) ) { 
  198. define( 'MONSTERINSIGHTS_PLUGIN_SLUG', $this->plugin_slug ); 
  199.  
  200. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_FILE' ) ) { 
  201. define( 'MONSTERINSIGHTS_PLUGIN_FILE', $this->file ); 
  202.  
  203. if ( ! defined( 'GAWP_FILE' ) ) { 
  204. define( 'GAWP_FILE', MONSTERINSIGHTS_PLUGIN_FILE ); 
  205.  
  206. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_DIR' ) ) { 
  207. define( 'MONSTERINSIGHTS_PLUGIN_DIR', plugin_dir_path( $this->file ) ); 
  208.  
  209. if ( ! defined( 'GAWP_PATH' ) ) { 
  210. define( 'GAWP_PATH', MONSTERINSIGHTS_PLUGIN_FILE ); 
  211.  
  212. if ( ! defined( 'MONSTERINSIGHTS_PLUGIN_URL' ) ) { 
  213. define( 'MONSTERINSIGHTS_PLUGIN_URL', plugin_dir_url( $this->file ) ); 
  214.  
  215. if ( ! defined( 'GAWP_URL' ) ) { 
  216. define( 'GAWP_URL', MONSTERINSIGHTS_PLUGIN_URL ); 
  217. }  
  218.  
  219. /** 
  220. * Loads the plugin textdomain for translation. 
  221. * @access public 
  222. * @since 6.0.0 
  223. * @return void 
  224. */ 
  225. public function load_plugin_textdomain() { 
  226.  
  227. $mi_locale = get_locale(); 
  228. if ( function_exists( 'get_user_locale' ) ) { 
  229. $mi_locale = get_user_locale(); 
  230.  
  231. // Traditional WordPress plugin locale filter. 
  232. $mi_locale = apply_filters( 'plugin_locale', $mi_locale, 'google-analytics-for-wordpress' ); 
  233. $mi_mofile = sprintf( '%1$s-%2$s.mo', 'google-analytics-for-wordpress', $mi_locale );  
  234.  
  235. // Look for wp-content/languages/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo 
  236. $mi_mofile1 = WP_LANG_DIR . '/google-analytics-for-wordpress/' . $mi_mofile; 
  237.  
  238. // Look in wp-content/languages/plugins/google-analytics-for-wordpress/google-analytics-for-wordpress-{lang}_{country}.mo 
  239. $mi_mofile2 = WP_LANG_DIR . '/plugins/google-analytics-for-wordpress/' . $mi_mofile; 
  240.  
  241. // Look in wp-content/languages/plugins/google-analytics-for-wordpress-{lang}_{country}.mo 
  242. $mi_mofile3 = WP_LANG_DIR . '/plugins/' . $mi_mofile; 
  243.  
  244. // Look in wp-content/plugins/google-analytics-for-wordpress/languages/google-analytics-for-wordpress-{lang}_{country}.mo 
  245. $mi_mofile4 = dirname( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ) . '/languages/'; 
  246. $mi_mofile4 = apply_filters( 'monsterinsights_lite_languages_directory', $mi_mofile4 ); 
  247.  
  248. if ( file_exists( $mi_mofile1 ) ) { 
  249. load_textdomain( 'google-analytics-for-wordpress', $mi_mofile1 ); 
  250. } elseif ( file_exists( $mi_mofile2 ) ) { 
  251. load_textdomain( 'google-analytics-for-wordpress', $mi_mofile2 ); 
  252. } elseif ( file_exists( $mi_mofile3 ) ) { 
  253. load_textdomain( 'google-analytics-for-wordpress', $mi_mofile3 ); 
  254. } else { 
  255. load_plugin_textdomain( 'google-analytics-for-wordpress', false, $mi_mofile4 ); 
  256.  
  257.  
  258.  
  259. /** 
  260. * Output notice to update eCommerce 
  261. * @access public 
  262. * @since 6.0.0 
  263. * @return void 
  264. */ 
  265. public function monsterinsights_old_ecommerce() { 
  266. ?> 
  267. <div class="error"> 
  268. <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> 
  269. </div> 
  270. <?php 
  271.  
  272.  
  273. /** 
  274. * Output a nag notice if the user has an out of date WP version installed 
  275. * @access public 
  276. * @since 6.0.0 
  277. * @return void 
  278. */ 
  279. public function monsterinsights_wp_notice() { 
  280. $url = admin_url( 'plugins.php' ); 
  281. // Check for MS dashboard 
  282. if( is_network_admin() ) { 
  283. $url = network_admin_url( 'plugins.php' ); 
  284. ?> 
  285. <div class="error"> 
  286. <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> 
  287. </div> 
  288. <?php 
  289.  
  290. /** 
  291. * Output a nag notice if the user has both Lite and Pro activated 
  292. * @access public 
  293. * @since 6.0.0 
  294. * @return void 
  295. */ 
  296. public function monsterinsights_pro_notice() { 
  297. $url = admin_url( 'plugins.php' ); 
  298. // Check for MS dashboard 
  299. if( is_network_admin() ) { 
  300. $url = network_admin_url( 'plugins.php' ); 
  301. ?> 
  302. <div class="error"> 
  303. <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> 
  304. </div> 
  305. <?php 
  306.  
  307.  
  308. /** 
  309. * Loads MonsterInsights settings 
  310. * Adds the items to the base object, and adds the helper functions. 
  311. * @since 6.0.0 
  312. * @access public 
  313. *  
  314. * @return void 
  315. */ 
  316. public function load_settings() { 
  317. global $monsterinsights_settings; 
  318. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/options.php'; 
  319. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/helpers.php'; 
  320. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/deprecated.php'; 
  321. $monsterinsights_settings = monsterinsights_get_options(); 
  322.  
  323. /** 
  324. * Loads all files into scope. 
  325. * @access public 
  326. * @since 6.0.0 
  327. * @return void 
  328. */ 
  329. public function require_files() { 
  330.  
  331. if ( is_admin() ) { 
  332.  
  333. // Lite and Pro files 
  334. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/ajax.php'; 
  335. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/admin.php'; 
  336. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/common.php'; 
  337. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/notice.php'; 
  338. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/capabilities.php'; 
  339. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/license.php'; 
  340.  
  341. // Pages 
  342. // Multisite 
  343. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/network-settings.php'; 
  344.  
  345. // Single Site 
  346. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/dashboard.php'; 
  347. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/settings.php'; 
  348. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/tools.php'; 
  349. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/reports.php'; 
  350.  
  351. // Both  
  352. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/pages/addons.php'; 
  353.  
  354. // Settings Tabs 
  355. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-general.php'; 
  356. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-tracking.php'; 
  357. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-status.php'; 
  358. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/tab-support.php'; 
  359.  
  360. // Register Settings + Settings API 
  361. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/settings-api.php'; 
  362. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/settings/register-settings.php';  
  363.  
  364. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reporting.php'; 
  365. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/abstract-report.php'; 
  366.  
  367. // Load Google Config 
  368. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/google.php'; 
  369.  
  370. // Lazy Load for Frontend. Load for Admin. 
  371. if ( is_admin() ) { 
  372. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php'; 
  373.  
  374. if ( is_admin() ) { 
  375. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/googleauth.php'; 
  376. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/addons.php'; 
  377. //require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/tab-support.php'; 
  378.  
  379. // Late loading classes (self instantiating) 
  380. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/reports/overview.php'; 
  381. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/tracking.php'; 
  382.  
  383. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/frontend/frontend.php'; 
  384.  
  385. /** 
  386. * Loads all updater related files and functions into scope. 
  387. * @access public 
  388. * @since 6.0.0 
  389. * @return null Return early if the license key is not set or there are key errors. 
  390. */ 
  391. public function require_updater() { 
  392.  
  393. // Retrieve the license key. If it is not set, return early. 
  394. $key = monsterinsights_get_license_key(); 
  395. if ( ! $key ) { 
  396. return; 
  397.  
  398. // If there are any errors with the key itself, return early. 
  399. if ( monsterinsights_get_license_key_errors() ) { 
  400. return; 
  401.  
  402. // Load the updater class. 
  403. require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/licensing/updater.php'; 
  404.  
  405. // Fire a hook for Addons to register their updater since we know the key is present. 
  406. do_action( 'monsterinsights_updater', $key );