PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.6.2
Jetpack – WP Security, Backup, Speed, & Growth v7.6.2
16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 All 503 releases
jetpack / modules / woocommerce-analytics / wp-woocommerce-analytics.php

wp-woocommerce-analytics.php in Jetpack – WP Security, Backup, Speed, & Growth 7.6.2, at modules/woocommerce-analytics/wp-woocommerce-analytics.php

95 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Jetpack_WooCommerce_Analytics is ported from the Jetpack_Google_Analytics code.
4 *
5 * @package Jetpack
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 require_once plugin_basename( 'classes/wp-woocommerce-analytics-universal.php' );
13
14 /**
15 * Class Jetpack_WooCommerce_Analytics
16 * Instantiate WooCommerce Analytics
17 */
18 class Jetpack_WooCommerce_Analytics {
19
20 /**
21 * Instance of this class
22 *
23 * @var Jetpack_WooCommerce_Analytics - Static property to hold our singleton instance
24 */
25 private static $instance = false;
26
27 /**
28 * Instance of the Universal functions
29 *
30 * @var Static property to hold concrete analytics impl that does the work (universal or legacy)
31 */
32 private static $analytics = false;
33
34 /**
35 * WooCommerce Analytics is only available to Jetpack connected WooCommerce stores with both plugins set to active
36 * and WooCommerce version 3.0 or higher
37 *
38 * @return bool
39 */
40 public static function shouldTrackStore() {
41 /**
42 * Make sure WooCommerce is installed and active
43 *
44 * This action is documented in https://docs.woocommerce.com/document/create-a-plugin
45 */
46 if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ) ) ) {
47 return false;
48 }
49 // Tracking only Site pages
50 if ( is_admin() ) {
51 return false;
52 }
53 // Don't track site admins
54 if ( is_user_logged_in() && in_array( 'administrator', wp_get_current_user()->roles ) ) {
55 return false;
56 }
57 // Make sure Jetpack is installed and active
58 if ( ! Jetpack::is_active() ) {
59 return false;
60 }
61 // Ensure the WooCommerce class exists and is a valid version
62 $minimum_woocommerce_active = class_exists( 'WooCommerce' ) && version_compare( WC_VERSION, '3.0', '>=' );
63 if ( ! $minimum_woocommerce_active ) {
64 return false;
65 }
66 return true;
67 }
68
69 /**
70 * This is our constructor, which is private to force the use of get_instance()
71 *
72 * @return void
73 */
74 private function __construct() {
75 $analytics = new Jetpack_WooCommerce_Analytics_Universal();
76 }
77
78 /**
79 * Function to instantiate our class and make it a singleton
80 */
81 public static function get_instance() {
82 if ( ! self::shouldTrackStore() ) {
83 return;
84 }
85 if ( ! self::$instance ) {
86 self::$instance = new self();
87 }
88
89 return self::$instance;
90 }
91 }
92
93 global $jetpack_woocommerce_analytics;
94 $jetpack_woocommerce_analytics = Jetpack_WooCommerce_Analytics::get_instance();
95