HubSpot Tracking Code for WordPress - Version 1.0.0

Version Description

  • Launched the plugin
Download this release

Release Info

Developer AndyGCook
Plugin Icon 128x128 HubSpot Tracking Code for WordPress
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

admin/hubspot-tracking-code-admin.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( !defined('HUBSPOT_TRACKING_CODE_PLUGIN_VERSION') )
4
+ {
5
+ header('HTTP/1.0 403 Forbidden');
6
+ die;
7
+ }
8
+
9
+ //=============================================
10
+ // Define Constants
11
+ //=============================================
12
+
13
+ if ( !defined('HUBSPOT_TRACKING_CODE_ADMIN_PATH') )
14
+ define('HUBSPOT_TRACKING_CODE_ADMIN_PATH', untrailingslashit(__FILE__));
15
+
16
+ //=============================================
17
+ // Include Needed Files
18
+ //=============================================
19
+
20
+ include_once(ABSPATH . 'wp-admin/includes/plugin.php');
21
+
22
+ //=============================================
23
+ // HubSpotTrackingCodeAdmin Class
24
+ //=============================================
25
+ class HubSpotTrackingCodeAdmin
26
+ {
27
+ /**
28
+ * Class constructor
29
+ */
30
+ function __construct ()
31
+ {
32
+ //=============================================
33
+ // Hooks & Filters
34
+ //=============================================
35
+
36
+ $options = get_option('hs_settings');
37
+
38
+ // If the plugin version matches the latest version escape the update function
39
+ if ( $options['hs_version'] != HUBSPOT_TRACKING_CODE_PLUGIN_VERSION )
40
+ self::hubspot_tracking_code_update_check();
41
+
42
+ add_action('admin_menu', array(&$this, 'hubspot_add_menu_items'));
43
+ add_action('admin_init', array(&$this, 'hubspot_build_settings_page'));
44
+ add_filter('plugin_action_links_' . HUBSPOT_TRACKING_CODE_PLUGIN_SLUG . '/hubspot-tracking-code.php', array($this, 'hubspot_plugin_settings_link'));
45
+ }
46
+
47
+ function hubspot_tracking_code_update_check ()
48
+ {
49
+ $options = get_option('hs_settings');
50
+
51
+ // Set the plugin version
52
+ hubspot_tracking_code_update_option('hs_settings', 'hs_version', HUBSPOT_TRACKING_CODE_PLUGIN_VERSION);
53
+ }
54
+
55
+ //=============================================
56
+ // Menus
57
+ //=============================================
58
+
59
+ function hubspot_add_menu_items ()
60
+ {
61
+ add_submenu_page('options-general.php', 'HubSpot Settings', 'HubSpot Settings', 'edit_posts', basename(__FILE__), array($this, 'hubspot_plugin_options'));
62
+ }
63
+
64
+
65
+ //=============================================
66
+ // Settings Page
67
+ //=============================================
68
+
69
+ /**
70
+ * Adds setting link for HubSpot to plugins management page
71
+ *
72
+ * @param array $links
73
+ * @return array
74
+ */
75
+ function hubspot_plugin_settings_link ( $links )
76
+ {
77
+ $url = get_admin_url() . 'options-general.php?page=hubspot-tracking-code-admin.php';
78
+ $settings_link = '<a href="' . $url . '">Settings</a>';
79
+ array_unshift($links, $settings_link);
80
+ return $links;
81
+ }
82
+
83
+ /**
84
+ * Creates settings options
85
+ */
86
+ function hubspot_build_settings_page ()
87
+ {
88
+ global $pagenow;
89
+ $options = get_option('hs_settings');
90
+
91
+ register_setting(
92
+ 'hubspot_settings_options',
93
+ 'hs_settings',
94
+ array($this, 'sanitize')
95
+ );
96
+
97
+ add_settings_section(
98
+ 'hubspot_settings_section',
99
+ '',
100
+ array($this, 'hs_settings_section_heading'),
101
+ HUBSPOT_TRACKING_CODE_ADMIN_PATH
102
+ );
103
+
104
+ add_settings_field(
105
+ 'hs_portal',
106
+ 'Hub ID',
107
+ array($this, 'hs_portal_callback'),
108
+ HUBSPOT_TRACKING_CODE_ADMIN_PATH,
109
+ 'hubspot_settings_section'
110
+ );
111
+ }
112
+
113
+ function hs_settings_section_heading ( )
114
+ {
115
+ $this->print_hidden_settings_fields();
116
+ }
117
+
118
+ function print_hidden_settings_fields ()
119
+ {
120
+ // Hacky solution to solve the Settings API overwriting the default values
121
+ $options = get_option('hs_settings');
122
+
123
+ $hs_installed = ( isset($options['hs_installed']) ? $options['hs_installed'] : 1 );
124
+ $hs_version = ( isset($options['hs_version']) ? $options['hs_version'] : HUBSPOT_TRACKING_CODE_PLUGIN_VERSION );
125
+
126
+ printf(
127
+ '<input id="hs_installed" type="hidden" name="hs_settings[hs_installed]" value="%d"/>',
128
+ $hs_installed
129
+ );
130
+
131
+ printf(
132
+ '<input id="hs_version" type="hidden" name="hs_settings[hs_version]" value="%s"/>',
133
+ $hs_version
134
+ );
135
+ }
136
+
137
+ /**
138
+ * Creates settings page
139
+ */
140
+ function hubspot_plugin_options ()
141
+ {
142
+ ?>
143
+ <div class="wrap">
144
+ <div class="dashboard-widgets-wrap">
145
+ <h2>HubSpot Tracking Code Settings</h2>
146
+ <form method="POST" action="options.php">
147
+ <div id="dashboard-widgets" class="metabox-holder">
148
+ <div class="postbox-container" style="width:60%;">
149
+ <div class="meta-box-sortables ui-sortable">
150
+ <div class="postbox">
151
+ <h3 class="hndle"><span>Settings</span></h3>
152
+ <div class="inside">
153
+ Enter your Hub ID below to track your WordPress site in HubSpot's analytics system.
154
+ <?php
155
+ settings_fields('hubspot_settings_options');
156
+ do_settings_sections(HUBSPOT_TRACKING_CODE_ADMIN_PATH);
157
+ ?>
158
+ </div>
159
+
160
+ </div>
161
+ </div>
162
+ <?php submit_button('Save Settings'); ?>
163
+ </div>
164
+
165
+ <div class="postbox-container" style="width:40%;">
166
+ <div class="meta-box-sortables ui-sortable">
167
+ <div class="postbox">
168
+ <h3 class="hndle"><span>Where is my HubSpot Hub ID?</span></h3>
169
+ <div class="inside">
170
+ <p><b>I'm setting up HubSpot for myself</b><br><a target='_blank' href='https://app.hubspot.com/'>Log in to HubSpot</a>. Your Hub ID is in the upper right corner of the screen.</p>
171
+ <img style="max-width: 100%;" src="http://cdn2.hubspot.net/hubfs/250707/CRM_Knowledge/Sidekick/HubID.jpg?t=1437426192644"/>
172
+ <p><b>I'm setting up HubSpot for someone else</b><br>If you received a "HubSpot Tracking Code Instructions" email, this contains the Hub ID.</p>
173
+ <p><b>I'm interested in trying HubSpot</b><br> <a target='_blank' href='http://offers.hubspot.com/free-trial'>Sign up for a free 30-day trial</a> to get your Hub ID assigned.</a></p>
174
+ </div>
175
+ </div>
176
+ </div>
177
+ </div>
178
+ </div>
179
+ </form>
180
+ </div>
181
+ </div>
182
+ <?php
183
+ }
184
+
185
+ /**
186
+ * Sanitize each setting field as needed
187
+ *
188
+ * @param array $input Contains all settings fields as array keys
189
+ */
190
+ public function sanitize ( $input )
191
+ {
192
+ $new_input = array();
193
+
194
+ $options = get_option('hs_settings');
195
+
196
+ if ( isset($input['hs_portal']) )
197
+ $new_input['hs_portal'] = $input['hs_portal'];
198
+
199
+ if ( isset($input['hs_installed']) )
200
+ $new_input['hs_installed'] = $input['hs_installed'];
201
+
202
+ if ( isset($input['hs_version']) )
203
+ $new_input['hs_version'] = $input['hs_version'];
204
+
205
+ return $new_input;
206
+ }
207
+
208
+ /**
209
+ * Prints Hub ID input for settings page
210
+ */
211
+ function hs_portal_callback ()
212
+ {
213
+ $options = get_option('hs_settings');
214
+ $hs_portal = ( isset($options['hs_portal']) && $options['hs_portal'] ? $options['hs_portal'] : '' );
215
+
216
+ printf(
217
+ '<input id="hs_portal" type="text" id="title" name="hs_settings[hs_portal]" style="width: 400px;" value="%s"/>',
218
+ $hs_portal
219
+ );
220
+
221
+ //echo '<p><a href="http://help.hubspot.com/articles/KCS_Article/Account/Where-can-I-find-my-HUB-ID" target="_blank">Where can I find my HUB ID?</a></p>';
222
+ }
223
+ }
224
+
225
+ ?>
hubspot-tracking-code.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: HubSpot Tracking Code for WordPress
4
+ Plugin URI: http://hubspot.com
5
+ Description: HubSpot's WordPress plugin allows existing HubSpot customers and trial users to install the HubSpot tracking code on their existing WordPress blogs and websites.
6
+ Version: 1.0.0
7
+ Author: HubSpotDev
8
+ Author URI: http://www.hubspot.com/integrations/wordpress
9
+ License: GPL2
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
+
14
+ //=============================================
15
+ // Define Constants
16
+ //=============================================
17
+
18
+ if ( !defined('HUBSPOT_TRACKING_CODE_PATH') )
19
+ define('HUBSPOT_TRACKING_CODE_PATH', untrailingslashit(plugins_url('', __FILE__ )));
20
+
21
+ if ( !defined('HUBSPOT_TRACKING_CODE_PLUGIN_DIR') )
22
+ define('HUBSPOT_TRACKING_CODE_PLUGIN_DIR', untrailingslashit(dirname( __FILE__ )));
23
+
24
+ if ( !defined('HUBSPOT_TRACKING_CODE_PLUGIN_SLUG') )
25
+ define('HUBSPOT_TRACKING_CODE_PLUGIN_SLUG', basename(dirname(__FILE__)));
26
+
27
+ if ( !defined('HUBSPOT_TRACKING_CODE_PLUGIN_VERSION') )
28
+ define('HUBSPOT_TRACKING_CODE_PLUGIN_VERSION', '1.0.0');
29
+
30
+ //=============================================
31
+ // Include Needed Files
32
+ //=============================================
33
+
34
+ require_once(HUBSPOT_TRACKING_CODE_PLUGIN_DIR . '/inc/hubspot-tracking-code-functions.php');
35
+ require_once(HUBSPOT_TRACKING_CODE_PLUGIN_DIR . '/inc/class-hubspot-tracking-code.php');
36
+ require_once(HUBSPOT_TRACKING_CODE_PLUGIN_DIR . '/inc/class-hubspot-tracking-code-analytics.php');
37
+ require_once(HUBSPOT_TRACKING_CODE_PLUGIN_DIR . '/admin/hubspot-tracking-code-admin.php');
38
+
39
+ //=============================================
40
+ // Hooks & Filters
41
+ //=============================================
42
+
43
+ /**
44
+ * Activate the plugin
45
+ */
46
+ function hubspot_tracking_code_activate ( $network_wide )
47
+ {
48
+ // Check activation on entire network or one blog
49
+ if ( is_multisite() && $network_wide )
50
+ {
51
+ global $wpdb;
52
+
53
+ // Get this so we can switch back to it later
54
+ $current_blog = $wpdb->blogid;
55
+
56
+ // Get all blogs in the network and activate plugin on each one
57
+ $q = "SELECT blog_id FROM $wpdb->blogs";
58
+ $blog_ids = $wpdb->get_col($q);
59
+ foreach ( $blog_ids as $blog_id )
60
+ {
61
+ switch_to_blog($blog_id);
62
+ hubspot_tracking_code_setup_plugin();
63
+ }
64
+
65
+ // Switch back to the current blog
66
+ switch_to_blog($current_blog);
67
+ }
68
+ else
69
+ {
70
+ hubspot_tracking_code_setup_plugin();
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Check Super Simple Landing Pages installation and register custom post type
76
+ */
77
+ function hubspot_tracking_code_setup_plugin ( )
78
+ {
79
+ $options = get_option('hs_settings');
80
+
81
+ if ( ! isset($options['hs_installed']) || $options['hs_installed'] != "on" || (!is_array($options)) )
82
+ {
83
+ $opt = array(
84
+ 'hs_installed' => "on",
85
+ 'hs_version' => HUBSPOT_TRACKING_CODE_PLUGIN_VERSION
86
+ );
87
+
88
+ // this is a hack because multisite doesn't recognize local options using either update_option or update_site_option...
89
+ if ( is_multisite() )
90
+ {
91
+ global $wpdb;
92
+
93
+ $multisite_prefix = ( is_multisite() ? $wpdb->prefix : '' );
94
+ $q = $wpdb->prepare("
95
+ INSERT INTO " . $multisite_prefix . "options
96
+ ( option_name, option_value )
97
+ VALUES ('hs_settings', %s)", serialize($opt));
98
+ $wpdb->query($q);
99
+ }
100
+ else
101
+ update_option('hs_settings', $opt);
102
+ }
103
+ }
104
+
105
+ function hubspot_tracking_code_activate_on_new_blog ( $blog_id, $user_id, $domain, $path, $site_id, $meta )
106
+ {
107
+ global $wpdb;
108
+
109
+ if ( is_plugin_active_for_network('hubspot-tracking-code/hubspot-tracking-code.php') )
110
+ {
111
+ $current_blog = $wpdb->blogid;
112
+ switch_to_blog($blog_id);
113
+ hubspot_tracking_code_setup_plugin();
114
+ switch_to_blog($current_blog);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Checks the stored database version against the current data version + updates if needed
120
+ */
121
+ function hubspot_tracking_code_init ()
122
+ {
123
+ if ( is_plugin_active('hubspot/hubspot.php') )
124
+ {
125
+ remove_action( 'plugins_loaded', 'hubspot_tracking_code_init' );
126
+ deactivate_plugins(plugin_basename( __FILE__ ));
127
+
128
+ add_action( 'admin_notices', 'deactivate_hubspot_tracking_code_notice' );
129
+ return;
130
+ }
131
+
132
+ $hubspot_wp = new HubSpotTrackingCode();
133
+ }
134
+
135
+ add_action( 'plugins_loaded', 'hubspot_tracking_code_init', 14 );
136
+
137
+ if ( is_admin() )
138
+ {
139
+ // Activate + install Super Simple Landing Pages
140
+ register_activation_hook( __FILE__, 'hubspot_tracking_code_activate');
141
+
142
+ // Activate on newly created wpmu blog
143
+ add_action('wpmu_new_blog', 'hubspot_tracking_code_activate_on_new_blog', 10, 6);
144
+ }
145
+
146
+ function deactivate_hubspot_tracking_code_notice ()
147
+ {
148
+ ?>
149
+ <div id="message" class="error">
150
+ <?php _e(
151
+ '<p><h3>HubSpot Tracking Code plugin wasn\'t activated because your HubSpot for WordPress plugin is still activated...</h3></p>' .
152
+ '<p>HubSpot Tracking Code and HubSpot for WordPress are like two rival siblings - they don\'t play nice together, but don\'t panic - it\'s an easy fix. Deactivate <b><i>HubSpot for WordPress</i></b> and then try activating <b><i>HubSpot Tracking Code for WordPress</i></b> again, and everything should work fine.</p>' .
153
+ '<p>By the way - make sure you replace all your form and CTA shortcodes with <a href="http://help.hubspot.com/articles/KCS_Article/Integrations/How-to-switch-from-the-HubSpot-for-Wordpress-plugin-to-the-HubSpot-Tracking-code-for-Wordpress-plugin" target="_blank">HubSpot embed codes</a></p>',
154
+ 'my-text-domain'
155
+ ); ?>
156
+ </div>
157
+ <?php
158
+ }
159
+
160
+ ?>
inc/class-hubspot-tracking-code-analytics.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HubSpotTrackingCodeAnalytics
3
+ {
4
+ function HubSpotTrackingCodeAnalytics ()
5
+ {
6
+ add_action('wp_footer', array(&$this, 'hubspot_analytics_insert'));
7
+ }
8
+
9
+ //=============================================
10
+ // Insert tracking code
11
+ //=============================================
12
+ function hubspot_analytics_insert ()
13
+ {
14
+ global $current_user;
15
+ wp_reset_query();
16
+
17
+ get_currentuserinfo();
18
+ $options = array();
19
+ $options = get_option('hs_settings');
20
+
21
+ if ( isset($options['hs_portal']) && $options['hs_portal'] != '' )
22
+ {
23
+ // Identify the current user if logged in
24
+ if ( $current_user->user_email )
25
+ {
26
+ $hs_identify_name = $current_user->user_login;
27
+ $hs_identify_email = $current_user->user_email;
28
+ $hs_identify_id = md5($current_user->user_email);
29
+ }
30
+ else
31
+ {
32
+ $commenter = wp_get_current_commenter();
33
+ if ( $commenter['comment_author_email'] )
34
+ {
35
+ $hs_identify_name = $commenter['comment_author'];
36
+ $hs_identify_email = $commenter['comment_author_email'];
37
+ $hs_identify_id = md5($commenter['comment_author_email']);
38
+ }
39
+ }
40
+
41
+ if ( isset($hs_identify_email) )
42
+ {
43
+ echo "\n" . '<!-- DO NOT COPY THIS SNIPPET! -- HubSpot User Identification Code -->' . "\n";
44
+ echo '<script type="text/javascript">'."\n";
45
+ echo "(function(d,w) {\n";
46
+ // Wrap `identify` call in hubspotutk check to help prevent accidental copy-paste
47
+ if ( isset($_COOKIE['hubspotutk']) )
48
+ {
49
+ echo "var match = d.cookie.match('(^|;) ?hubspotutk=([^;]*)(;|$)');\n";
50
+ echo "if (match && match[2] == \"" . $_COOKIE['hubspotutk'] . "\") {\n";
51
+ }
52
+ echo "w._hsq = w._hsq || [];\n";
53
+ echo "w._hsq.push([\"identify\", {\n";
54
+ echo " \"email\" : \"" . $hs_identify_email . "\",\n";
55
+ echo " \"name\" : \"" . $hs_identify_name . "\",\n";
56
+ echo " \"id\" : \"" . $hs_identify_id . "\"\n";
57
+ echo "}]);\n";
58
+ if ( isset($_COOKIE['hubspotutk']) )
59
+ {
60
+ echo "}\n";
61
+ }
62
+ echo "})(document, window);\n";
63
+ echo '</script>' . "\n";
64
+ echo '<!-- End of HubSpot User Identification Code -- DO NOT COPY THIS SNIPPET! -->' . "\n";
65
+ }
66
+
67
+ echo "\n".'<!-- Start of Async HubSpot Analytics Code for WordPress v' . HUBSPOT_TRACKING_CODE_PLUGIN_VERSION . ' -->' . "\n";
68
+ echo '<script type="text/javascript">' . "\n";
69
+ echo 'var _hsq = _hsq || [];' . "\n";
70
+ // Pass along the correct content-type
71
+ if ( is_single () )
72
+ {
73
+ echo '_hsq.push(["setContentType", "blog-post"]);' . "\n";
74
+ }
75
+ else if ( is_archive () || is_search() )
76
+ {
77
+ echo '_hsq.push(["setContentType", "listing-page"]);' . "\n";
78
+ }
79
+ else
80
+ {
81
+ echo '_hsq.push(["setContentType", "standard-page"]);' . "\n";
82
+ }
83
+
84
+ echo '(function(d,s,i,r) {' . "\n";
85
+ echo ' if (d.getElementById(i)){return;}' . "\n";
86
+ echo ' var n = d.createElement(s),e = document.getElementsByTagName(s)[0];' . "\n";
87
+ echo ' n.id=i;n.src = \'//js.hs-analytics.net/analytics/\'+(Math.ceil(new Date()/r)*r)+\'/' . trim($options['hs_portal']) . '.js\';' . "\n";
88
+ echo ' e.parentNode.insertBefore(n, e);' . "\n";
89
+ echo '})(document, "script", "hs-analytics", 300000);' . "\n";
90
+ echo '</script>' . "\n";
91
+ echo '<!-- End of Async HubSpot Analytics Code -->' . "\n";
92
+ }
93
+ }
94
+ }
95
+ ?>
inc/class-hubspot-tracking-code.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //=============================================
4
+ // HubSpotTrackingCode Class
5
+ //=============================================
6
+ class HubSpotTrackingCode
7
+ {
8
+ /**
9
+ * Class constructor
10
+ */
11
+ function __construct ()
12
+ {
13
+ if ( is_admin() )
14
+ {
15
+ if ( ! defined('DOING_AJAX') || ! DOING_AJAX )
16
+ {
17
+ $hubspot_wp_admin = new HubSpotTrackingCodeAdmin();
18
+ add_action('admin_notices', array($this, 'plugin_activation'));
19
+ }
20
+ }
21
+ else
22
+ {
23
+ global $hubspot_analytics;
24
+ $hubspot_analytics = new HubSpotTrackingCodeAnalytics();
25
+ }
26
+ }
27
+
28
+ function plugin_activation ()
29
+ {
30
+ $options = get_option('hs_settings');
31
+
32
+ if ( isset($_GET['page']) && $_GET['page'] == 'hubspot-tracking-code-admin.php' )
33
+ return FALSE;
34
+
35
+ $html = '';
36
+ if ( ! isset($options['hs_portal']) || ( isset($options['hs_portal']) && ! $options['hs_portal'] ) )
37
+ {
38
+ $html = '<div class="updated" style="border-color: #f47621">';
39
+ $html .= '<p>';
40
+ $html .= __("Almost done! <a href='options-general.php?page=hubspot-tracking-code-admin.php'>Enter your HubSpot Hub ID</a> and you'll be ready to rock.");
41
+ $html .= '</p>';
42
+ $html .= '</div>';
43
+ }
44
+ else if ( isset($options['hs_portal']) && ! is_numeric($options['hs_portal']) )
45
+ {
46
+ $html = '<div class="updated" style="border-color: #f47621">';
47
+ $html .= '<p>';
48
+ $html .= __("Your HubID should be a number, and it looks like the HubID you entered contains some shady characters... <a href='options-general.php?page=hubspot-tracking-code-admin.php'>Re-enter your HubSpot Hub ID</a> and you'll be ready to rock.");
49
+ $html .= '</p>';
50
+ $html .= '</div>';
51
+ }
52
+
53
+ if ( $html )
54
+ echo $html;
55
+ }
56
+ }
57
+
58
+ //=============================================
59
+ // Leadin Init
60
+ //=============================================
61
+
62
+ global $hubspot_wp_admin, $hubspot_analytics;
inc/hubspot-tracking-code-functions.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( !defined('HUBSPOT_TRACKING_CODE_PLUGIN_VERSION') )
4
+ {
5
+ header('HTTP/1.0 403 Forbidden');
6
+ die;
7
+ }
8
+
9
+ /**
10
+ * Updates an option in the multi-dimensional option array
11
+ *
12
+ * @param string $option option_name in wp_options
13
+ * @param string $option_key key for array
14
+ * @param string $option new value for array
15
+ *
16
+ * @return bool True if option value has changed, false if not or if update failed.
17
+ */
18
+ function hubspot_tracking_code_update_option ( $option, $option_key, $new_value )
19
+ {
20
+ $options_array = get_option($option);
21
+
22
+ if ( isset($options_array[$option_key]) )
23
+ {
24
+ if ( $options_array[$option_key] == $new_value )
25
+ return false; // Don't update an option if it already is set to the value
26
+ }
27
+
28
+ if ( ! is_array( $options_array ) ) {
29
+ $options_array = array();
30
+ }
31
+
32
+ $options_array[$option_key] = $new_value;
33
+ update_option($option, $options_array);
34
+
35
+ $options_array = get_option($option);
36
+ return update_option($option, $options_array);
37
+ }
38
+
39
+ /**
40
+ * Logs a debug statement to /wp-content/debug.log
41
+ *
42
+ * @param string
43
+ */
44
+ function hubspot_log_debug ( $message )
45
+ {
46
+ if ( WP_DEBUG === TRUE )
47
+ {
48
+ if ( is_array($message) || is_object($message) )
49
+ error_log(print_r($message, TRUE));
50
+ else
51
+ error_log($message);
52
+ }
53
+ }
54
+
55
+ ?>
readme.txt ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === HubSpot Tracking Code for WordPress ===
2
+ Contributors: HubSpotDev
3
+ Tags: analytics, marketing analytics, hubspot, tracking code, inbound marketing, marketing
4
+ Requires at least: 3.7
5
+ Tested up to: 4.2.2
6
+ Stable tag: 1.0.0
7
+
8
+ HubSpot's WordPress plugin allows existing HubSpot customers and trial users to install the HubSpot tracking code on their existing WordPress blogs and websites.
9
+
10
+ == Description ==
11
+
12
+ HubSpot's WordPress plugin allows existing HubSpot customers and trial users to install the HubSpot tracking code on their existing WordPress blogs and websites.
13
+
14
+ If you don't have an account yet, <a href="http://offers.hubspot.com/free-trial">sign up for a free 30 day trial.</a>
15
+
16
+ Note: HubSpot collects usage information about this plugin so that we can better serve our customers and know what features to add. By installing and activating the HubSpot for WordPress plugin you agree to these terms.
17
+
18
+
19
+ == Installation ==
20
+
21
+ *(using the Wordpress Admin Console)*
22
+
23
+ 1. From your dashboard, click on "Plugins" in the left sidebar
24
+ 2. Add a new plugin
25
+ 3. Search for "HubSpot"
26
+ 4. Install "HubSpot Tracking Code”
27
+ 5. Once Installed, click Settings → HubSpot Settings
28
+ 6. Enter your Hub ID and press “Save Settings” (your Hub ID can be found with the product version at the bottom of your HubSpot Dashboard. Once you've entered it into the plugin settings, click the Click here to authenticate button. You'll be asked to login to HubSpot and give access).
29
+
30
+ http://help.hubspot.com/articles/How_To_Doc/how-to-install-hubspot-javascript-tracking-code-on-wordpress
31
+
32
+ *(manually via FTP)*
33
+
34
+ 1. Delete any existing 'hubspot' folder from the '/wp-content/plugins/' directory
35
+ 2. Upload the 'hubspot' folder to the '/wp-content/plugins/' directory
36
+ 3. Activate the plugin through the 'Plugins' menu in WordPress
37
+ 4. Once Installed, click on the HubSpot plugin in your sidebar and go to "settings"
38
+ 5. Enter your Hub ID and press “Save Settings” (your Hub ID can be found with the product version at the bottom of your HubSpot Dashboard. Once you've entered it into the plugin settings, click the Click here to authenticate button. You'll be asked to login to HubSpot and give access).
39
+
40
+
41
+ == Changelog ==
42
+
43
+ = 1.0.0 =
44
+ * Launched the plugin
45
+