-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgosquared.php
More file actions
95 lines (77 loc) · 2.51 KB
/
gosquared.php
File metadata and controls
95 lines (77 loc) · 2.51 KB
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
<?php
/**
* Plugin Name: GoSquared
* Plugin URI: http://garman.io
* Description: Integrate GoSquared with your WordPress site, includes WooCommerce support.
* Version: 1.0.0
* Author: Patrick Garman
* Author URI: http://pmgarman.me
* Text Domain: gio-gosquared
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'GIO_GoSquared' ) ) :
class GIO_GoSquared {
/**
* Settings
*/
public $settings = null;
/**
* Construct the plugin.
*/
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'init' ) );
}
/**
* Initialize the plugin.
*/
public function init() {
// Load and register settings
require_once 'inc/class-gio-gosquared-settings.php';
$this->settings = new GIO_GoSquared_Settings;
if( ! empty( $this->settings->get( 'site_token' ) ) ) {
add_action( 'wp_footer', array( $this, 'output_script' ) );
}
if( 1 == absint( $this->settings->get( 'people' ) ) && is_user_logged_in() ) {
add_action( 'gio_gosquared_js_output', array( $this, 'add_people' ) );
}
// Checks if WooCommerce is installed and loads the integration
if ( class_exists( 'WC_Integration' ) ) {
require_once 'inc/class-gio-gosquared-wc-integration.php';
// Register the integration with WooCommerce
add_filter( 'woocommerce_integrations', array( $this, 'add_wc_integration' ) );
}
}
/**
* Add a new integration to WooCommerce.
*/
public function add_wc_integration( $integrations ) {
$integrations[] = 'GIO_GoSquared_WC_Integration';
return $integrations;
}
public function output_script() { ?>
<!-- GoSquared Start -->
<!-- Integration by Garman.IO -->
<script>
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(
arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];
d.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';q.parentNode.
insertBefore(d,q)}(window,document,'script','_gs');
_gs('<?php echo $this->settings->get( 'site_token' ); ?>');
<?php do_action( 'gio_gosquared_js_output' ); ?>
</script>
<!-- GoSquared End -->
<?php }
public function add_people() { global $current_user; get_currentuserinfo(); ?>
_gs('identify', {
id: <?php echo $current_user->ID; ?>,
username: '<?php echo $current_user->user_login; ?>',
email: '<?php echo $current_user->user_email; ?>'
});
<?php }
}
global $GIO_GoSquared;
$GIO_GoSquared = new GIO_GoSquared( __FILE__ );
endif;