-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-google-analytics-integration.php
108 lines (91 loc) · 3.1 KB
/
woocommerce-google-analytics-integration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Plugin Name: WooCommerce Google Analytics Integration
* Plugin URI: http://wordpress.org/plugins/woocommerce-google-analytics-integration/
* Description: Allows Google Analytics tracking code to be inserted into WooCommerce store pages.
* Author: WooThemes
* Author URI: http://woothemes.com
* Version: 1.3.0
* License: GPLv2 or later
* Text Domain: woocommerce-google-analytics-integration
* Domain Path: languages/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Google_Analytics_Integration' ) ) :
/**
* WooCommerce Google Analytics Integration main class.
*/
class WC_Google_Analytics_Integration {
/**
* Plugin version.
*
* @var string
*/
const VERSION = '1.3.0';
/**
* Instance of this class.
*
* @var object
*/
protected static $instance = null;
/**
* Initialize the plugin.
*/
private function __construct() {
// Load plugin text domain
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
// Checks with WooCommerce is installed.
if ( class_exists( 'WC_Integration' ) && defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '2.1-beta-1', '>=' ) ) {
include_once 'includes/class-wc-google-analytics.php';
// Register the integration.
add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) );
} else {
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
}
}
/**
* Return an instance of this class.
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Load the plugin text domain for translation.
*
* @return void
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-google-analytics-integration' );
load_textdomain( 'woocommerce-google-analytics-integration', trailingslashit( WP_LANG_DIR ) . 'woocommerce-google-analytics-integration/woocommerce-google-analytics-integration-' . $locale . '.mo' );
load_plugin_textdomain( 'woocommerce-google-analytics-integration', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* WooCommerce fallback notice.
*
* @return string
*/
public function woocommerce_missing_notice() {
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Google Analytics depends on the last version of %s to work!', 'woocommerce-google-analytics-integration' ), '<a href="http://www.woothemes.com/woocommerce/" target="_blank">' . __( 'WooCommerce', 'woocommerce-google-analytics-integration' ) . '</a>' ) . '</p></div>';
}
/**
* Add a new integration to WooCommerce.
*
* @param array $integrations WooCommerce integrations.
*
* @return array Google Analytics integration.
*/
public function add_integration( $integrations ) {
$integrations[] = 'WC_Google_Analytics';
return $integrations;
}
}
add_action( 'plugins_loaded', array( 'WC_Google_Analytics_Integration', 'get_instance' ), 0 );
endif;