PageRenderTime 30ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-content/plugins/google-analytics-dashboard-for-wp/gadwp.php

https://gitlab.com/VTTE/sitios-vtte
PHP | 728 lines | 277 code | 99 blank | 352 comment | 56 complexity | 46d1181622167bad88d2aad4fff2a34c MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Name: Google Analytics Dashboard for WP (GADWP)
  4. * Plugin URI: https://exactmetrics.com
  5. * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
  6. * Author: ExactMetrics
  7. * Version: 6.0.2
  8. * Author URI: https://exactmetrics.com
  9. * Text Domain: google-analytics-dashboard-for-wp
  10. * Domain Path: /languages
  11. */
  12. // Exit if accessed directly.
  13. if ( ! defined( 'ABSPATH' ) ) {
  14. exit;
  15. }
  16. /**
  17. * Main plugin class.
  18. *
  19. * @since 6.0.0
  20. *
  21. * @package ExactMetrics
  22. * @author Chris Christoff
  23. * @access public
  24. */
  25. final class ExactMetrics_Lite {
  26. /**
  27. * Holds the class object.
  28. *
  29. * @since 6.0.0
  30. * @access public
  31. * @var object Instance of instantiated ExactMetrics class.
  32. */
  33. public static $instance;
  34. /**
  35. * Plugin version, used for cache-busting of style and script file references.
  36. *
  37. * @since 6.0.0
  38. * @access public
  39. * @var string $version Plugin version.
  40. */
  41. public $version = '6.0.2';
  42. /**
  43. * Plugin file.
  44. *
  45. * @since 6.0.0
  46. * @access public
  47. * @var string $file PHP File constant for main file.
  48. */
  49. public $file;
  50. /**
  51. * The name of the plugin.
  52. *
  53. * @since 6.0.0
  54. * @access public
  55. * @var string $plugin_name Plugin name.
  56. */
  57. public $plugin_name = 'ExactMetrics Lite';
  58. /**
  59. * Unique plugin slug identifier.
  60. *
  61. * @since 6.0.0
  62. * @access public
  63. * @var string $plugin_slug Plugin slug.
  64. */
  65. public $plugin_slug = 'exactmetrics-lite';
  66. /**
  67. * Holds instance of ExactMetrics License class.
  68. *
  69. * @since 6.0.0
  70. * @access public
  71. * @var ExactMetrics_License $license Instance of License class.
  72. */
  73. protected $license;
  74. /**
  75. * Holds instance of ExactMetrics Admin Notice class.
  76. *
  77. * @since 6.0.0
  78. * @access public
  79. * @var ExactMetrics_Admin_Notice $notices Instance of Admin Notice class.
  80. */
  81. public $notices;
  82. /**
  83. * Holds instance of ExactMetrics Reporting class.
  84. *
  85. * @since 6.0.0
  86. * @access public
  87. * @var ExactMetrics_Reporting $reporting Instance of Reporting class.
  88. */
  89. public $reporting;
  90. /**
  91. * Holds instance of ExactMetrics Auth class.
  92. *
  93. * @since 7.0.0
  94. * @access public
  95. * @var ExactMetrics_Auth $auth Instance of Auth class.
  96. */
  97. protected $auth;
  98. /**
  99. * Holds instance of ExactMetrics API Auth class.
  100. *
  101. * @since 6.0.0
  102. * @access public
  103. * @var ExactMetrics_Auth $api_auth Instance of APIAuth class.
  104. */
  105. public $api_auth;
  106. /**
  107. * Holds instance of ExactMetrics API Rest Routes class.
  108. *
  109. * @since 7.4.0
  110. * @access public
  111. * @var ExactMetrics_Rest_Routes $routes Instance of rest routes.
  112. */
  113. public $routes;
  114. /**
  115. * Primary class constructor.
  116. *
  117. * @since 6.0.0
  118. * @access public
  119. */
  120. public function __construct() {
  121. // We don't use this
  122. }
  123. /**
  124. * Returns the singleton instance of the class.
  125. *
  126. * @access public
  127. * @since 6.0.0
  128. *
  129. * @return object The ExactMetrics_Lite object.
  130. */
  131. public static function get_instance() {
  132. if ( ! isset( self::$instance ) && ! ( self::$instance instanceof ExactMetrics_Lite ) ) {
  133. self::$instance = new ExactMetrics_Lite();
  134. self::$instance->file = __FILE__;
  135. global $wp_version;
  136. // Detect non-supported WordPress version and return early
  137. if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'EXACTMETRICS_FORCE_ACTIVATION' ) || ! EXACTMETRICS_FORCE_ACTIVATION ) ) {
  138. add_action( 'admin_notices', array( self::$instance, 'exactmetrics_wp_notice' ) );
  139. return;
  140. }
  141. // Detect Pro version and return early
  142. if ( defined( 'EXACTMETRICS_PRO_VERSION' ) ) {
  143. add_action( 'admin_notices', array( self::$instance, 'exactmetrics_pro_notice' ) );
  144. return;
  145. }
  146. // Define constants
  147. self::$instance->define_globals();
  148. // Load in settings
  149. self::$instance->load_settings();
  150. // Load in Licensing
  151. self::$instance->load_licensing();
  152. // Load in Auth
  153. self::$instance->load_auth();
  154. // Load files
  155. self::$instance->require_files();
  156. // This does the version to version background upgrade routines and initial install
  157. $em_version = get_option( 'exactmetrics_current_version', '5.5.3' );
  158. if ( version_compare( $em_version, '6.0.0', '<' ) ) {
  159. exactmetrics_lite_call_install_and_upgrade();
  160. }
  161. if ( is_admin() ) {
  162. new AM_Deactivation_Survey( 'ExactMetrics', 'google-analytics-dashboard-for-wp' );
  163. }
  164. // Load the plugin textdomain.
  165. add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
  166. // Load admin only components.
  167. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  168. self::$instance->notices = new ExactMetrics_Notice_Admin();
  169. self::$instance->reporting = new ExactMetrics_Reporting();
  170. self::$instance->api_auth = new ExactMetrics_API_Auth();
  171. self::$instance->routes = new ExactMetrics_Rest_Routes();
  172. }
  173. if ( exactmetrics_is_pro_version() ) {
  174. require_once EXACTMETRICS_PLUGIN_DIR . 'pro/includes/load.php';
  175. } else {
  176. require_once EXACTMETRICS_PLUGIN_DIR . 'lite/includes/load.php';
  177. }
  178. // Run hook to load ExactMetrics addons.
  179. do_action( 'exactmetrics_load_plugins' ); // the updater class for each addon needs to be instantiated via `exactmetrics_updater`
  180. }
  181. return self::$instance;
  182. }
  183. /**
  184. * Throw error on object clone
  185. *
  186. * The whole idea of the singleton design pattern is that there is a single
  187. * object therefore, we don't want the object to be cloned.
  188. *
  189. * @since 6.0.0
  190. * @access public
  191. *
  192. * @return void
  193. */
  194. public function __clone() {
  195. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-dashboard-for-wp' ), '6.0.0' );
  196. }
  197. /**
  198. * Disable unserializing of the class
  199. *
  200. * Attempting to wakeup an ExactMetrics instance will throw a doing it wrong notice.
  201. *
  202. * @since 6.0.0
  203. * @access public
  204. *
  205. * @return void
  206. */
  207. public function __wakeup() {
  208. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-dashboard-for-wp' ), '6.0.0' );
  209. }
  210. /**
  211. * Magic get function.
  212. *
  213. * We use this to lazy load certain functionality. Right now used to lazyload
  214. * the API & Auth frontend, so it's only loaded if user is using a plugin
  215. * that requires it.
  216. *
  217. * @since 7.0.0
  218. * @access public
  219. *
  220. * @return void
  221. */
  222. public function __get( $key ) {
  223. if ( $key === 'auth' ) {
  224. if ( empty( self::$instance->auth ) ) {
  225. // LazyLoad Auth for Frontend
  226. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/auth.php';
  227. self::$instance->auth = new ExactMetrics_Auth();
  228. }
  229. return self::$instance->$key;
  230. } else {
  231. return self::$instance->$key;
  232. }
  233. }
  234. /**
  235. * Define ExactMetrics constants.
  236. *
  237. * This function defines all of the ExactMetrics PHP constants.
  238. *
  239. * @since 6.0.0
  240. * @access public
  241. *
  242. * @return void
  243. */
  244. public function define_globals() {
  245. if ( ! defined( 'EXACTMETRICS_VERSION' ) ) {
  246. define( 'EXACTMETRICS_VERSION', $this->version );
  247. }
  248. if ( ! defined( 'EXACTMETRICS_LITE_VERSION' ) ) {
  249. define( 'EXACTMETRICS_LITE_VERSION', EXACTMETRICS_VERSION );
  250. }
  251. if ( ! defined( 'EXACTMETRICS_PLUGIN_NAME' ) ) {
  252. define( 'EXACTMETRICS_PLUGIN_NAME', $this->plugin_name );
  253. }
  254. if ( ! defined( 'EXACTMETRICS_PLUGIN_SLUG' ) ) {
  255. define( 'EXACTMETRICS_PLUGIN_SLUG', $this->plugin_slug );
  256. }
  257. if ( ! defined( 'EXACTMETRICS_PLUGIN_FILE' ) ) {
  258. define( 'EXACTMETRICS_PLUGIN_FILE', $this->file );
  259. }
  260. if ( ! defined( 'EXACTMETRICS_PLUGIN_DIR' ) ) {
  261. define( 'EXACTMETRICS_PLUGIN_DIR', plugin_dir_path( $this->file ) );
  262. }
  263. if ( ! defined( 'EXACTMETRICS_PLUGIN_URL' ) ) {
  264. define( 'EXACTMETRICS_PLUGIN_URL', plugin_dir_url( $this->file ) );
  265. }
  266. }
  267. /**
  268. * Loads the plugin textdomain for translation.
  269. *
  270. * @access public
  271. * @since 6.0.0
  272. *
  273. * @return void
  274. */
  275. public function load_plugin_textdomain() {
  276. $mi_locale = get_locale();
  277. if ( function_exists( 'get_user_locale' ) ) {
  278. $mi_locale = get_user_locale();
  279. }
  280. // Traditional WordPress plugin locale filter.
  281. $mi_locale = apply_filters( 'plugin_locale', $mi_locale, 'google-analytics-dashboard-for-wp' );
  282. $mi_mofile = sprintf( '%1$s-%2$s.mo', 'google-analytics-dashboard-for-wp', $mi_locale );
  283. // Look for wp-content/languages/google-analytics-dashboard-for-wp/google-analytics-dashboard-for-wp-{lang}_{country}.mo
  284. $mi_mofile1 = WP_LANG_DIR . '/google-analytics-dashboard-for-wp/' . $mi_mofile;
  285. // Look in wp-content/languages/plugins/google-analytics-dashboard-for-wp/google-analytics-dashboard-for-wp-{lang}_{country}.mo
  286. $mi_mofile2 = WP_LANG_DIR . '/plugins/google-analytics-dashboard-for-wp/' . $mi_mofile;
  287. // Look in wp-content/languages/plugins/google-analytics-dashboard-for-wp-{lang}_{country}.mo
  288. $mi_mofile3 = WP_LANG_DIR . '/plugins/' . $mi_mofile;
  289. // Look in wp-content/plugins/google-analytics-dashboard-for-wp/languages/google-analytics-dashboard-for-wp-{lang}_{country}.mo
  290. $mi_mofile4 = dirname( plugin_basename( EXACTMETRICS_PLUGIN_FILE ) ) . '/languages/';
  291. $mi_mofile4 = apply_filters( 'exactmetrics_lite_languages_directory', $mi_mofile4 );
  292. if ( file_exists( $mi_mofile1 ) ) {
  293. load_textdomain( 'google-analytics-dashboard-for-wp', $mi_mofile1 );
  294. } elseif ( file_exists( $mi_mofile2 ) ) {
  295. load_textdomain( 'google-analytics-dashboard-for-wp', $mi_mofile2 );
  296. } elseif ( file_exists( $mi_mofile3 ) ) {
  297. load_textdomain( 'google-analytics-dashboard-for-wp', $mi_mofile3 );
  298. } else {
  299. load_plugin_textdomain( 'google-analytics-dashboard-for-wp', false, $mi_mofile4 );
  300. }
  301. }
  302. /**
  303. * Output a nag notice if the user has an out of date WP version installed
  304. *
  305. * @access public
  306. * @since 6.0.0
  307. *
  308. * @return void
  309. */
  310. public function exactmetrics_wp_notice() {
  311. $url = admin_url( 'plugins.php' );
  312. // Check for MS dashboard
  313. if( is_network_admin() ) {
  314. $url = network_admin_url( 'plugins.php' );
  315. }
  316. ?>
  317. <div class="error">
  318. <p>
  319. <?php
  320. // Translators: Make version number bold and add a link to return to the plugins page.
  321. echo sprintf( esc_html__( 'Sorry, but your version of WordPress does not meet ExactMetrics\'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-dashboard-for-wp' ), '<strong>', '</strong>', '<a href="' . $url . '">', '</a>' );
  322. ?>
  323. </p>
  324. </div>
  325. <?php
  326. }
  327. /**
  328. * Output a nag notice if the user has both Lite and Pro activated
  329. *
  330. * @access public
  331. * @since 6.0.0
  332. *
  333. * @return void
  334. */
  335. public function exactmetrics_pro_notice() {
  336. $url = admin_url( 'plugins.php' );
  337. // Check for MS dashboard
  338. if( is_network_admin() ) {
  339. $url = network_admin_url( 'plugins.php' );
  340. }
  341. ?>
  342. <div class="error">
  343. <p>
  344. <?php
  345. // Translators: Adds a link to the plugins page.
  346. echo sprintf( esc_html__( 'Please %1$suninstall%2$s the ExactMetrics Lite Plugin. Your Pro version of ExactMetrics may not work as expected until the Lite version is uninstalled.', 'google-analytics-dashboard-for-wp' ), '<a href="' . $url . '">', '</a>' );
  347. ?>
  348. </p>
  349. </div>
  350. <?php
  351. }
  352. /**
  353. * Loads ExactMetrics settings
  354. *
  355. * Adds the items to the base object, and adds the helper functions.
  356. *
  357. * @since 6.0.0
  358. * @access public
  359. *
  360. * @return void
  361. */
  362. public function load_settings() {
  363. global $exactmetrics_settings;
  364. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/options.php';
  365. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/helpers.php';
  366. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/deprecated.php';
  367. $exactmetrics_settings = exactmetrics_get_options();
  368. }
  369. /**
  370. * Loads ExactMetrics License
  371. *
  372. * Loads license class used by ExactMetrics
  373. *
  374. * @since 7.0.0
  375. * @access public
  376. *
  377. * @return void
  378. */
  379. public function load_licensing(){
  380. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  381. require_once EXACTMETRICS_PLUGIN_DIR . 'lite/includes/license-compat.php';
  382. self::$instance->license = new ExactMetrics_License_Compat();
  383. }
  384. }
  385. /**
  386. * Loads ExactMetrics Auth
  387. *
  388. * Loads auth used by ExactMetrics
  389. *
  390. * @since 7.0.0
  391. * @access public
  392. *
  393. * @return void
  394. */
  395. public function load_auth() {
  396. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  397. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/auth.php';
  398. self::$instance->auth = new ExactMetrics_Auth();
  399. }
  400. }
  401. /**
  402. * Loads all files into scope.
  403. *
  404. * @access public
  405. * @since 6.0.0
  406. *
  407. * @return void
  408. */
  409. public function require_files() {
  410. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/capabilities.php';
  411. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  412. // Lite and Pro files
  413. require_once EXACTMETRICS_PLUGIN_DIR . 'assets/lib/pandora/class-am-deactivation-survey.php';
  414. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/ajax.php';
  415. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/admin.php';
  416. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/common.php';
  417. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/notice.php';
  418. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/licensing/autoupdate.php';
  419. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/review.php';
  420. // Pages
  421. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/pages/settings.php';
  422. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/pages/tools.php';
  423. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/pages/reports.php';
  424. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/pages/addons.php';
  425. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/api-auth.php';
  426. // Reports
  427. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/reports/abstract-report.php';
  428. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/reports/overview.php';
  429. // Reporting Functionality
  430. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/reporting.php';
  431. // Routes used by Vue
  432. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/routes.php';
  433. }
  434. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/api-request.php';
  435. if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
  436. // Late loading classes (self instantiating)
  437. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/admin/tracking.php';
  438. }
  439. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/frontend/frontend.php';
  440. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/frontend/seedprod.php';
  441. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/measurement-protocol.php';
  442. }
  443. }
  444. /**
  445. * Fired when the plugin is activated.
  446. *
  447. * @access public
  448. * @since 6.0.0
  449. *
  450. * @global int $wp_version The version of WordPress for this install.
  451. * @global object $wpdb The WordPress database object.
  452. * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false otherwise.
  453. *
  454. * @return void
  455. */
  456. function exactmetrics_lite_activation_hook( $network_wide ) {
  457. global $wp_version;
  458. $url = admin_url( 'plugins.php' );
  459. // Check for MS dashboard
  460. if ( is_network_admin() ) {
  461. $url = network_admin_url( 'plugins.php' );
  462. }
  463. if ( version_compare( $wp_version, '3.8', '<' ) && ( ! defined( 'EXACTMETRICS_FORCE_ACTIVATION' ) || ! EXACTMETRICS_FORCE_ACTIVATION ) ) {
  464. deactivate_plugins( plugin_basename( __FILE__ ) );
  465. 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>' ) );
  466. }
  467. if ( class_exists( 'ExactMetrics' ) ) {
  468. deactivate_plugins( plugin_basename( __FILE__ ) );
  469. wp_die( sprintf( esc_html__( 'Please uninstall and remove ExactMetrics Pro before activating Google Analytics Dashboard for WP (GADWP). 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>' ) );
  470. }
  471. // Add transient to trigger redirect.
  472. set_transient( '_exactmetrics_activation_redirect', 1, 30 );
  473. }
  474. register_activation_hook( __FILE__, 'exactmetrics_lite_activation_hook' );
  475. /**
  476. * Fired when the plugin is uninstalled.
  477. *
  478. * @access public
  479. * @since 6.0.0
  480. *
  481. * @return void
  482. */
  483. function exactmetrics_lite_uninstall_hook() {
  484. wp_cache_flush();
  485. // Note, if both MI Pro and Lite are active, this is an MI Pro instance
  486. // Therefore MI Lite can only use functions of the instance common to
  487. // both plugins. If it needs to be pro specific, then include a file that
  488. // has that method.
  489. $instance = ExactMetrics();
  490. // If uninstalling via wp-cli load admin-specific files only here.
  491. if ( defined( 'WP_CLI' ) && WP_CLI ) {
  492. define( 'WP_ADMIN', true );
  493. $instance->require_files();
  494. $instance->load_auth();
  495. $instance->notices = new ExactMetrics_Notice_Admin();
  496. $instance->reporting = new ExactMetrics_Reporting();
  497. $instance->api_auth = new ExactMetrics_API_Auth();
  498. }
  499. // Don't delete any data if the PRO version is already active.
  500. if ( exactmetrics_is_pro_version() ) {
  501. return;
  502. }
  503. if ( is_multisite() ) {
  504. $site_list = get_sites();
  505. foreach ( (array) $site_list as $site ) {
  506. switch_to_blog( $site->blog_id );
  507. // Delete auth
  508. $instance->api_auth->delete_auth();
  509. // Delete data
  510. $instance->reporting->delete_aggregate_data('site');
  511. restore_current_blog();
  512. }
  513. // Delete network auth using a custom function as some variables are not initiated.
  514. $instance->api_auth->uninstall_network_auth();
  515. // Delete network data
  516. $instance->reporting->delete_aggregate_data('network');
  517. } else {
  518. // Delete auth
  519. $instance->api_auth->delete_auth();
  520. // Delete data
  521. $instance->reporting->delete_aggregate_data('site');
  522. }
  523. }
  524. register_uninstall_hook( __FILE__, 'exactmetrics_lite_uninstall_hook' );
  525. /**
  526. * The main function responsible for returning the one true ExactMetrics_Lite
  527. * Instance to functions everywhere.
  528. *
  529. * Use this function like you would a global variable, except without needing
  530. * to declare the global.
  531. *
  532. * Example: <?php $exactmetrics = ExactMetrics_Lite(); ?>
  533. *
  534. * @since 6.0.0
  535. *
  536. * @uses ExactMetrics_Lite::get_instance() Retrieve ExactMetrics_Lite instance.
  537. *
  538. * @return ExactMetrics_Lite The singleton ExactMetrics_Lite instance.
  539. */
  540. function ExactMetrics_Lite() {
  541. return ExactMetrics_Lite::get_instance();
  542. }
  543. /**
  544. * ExactMetrics Install and Updates.
  545. *
  546. * This function is used install and upgrade ExactMetrics. This is used for upgrade routines
  547. * that can be done automatically, behind the scenes without the need for user interaction
  548. * (for example pagination or user input required), as well as the initial install.
  549. *
  550. * @since 6.0.0
  551. * @access public
  552. *
  553. * @global string $wp_version WordPress version (provided by WordPress core).
  554. * @uses ExactMetrics_Lite::load_settings() Loads ExactMetrics settings
  555. * @uses ExactMetrics_Install::init() Runs upgrade process
  556. *
  557. * @return void
  558. */
  559. function exactmetrics_lite_install_and_upgrade() {
  560. global $wp_version;
  561. // If the WordPress site doesn't meet the correct WP version requirements, don't activate ExactMetrics
  562. if ( version_compare( $wp_version, '3.8', '<' ) ) {
  563. if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
  564. return;
  565. }
  566. }
  567. // Don't run if ExactMetrics Pro is installed
  568. if ( class_exists( 'ExactMetrics' ) ) {
  569. if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
  570. return;
  571. }
  572. }
  573. // Load settings and globals (so we can use/set them during the upgrade process)
  574. ExactMetrics_Lite()->define_globals();
  575. ExactMetrics_Lite()->load_settings();
  576. // Load in Auth
  577. ExactMetrics()->load_auth();
  578. // Load upgrade file
  579. require_once EXACTMETRICS_PLUGIN_DIR . 'includes/em-install.php';
  580. // Run the ExactMetrics upgrade routines
  581. $updates = new ExactMetrics_Install();
  582. $updates->init();
  583. }
  584. /**
  585. * ExactMetrics check for install and update processes.
  586. *
  587. * This function is used to call the ExactMetrics automatic upgrade class, which in turn
  588. * checks to see if there are any update procedures to be run, and if
  589. * so runs them. Also installs ExactMetrics for the first time.
  590. *
  591. * @since 6.0.0
  592. * @access public
  593. *
  594. * @uses ExactMetrics_Install() Runs install and upgrade process.
  595. *
  596. * @return void
  597. */
  598. function exactmetrics_lite_call_install_and_upgrade(){
  599. add_action( 'wp_loaded', 'exactmetrics_lite_install_and_upgrade' );
  600. }
  601. /**
  602. * Returns the ExactMetrics combined object that you can use for both
  603. * ExactMetrics Lite and Pro Users. When both plugins active, defers to the
  604. * more complete Pro object.
  605. *
  606. * Warning: Do not use this in Lite or Pro specific code (use the individual objects instead).
  607. * Also do not use in the ExactMetrics Lite/Pro upgrade and install routines.
  608. *
  609. * Use this function like you would a global variable, except without needing
  610. * to declare the global.
  611. *
  612. * Prevents the need to do conditional global object logic when you have code that you want to work with
  613. * both Pro and Lite.
  614. *
  615. * Example: <?php $exactmetrics = ExactMetrics(); ?>
  616. *
  617. * @since 6.0.0
  618. *
  619. * @uses ExactMetrics::get_instance() Retrieve ExactMetrics Pro instance.
  620. * @uses ExactMetrics_Lite::get_instance() Retrieve ExactMetrics Lite instance.
  621. *
  622. * @return ExactMetrics The singleton ExactMetrics instance.
  623. */
  624. if ( ! function_exists( 'ExactMetrics' ) ) {
  625. function ExactMetrics() {
  626. return ( class_exists( 'ExactMetrics' ) ? ExactMetrics_Pro() : ExactMetrics_Lite() );
  627. }
  628. add_action( 'plugins_loaded', 'ExactMetrics' );
  629. }