HubSpot – Free Marketing Plugin for WordPress - Version 7.5.0

Version Description

(2019.05.22) = - Add banner to inform users if the version is outdated - Add notification that informs user if something is not working on our servers - Reload window when connection happens on a different tab - Reduce loading time for non authenticated users - Improve performances when navigating between pages - Add tests

Download this release

Release Info

Developer leadin
Plugin Icon 128x128 HubSpot – Free Marketing Plugin for WordPress
Version 7.5.0
Comparing to
See all releases

Code changes from version 7.4.1 to 7.5.0

admin/leadin-admin.php CHANGED
@@ -20,7 +20,11 @@ function action_required_notice(){
20
  $current_screen = get_current_screen();
21
  if ( $current_screen->parent_base !== 'leadin' ) {
22
  $leadin_icon = LEADIN_PATH . '/images/sprocket.svg';
23
- echo '<div class="notice notice-warning is-dismissible"><p><img src="' . $leadin_icon . '" height="16" style="margin-bottom: -3px" /> ' . __('The HubSpot plugin isn’t connected right now. To use HubSpot tools on your WordPress site, <a href="admin.php?page=leadin">connect the plugin now</a>.', 'leadin') . '</p></div>';
 
 
 
 
24
  }
25
  }
26
 
@@ -51,9 +55,10 @@ class WPLeadInAdmin {
51
  }
52
 
53
  add_action( 'admin_menu', array( &$this, 'leadin_add_menu_items' ) );
54
- add_action( 'admin_print_scripts', array( &$this, 'add_leadin_admin_scripts' ) );
55
  add_filter( 'plugin_action_links_' . 'leadin/leadin.php', array( $this, 'leadin_plugin_settings_link' ) );
56
  add_action( 'admin_notices', array( &$this, 'leadin_add_background_iframe' ) );
 
57
 
58
  if ($affiliate = $this->get_affiliate_code()) {
59
  add_option( 'hubspot_affiliate_code', $affiliate );
@@ -126,7 +131,6 @@ class WPLeadInAdmin {
126
  $notificationIcon = '';
127
  if ( ! get_option( 'leadin_portalId' ) ) {
128
  $notificationIcon = ' <span class="update-plugins count-1"><span class="plugin-count">!</span></span>';
129
- add_action('admin_notices', 'action_required_notice');
130
  }
131
 
132
  add_menu_page( __('HubSpot', 'leadin'), __('HubSpot', 'leadin').$notificationIcon, $capability, 'leadin', array( $this, 'leadin_build_app' ), 'dashicons-sprocket', '25.100713' );
@@ -189,8 +193,9 @@ class WPLeadInAdmin {
189
  if ($error_message) {
190
  echo "<div class='notice notice-warning'><p>$error_message</p></div>";
191
  } else {
 
192
  ?>
193
- <iframe id="leadin-iframe" src="<?php echo leadin_get_iframe_src(); ?>"></iframe>
194
  <?php
195
  }
196
  }
@@ -198,8 +203,9 @@ class WPLeadInAdmin {
198
  function leadin_add_background_iframe() {
199
  $screen = get_current_screen();
200
  if ( $screen->id === 'dashboard' ) {
 
201
  ?>
202
- <iframe class="leadin-background-iframe" style="display: none" id="leadin-iframe" src="<?php echo leadin_get_background_iframe_src(); ?>"></iframe>
203
  <?php
204
  }
205
  }
@@ -211,38 +217,19 @@ class WPLeadInAdmin {
211
  * Adds admin javascript
212
  */
213
  function add_leadin_admin_scripts() {
214
- global $pagenow;
215
- global $wp_roles;
216
  global $wp_version;
217
 
218
- $ajaxUrl = get_admin_url( get_current_blog_id(), 'admin-ajax.php' );
219
- $wpUser = wp_get_current_user();
220
-
221
  $leadin_config = array(
222
- 'portalId' => get_option( 'leadin_portalId' ),
223
- 'affiliateCode' => get_option( 'hubspot_affiliate_code' ),
224
- 'acquisitionAttributionParams' => $this->get_acquisition_attribution_option(),
225
- 'env' => constant( 'LEADIN_ENV' ),
226
- 'hubspotBaseUrl' => constant( 'LEADIN_BASE_URL' ),
227
- 'user' => $this->leadin_get_user_for_tracking(),
228
- 'allRoles' => $wp_roles->get_names(),
229
- 'leadinPluginVersion' => constant( 'LEADIN_PLUGIN_VERSION' ),
230
- 'wpVersion' => $wp_version,
231
- 'siteUrl' => get_site_url(),
232
- 'adminEmail' => get_option( 'admin_email' ),
233
- 'siteName' => get_bloginfo( 'name' ),
234
- 'adminBaseUrl' => get_admin_url( get_current_blog_id(), 'admin.php' ),
235
- 'leadinPluginDirectory' => LEADIN_PLUGIN_SLUG,
236
- 'ajaxUrl' => is_ssl() ? str_replace( 'http:', 'https:', $ajaxUrl ) : str_replace( 'https:', 'http:', $ajaxUrl ),
237
- 'locale' => get_locale(),
238
- 'timezone' => get_option( 'gmt_offset' ),
239
- 'timezoneString' => get_option( 'timezone_string' ), // If not set by the user manually it will be an empty string
240
- 'connectionTimeInMs' => get_option( 'leadin_connectionTimeInMs' ),
241
- 'plugins' => get_plugins(),
242
- 'phpVersion' => phpversion(),
243
- 'wpUserFirstName' => $wpUser->user_firstname,
244
- 'wpUserLastName' => $wpUser->user_lastname,
245
- 'wpUserEmail' => $wpUser->user_email,
246
  );
247
 
248
  $leadin_i18n = array(
@@ -251,37 +238,12 @@ class WPLeadInAdmin {
251
 
252
  wp_register_script( 'leadin-raven-js', LEADIN_PATH.'/scripts/raven.min.js' );
253
  wp_register_style( 'leadin-bridge-css', LEADIN_PATH.'/style/leadin-bridge.css' );
254
- wp_register_script( 'leadin-js', LEADIN_PATH.'/scripts/leadin.js', array( 'underscore', 'leadin-raven-js' ), false, true );
255
- wp_localize_script( 'leadin-js', 'leadin_config', $leadin_config );
256
- wp_localize_script( 'leadin-js', 'leadin_i18n', $leadin_i18n );
257
  wp_enqueue_script( 'leadin-js' );
258
  }
259
 
260
- // =============================================
261
- // Internal Class Functions
262
- // =============================================
263
- function leadin_get_user_for_tracking() {
264
- $leadin_user = leadin_get_current_user();
265
- $tracking_leadin_user = array(
266
- 'hashed_wp_url' => $leadin_user['user_id'],
267
- 'name' => $leadin_user['alias'],
268
- 'email' => $leadin_user['email'],
269
- 'wp-url' => $leadin_user['wp_url'],
270
- 'wp-version' => $leadin_user['wp_version'],
271
- 'li-source' => LEADIN_SOURCE,
272
- 'website' => $leadin_user['wp_url'],
273
- 'company' => $leadin_user['wp_url'],
274
- 'utm_source' => $leadin_user['utm_source'],
275
- 'utm_medium' => $leadin_user['utm_medium'],
276
- 'utm_term' => $leadin_user['utm_term'],
277
- 'utm_content' => $leadin_user['utm_term'],
278
- 'utm_campaign' => $leadin_user['utm_campaign'],
279
- 'referral_source' => $leadin_user['referral_source'],
280
- 'user_email' => $leadin_user['user_email'],
281
- );
282
- return $tracking_leadin_user;
283
- }
284
-
285
  /**
286
  * GET and set url actions into readable strings
287
  *
20
  $current_screen = get_current_screen();
21
  if ( $current_screen->parent_base !== 'leadin' ) {
22
  $leadin_icon = LEADIN_PATH . '/images/sprocket.svg';
23
+ if ( get_option( 'leadin_outdated_version' ) ) {
24
+ echo '<div class="notice notice-warning is-dismissible"><p><img src="' . $leadin_icon . '" height="16" style="margin-bottom: -3px" /> ' . sprintf( __('Your current version of the HubSpot plugin is outdated, and errors may occur. <a class="thickbox open-plugin-details-modal" href="%1$splugin-install.php?tab=plugin-information&amp;plugin=leadin&amp;section=changelog&amp;TB_iframe=true&amp;width=616&amp;height=1046">Please update now.</a>', 'leadin'), admin_url() ) . '</p></div>';
25
+ } else if ( ! get_option( 'leadin_portalId' ) ) {
26
+ echo '<div class="notice notice-warning is-dismissible"><p><img src="' . $leadin_icon . '" height="16" style="margin-bottom: -3px" /> ' . __('The HubSpot plugin isn’t connected right now. To use HubSpot tools on your WordPress site, <a href="admin.php?page=leadin">connect the plugin now</a>.', 'leadin') . '</p></div>';
27
+ }
28
  }
29
  }
30
 
55
  }
56
 
57
  add_action( 'admin_menu', array( &$this, 'leadin_add_menu_items' ) );
58
+ add_action( 'admin_enqueue_scripts', array( &$this, 'add_leadin_admin_scripts' ) );
59
  add_filter( 'plugin_action_links_' . 'leadin/leadin.php', array( $this, 'leadin_plugin_settings_link' ) );
60
  add_action( 'admin_notices', array( &$this, 'leadin_add_background_iframe' ) );
61
+ add_action( 'admin_notices', 'action_required_notice' );
62
 
63
  if ($affiliate = $this->get_affiliate_code()) {
64
  add_option( 'hubspot_affiliate_code', $affiliate );
131
  $notificationIcon = '';
132
  if ( ! get_option( 'leadin_portalId' ) ) {
133
  $notificationIcon = ' <span class="update-plugins count-1"><span class="plugin-count">!</span></span>';
 
134
  }
135
 
136
  add_menu_page( __('HubSpot', 'leadin'), __('HubSpot', 'leadin').$notificationIcon, $capability, 'leadin', array( $this, 'leadin_build_app' ), 'dashicons-sprocket', '25.100713' );
193
  if ($error_message) {
194
  echo "<div class='notice notice-warning'><p>$error_message</p></div>";
195
  } else {
196
+ $iframe_url = leadin_get_iframe_src();
197
  ?>
198
+ <iframe id="leadin-iframe" src="<?= $iframe_url ?>"></iframe>
199
  <?php
200
  }
201
  }
203
  function leadin_add_background_iframe() {
204
  $screen = get_current_screen();
205
  if ( $screen->id === 'dashboard' ) {
206
+ $background_iframe_url = leadin_get_background_iframe_src();
207
  ?>
208
+ <iframe class="leadin-background-iframe" style="display: none" id="leadin-iframe" src="<?= $background_iframe_url ?>"></iframe>
209
  <?php
210
  }
211
  }
217
  * Adds admin javascript
218
  */
219
  function add_leadin_admin_scripts() {
 
 
220
  global $wp_version;
221
 
 
 
 
222
  $leadin_config = array(
223
+ 'adminUrl' => admin_url(),
224
+ 'ajaxUrl' => leadin_get_ajax_url(),
225
+ 'env' => constant( 'LEADIN_ENV' ),
226
+ 'hubspotBaseUrl' => constant( 'LEADIN_BASE_URL' ),
227
+ 'leadinPluginVersion' => constant( 'LEADIN_PLUGIN_VERSION' ),
228
+ 'locale' => get_locale(),
229
+ 'phpVersion' => leadin_parse_version( phpversion() ),
230
+ 'plugins' => get_plugins(),
231
+ 'portalId' => get_option( 'leadin_portalId' ),
232
+ 'wpVersion' => leadin_parse_version( $wp_version ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  );
234
 
235
  $leadin_i18n = array(
238
 
239
  wp_register_script( 'leadin-raven-js', LEADIN_PATH.'/scripts/raven.min.js' );
240
  wp_register_style( 'leadin-bridge-css', LEADIN_PATH.'/style/leadin-bridge.css' );
241
+ wp_register_script( 'leadin-js', LEADIN_PATH.'/scripts/leadin.js', array( 'leadin-raven-js' ), false, true );
242
+ wp_localize_script( 'leadin-js', 'leadinConfig', $leadin_config );
243
+ wp_localize_script( 'leadin-js', 'leadinI18n', $leadin_i18n );
244
  wp_enqueue_script( 'leadin-js' );
245
  }
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  /**
248
  * GET and set url actions into readable strings
249
  *
changelog.txt CHANGED
@@ -1,3 +1,12 @@
 
 
 
 
 
 
 
 
 
1
  = 7.4.1 (2019.05.07) =
2
  - Implement faster navigation
3
  - Fix signup url
1
+ = 7.5.0 (2019.05.22) =
2
+ - Add banner to inform users if the version is outdated
3
+ - Add notification that informs user if something is not working on our
4
+ servers
5
+ - Reload window when connection happens on a different tab
6
+ - Reduce loading time for non authenticated users
7
+ - Improve performances when navigating between pages
8
+ - Add tests
9
+
10
  = 7.4.1 (2019.05.07) =
11
  - Implement faster navigation
12
  - Fix signup url
inc/leadin-functions.php CHANGED
@@ -8,79 +8,6 @@ if ( ! defined( 'LEADIN_PORTAL_ID' ) ) {
8
  DEFINE( 'LEADIN_PORTAL_ID', intval( get_option( 'leadin_portalId' ) ) );
9
  }
10
 
11
- /**
12
- * Get Leadin user
13
- *
14
- * @return array
15
- */
16
- function leadin_get_current_user() {
17
- global $wp_version;
18
-
19
- $current_user = wp_get_current_user();
20
- $li_user_id = md5( get_bloginfo( 'wpurl' ) );
21
-
22
- $li_options = get_option( 'leadin_options' );
23
- $leadinPortalId = get_option( 'leadin_portalId' );
24
-
25
- if ( isset( $li_options['li_email'] ) ) {
26
- $li_user_email = $li_options['li_email'];
27
- } else {
28
- $li_user_email = $current_user->user_email;
29
- }
30
-
31
- $leadin_user = array(
32
- 'user_id' => $li_user_id,
33
- 'email' => $li_user_email,
34
- 'alias' => $current_user->display_name,
35
- 'wp_url' => get_bloginfo( 'wpurl' ),
36
- 'li_version' => LEADIN_PLUGIN_VERSION,
37
- 'wp_version' => $wp_version,
38
- 'user_email' => $current_user->user_email,
39
- );
40
-
41
- if ( defined( 'LEADIN_REFERRAL_SOURCE' ) ) {
42
- $leadin_user['referral_source'] = LEADIN_REFERRAL_SOURCE;
43
- } else {
44
- $leadin_user['referral_source'] = '';
45
- }
46
-
47
- if ( defined( 'LEADIN_UTM_SOURCE' ) ) {
48
- $leadin_user['utm_source'] = LEADIN_UTM_SOURCE;
49
- } else {
50
- $leadin_user['utm_source'] = '';
51
- }
52
-
53
- if ( defined( 'LEADIN_UTM_MEDIUM' ) ) {
54
- $leadin_user['utm_medium'] = LEADIN_UTM_MEDIUM;
55
- } else {
56
- $leadin_user['utm_medium'] = '';
57
- }
58
-
59
- if ( defined( 'LEADIN_UTM_TERM' ) ) {
60
- $leadin_user['utm_term'] = LEADIN_UTM_TERM;
61
- } else {
62
- $leadin_user['utm_term'] = '';
63
- }
64
-
65
- if ( defined( 'LEADIN_UTM_CONTENT' ) ) {
66
- $leadin_user['utm_content'] = LEADIN_UTM_CONTENT;
67
- } else {
68
- $leadin_user['utm_content'] = '';
69
- }
70
-
71
- if ( defined( 'LEADIN_UTM_CAMPAIGN' ) ) {
72
- $leadin_user['utm_campaign'] = LEADIN_UTM_CAMPAIGN;
73
- } else {
74
- $leadin_user['utm_campaign'] = '';
75
- }
76
-
77
- if ( ! empty( $leadinPortalId ) ) {
78
- $leadin_user['portal_id'] = $leadinPortalId;
79
- }
80
-
81
- return $leadin_user;
82
- }
83
-
84
  /**
85
  * Logs a debug statement to /wp-content/debug.log
86
  *
@@ -108,20 +35,93 @@ function leadin_get_user_role() {
108
  return $user_role;
109
  }
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  /**
112
  * Return the signup url based on the site options
113
  */
114
  function leadin_get_signup_url() {
 
115
  $acquisition_option = get_option( 'hubspot_acquisition_attribution', '' );
116
- $affiliate_code = get_option( 'hubspot_affiliate_code' );
117
- $signup_url = LEADIN_BASE_URL . "/signup/wordpress?$acquisition_option";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  if ($affiliate_code) {
 
120
  $destination_url = rawurlencode($signup_url);
121
  return "https://mbsy.co/$affiliate_code?url=$destination_url";
122
  }
123
 
124
- return "$signup_url&utm_source=wordpress-plugin&utm_medium=marketplaces";
 
 
 
 
 
 
 
 
125
  }
126
 
127
  /**
@@ -144,7 +144,7 @@ function leadin_get_iframe_src() {
144
  }
145
 
146
  $pathname = preg_replace( $regex, "", $page );
147
- return LEADIN_BASE_URL."/hubspot-plugin/$portal_id/$pathname";
148
  }
149
 
150
  function leadin_get_background_iframe_src() {
@@ -155,5 +155,5 @@ function leadin_get_background_iframe_src() {
155
  $portal_id_url = "/$portal_id";
156
  }
157
 
158
- return LEADIN_BASE_URL . "/hubspot-plugin$portal_id_url/background";
159
  }
8
  DEFINE( 'LEADIN_PORTAL_ID', intval( get_option( 'leadin_portalId' ) ) );
9
  }
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  /**
12
  * Logs a debug statement to /wp-content/debug.log
13
  *
35
  return $user_role;
36
  }
37
 
38
+ /**
39
+ * Return query string from object
40
+ */
41
+ function leadin_http_build_query($arr) {
42
+ return http_build_query( $arr, null, ini_get('arg_separator.output'), PHP_QUERY_RFC3986 );
43
+ }
44
+
45
+ /**
46
+ * Return the given version until the patch version
47
+ * eg: 6.4.2.1-beta => 6.4.2
48
+ */
49
+ function leadin_parse_version($version) {
50
+ preg_match('/^\d+(\.\d+){0,2}/', $version, $match);
51
+ if ( empty( $match ) ) {
52
+ return '';
53
+ }
54
+ return $match[0];
55
+ }
56
+
57
+ function leadin_get_query_params() {
58
+ global $wp_version;
59
+
60
+ return leadin_http_build_query( array(
61
+ 'l' => get_locale(),
62
+ 'php' => leadin_parse_version( phpversion() ),
63
+ 'v' => get_option( 'LEADIN_PLUGIN_VERSION' ),
64
+ 'wp' => leadin_parse_version( $wp_version ),
65
+ ) );
66
+ }
67
+
68
+ /**
69
+ * Return the affiliate code
70
+ */
71
+ function leadin_get_affiliate_code() {
72
+ $affiliate_link = get_option( 'hubspot_affiliate_code' );
73
+ preg_match('/(?:(?:hubs\.to)|(?:mbsy\.co))\/([a-zA-Z0-9]+)/', $affiliate_link, $matches);
74
+ if (sizeof($matches) === 2) {
75
+ return $matches[1];
76
+ } else {
77
+ return $affiliate_link;
78
+ }
79
+ }
80
+
81
  /**
82
  * Return the signup url based on the site options
83
  */
84
  function leadin_get_signup_url() {
85
+ // Get attribution string.
86
  $acquisition_option = get_option( 'hubspot_acquisition_attribution', '' );
87
+ parse_str( $acquisition_option, $signup_params );
88
+
89
+ // Get leadin query.
90
+ $leadin_query = leadin_get_query_params();
91
+ parse_str( $leadin_query, $leadin_params );
92
+
93
+ $signup_params = array_merge( $signup_params, $leadin_params );
94
+
95
+ // Add signup pre-fill info.
96
+ $wp_user = wp_get_current_user();
97
+ $signup_params['firstName'] = $wp_user->user_firstname;
98
+ $signup_params['lastName'] = $wp_user->user_lastname;
99
+ $signup_params['email'] = $wp_user->user_email;
100
+ $signup_params['company'] = get_bloginfo( 'name' );
101
+ $signup_params['domain'] = get_site_url();
102
+
103
+ $affiliate_code = leadin_get_affiliate_code();
104
+ $signup_url = LEADIN_SIGNUP_BASE_URL . '/signup/wordpress?';
105
+
106
+ if (LEADIN_SIGNUP_BASE_URL !== LEADIN_BASE_URL) {
107
+ $signup_params['redirectBaseUrl'] = LEADIN_BASE_URL;
108
+ }
109
 
110
  if ($affiliate_code) {
111
+ $signup_url .= leadin_http_build_query( $signup_params );
112
  $destination_url = rawurlencode($signup_url);
113
  return "https://mbsy.co/$affiliate_code?url=$destination_url";
114
  }
115
 
116
+ $signup_params['utm_source'] = 'wordpress-plugin';
117
+ $signup_params['utm_medium'] = 'marketplaces';
118
+
119
+ return $signup_url . leadin_http_build_query( $signup_params );
120
+ }
121
+
122
+ function leadin_get_ajax_url() {
123
+ $ajaxUrl = get_admin_url( get_current_blog_id(), 'admin-ajax.php' );
124
+ return is_ssl() ? str_replace( 'http:', 'https:', $ajaxUrl ) : str_replace( 'https:', 'http:', $ajaxUrl );
125
  }
126
 
127
  /**
144
  }
145
 
146
  $pathname = preg_replace( $regex, "", $page );
147
+ return LEADIN_BASE_URL . "/hubspot-plugin/$portal_id/$pathname?" . leadin_get_query_params();
148
  }
149
 
150
  function leadin_get_background_iframe_src() {
155
  $portal_id_url = "/$portal_id";
156
  }
157
 
158
+ return LEADIN_BASE_URL . "/hubspot-plugin$portal_id_url/background?" . leadin_get_query_params();
159
  }
inc/leadin-mark-outdated.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
3
+ wp_die( '', '', 403 );
4
+ }
5
+
6
+ if ( is_admin() ) {
7
+ add_action( 'wp_ajax_leadin_mark_outdated', 'mark_outdated_ajax' );
8
+ }
9
+
10
+ function mark_outdated_ajax() {
11
+ update_option( 'leadin_outdated_version', true );
12
+ wp_die( '{"message": "Success!"}' );
13
+ }
inc/leadin-wp-get.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
3
+ wp_die( '', '', 403 );
4
+ }
5
+
6
+ if ( is_admin() ) {
7
+ add_action( 'wp_ajax_leadin_get_portal', 'leadin_get_portal_ajax' );
8
+ add_action( 'wp_ajax_leadin_get_domain', 'leadin_get_domain_ajax' );
9
+ }
10
+
11
+ function leadin_get_portal_ajax() {
12
+ $portal_id = get_option( 'leadin_portalId' );
13
+ wp_die( json_encode( array ( 'portalId' => $portal_id ) ) );
14
+ }
15
+
16
+ function leadin_get_domain_ajax() {
17
+ $domain = get_site_url();
18
+ wp_die( json_encode( array ( 'domain' => $domain ) ) );
19
+ }
leadin.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: HubSpot All-In-One Marketing - Forms, Popups, Live Chat
4
  * Plugin URI: http://www.hubspot.com/integrations/wordpress
5
  * Description: HubSpot’s official WordPress plugin allows you to add forms, popups, and live chat to your website and integrate with the best WordPress CRM.
6
- * Version: 7.4.1
7
  * Author: HubSpot
8
  * Author URI: http://www.hubspot.com
9
  * License: GPL v3
@@ -60,7 +60,7 @@ if ( ! defined( 'LEADIN_DB_VERSION' ) ) {
60
  }
61
 
62
  if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
63
- define( 'LEADIN_PLUGIN_VERSION', '7.4.1' );
64
  }
65
 
66
  if ( ! defined( 'LEADIN_SOURCE' ) ) {
@@ -87,6 +87,10 @@ if ( ! defined( 'LEADIN_BASE_URL' ) ) {
87
  define( 'LEADIN_BASE_URL', 'https://app.hubspot.com' );
88
  }
89
 
 
 
 
 
90
  // =============================================
91
  // Include Needed Files
92
  // =============================================
@@ -97,6 +101,8 @@ if ( file_exists( LEADIN_PLUGIN_DIR . '/inc/leadin-constants.php' ) ) {
97
  require_once LEADIN_PLUGIN_DIR . '/inc/leadin-functions.php';
98
  require_once LEADIN_PLUGIN_DIR . '/inc/leadin-registration.php';
99
  require_once LEADIN_PLUGIN_DIR . '/inc/leadin-disconnect.php';
 
 
100
  require_once LEADIN_PLUGIN_DIR . '/admin/leadin-admin.php';
101
 
102
  require_once LEADIN_PLUGIN_DIR . '/inc/class-leadin.php';
3
  * Plugin Name: HubSpot All-In-One Marketing - Forms, Popups, Live Chat
4
  * Plugin URI: http://www.hubspot.com/integrations/wordpress
5
  * Description: HubSpot’s official WordPress plugin allows you to add forms, popups, and live chat to your website and integrate with the best WordPress CRM.
6
+ * Version: 7.5.0
7
  * Author: HubSpot
8
  * Author URI: http://www.hubspot.com
9
  * License: GPL v3
60
  }
61
 
62
  if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
63
+ define( 'LEADIN_PLUGIN_VERSION', '7.5.0' );
64
  }
65
 
66
  if ( ! defined( 'LEADIN_SOURCE' ) ) {
87
  define( 'LEADIN_BASE_URL', 'https://app.hubspot.com' );
88
  }
89
 
90
+ if ( ! defined( 'LEADIN_SIGNUP_BASE_URL' ) ) {
91
+ define( 'LEADIN_SIGNUP_BASE_URL', LEADIN_BASE_URL );
92
+ }
93
+
94
  // =============================================
95
  // Include Needed Files
96
  // =============================================
101
  require_once LEADIN_PLUGIN_DIR . '/inc/leadin-functions.php';
102
  require_once LEADIN_PLUGIN_DIR . '/inc/leadin-registration.php';
103
  require_once LEADIN_PLUGIN_DIR . '/inc/leadin-disconnect.php';
104
+ require_once LEADIN_PLUGIN_DIR . '/inc/leadin-wp-get.php';
105
+ require_once LEADIN_PLUGIN_DIR . '/inc/leadin-mark-outdated.php';
106
  require_once LEADIN_PLUGIN_DIR . '/admin/leadin-admin.php';
107
 
108
  require_once LEADIN_PLUGIN_DIR . '/inc/class-leadin.php';
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: forms, popup, live chat, contact form, crm, newsletter, marketing, lead ge
6
  Requires at least: 4.0
7
  Tested up to: 5.2
8
  Requires PHP: 5.6
9
- Stable tag: 7.4.1
10
 
11
  HubSpot All-In-One Marketing, is a free all-in-one marketing plugin that allows you to easily use HubSpot forms, popups, and live chat on your WordPress site. If you’re already a HubSpot user, the plugin lets you connect your HubSpot account to your website without any code.
12
 
@@ -164,18 +164,17 @@ Please <a href="https://community.hubspot.com?utm_source=wordpress-plugin-listin
164
 
165
  == Changelog ==
166
 
167
- - Current version: 7.4.1
168
- - Current version release: 2019-05-07
169
-
170
- = 7.4.1 (2019.05.07) =
171
- - Implement faster navigation
172
- - Fix signup url
173
- - Use i18n on PHP
174
-
175
- = 7.4.0 (2019.04.30) =
176
- - Improve performances
177
- - Remove dependencies from HubSpot's CDN
178
- - Update license
179
 
180
  = 7.0.0 (2018.10.03) =
181
  - Add deeper integration with HubSpot. Starts a new release of a new forms integration within WordPress. Released progressively for some users.
6
  Requires at least: 4.0
7
  Tested up to: 5.2
8
  Requires PHP: 5.6
9
+ Stable tag: 7.5.0
10
 
11
  HubSpot All-In-One Marketing, is a free all-in-one marketing plugin that allows you to easily use HubSpot forms, popups, and live chat on your WordPress site. If you’re already a HubSpot user, the plugin lets you connect your HubSpot account to your website without any code.
12
 
164
 
165
  == Changelog ==
166
 
167
+ - Current version: 7.5.0
168
+ - Current version release: 2019-05-22
169
+
170
+ = 7.5.0 (2019.05.22) =
171
+ - Add banner to inform users if the version is outdated
172
+ - Add notification that informs user if something is not working on our
173
+ servers
174
+ - Reload window when connection happens on a different tab
175
+ - Reduce loading time for non authenticated users
176
+ - Improve performances when navigating between pages
177
+ - Add tests
 
178
 
179
  = 7.0.0 (2018.10.03) =
180
  - Add deeper integration with HubSpot. Starts a new release of a new forms integration within WordPress. Released progressively for some users.
scripts/leadin.js CHANGED
@@ -1,8 +1,8 @@
1
  (function($) {
2
  'use strict';
3
  // HubSpot Env
4
- var leadinConfig = window.leadin_config || {};
5
- var i18n = window.leadin_i18n || {};
6
  var hubspotBaseUrl = leadinConfig.hubspotBaseUrl;
7
  var portalId = leadinConfig.portalId;
8
 
@@ -15,14 +15,22 @@
15
  }
16
 
17
  Raven.config(
18
- 'https://e9b8f382cdd130c0d415cd977d2be56f@exceptions.hubspot.com/1'
 
 
 
 
 
19
  ).install();
20
 
 
 
 
 
 
 
21
  Raven.setUserContext({
22
  hub: leadinConfig.portalId,
23
- wp: leadinConfig.wpVersion,
24
- php: leadinConfig.phpVersion,
25
- v: leadinConfig.leadinPluginVersion,
26
  plugins: Object.keys(leadinConfig.plugins)
27
  .map(function(name, index) {
28
  return name + '#' + leadinConfig.plugins[name].Version;
@@ -112,8 +120,24 @@
112
  var Interframe = (function() {
113
  var eventBus = new EventBus();
114
 
 
 
 
 
 
 
 
115
  function handleMessage(message) {
116
- eventBus.trigger('message', message);
 
 
 
 
 
 
 
 
 
117
  }
118
 
119
  function handleMessageEvent(event) {
@@ -127,95 +151,164 @@
127
  }
128
  }
129
 
130
- function postMessage(message) {
131
- domElements.iframe.contentWindow.postMessage(
132
- JSON.stringify(message),
133
- hubspotBaseUrl
134
- );
135
- }
136
-
137
  return {
138
  init: function() {
139
  window.addEventListener('message', handleMessageEvent);
140
  },
141
- onMessage: function(callback) {
142
- eventBus.on('message', callback);
 
 
143
  },
144
  postMessage: postMessage,
145
- reply: function(message, payload) {
146
- var newMessage = Object.assign({}, message);
147
- newMessage.response = payload;
148
- postMessage(newMessage);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  },
 
 
 
 
150
  };
151
  })();
152
 
153
  /**
154
  * HubspotPluginUI API
155
  *
156
- * All outgoing messages are defined here
157
  */
158
  var HubspotPluginAPI = (function() {
159
- function setConfig() {
160
- Interframe.postMessage({ leadin_config: leadinConfig });
161
- }
162
-
163
  function changeRoute(route) {
164
  Interframe.postMessage({ leadin_change_route: route });
165
  }
166
 
 
 
 
 
167
  var api = {
168
- setConfig: setConfig,
169
  changeRoute: changeRoute,
 
 
 
 
 
 
 
 
 
170
  };
171
 
172
  return api;
173
  })();
174
 
175
  /**
176
- * Bridge API
177
  *
178
  * All incoming messages are handled here
179
  */
180
- var MessagesHandlers = (function() {
181
- var eventBus = new EventBus();
182
-
183
- eventBus.on('leadin_parent_ajax', function(event, payload, reply) {
184
- var ajaxPayload = Object.assign(
185
- {
186
- complete: Raven.wrap(function(jqXHR, textStatus) {
187
- var response = Object.assign({ textStatus: textStatus }, jqXHR);
188
- reply(response);
189
- }),
190
- error: Raven.wrap(function(jqXHR) {
191
- var message;
192
-
193
- try {
194
- message = JSON.parse(jqXHR.responseText).error;
195
- } catch (e) {
196
- message = jqXHR.responseText;
197
- }
198
 
199
- Raven.captureMessage(
200
- 'AJAX request failed with code ' + jqXHR.status + ': ' + message
201
- );
202
- // TODO: sentry
203
- }),
 
204
  },
205
- payload
206
  );
207
- $.ajax(ajaxPayload);
208
  });
209
 
210
- eventBus.on('leadin_page_reload', function() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  window.location.reload();
212
  });
213
 
214
- eventBus.on('leadin_get_config', function() {
215
- HubspotPluginAPI.setConfig();
 
216
  });
217
 
218
- eventBus.on('leadin_clear_query_param', function() {
219
  var currentWindowLocation = window.location.toString();
220
  if (currentWindowLocation.indexOf('?') > 0) {
221
  currentWindowLocation = currentWindowLocation.substring(
@@ -227,17 +320,37 @@
227
  window.history.pushState({}, '', newWindowLocation);
228
  });
229
 
230
- return {
231
- start() {
232
- Interframe.onMessage(function(event, message) {
233
- function reply(payload) {
234
- Interframe.reply(message, payload);
235
- }
 
 
236
 
237
- for (var command in message) {
238
- eventBus.trigger(command, [message[command], reply]);
239
- }
240
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  },
242
  };
243
  })();
@@ -246,12 +359,14 @@
246
  * Main
247
  */
248
  function main() {
249
- MessagesHandlers.start();
250
  Interframe.init();
251
 
252
  // Enable App Navigation only when viewing the plugin
253
  if (window.location.search.indexOf('page=leadin') !== -1) {
254
- initNavigation();
 
 
255
  }
256
 
257
  initChatflows();
1
  (function($) {
2
  'use strict';
3
  // HubSpot Env
4
+ var leadinConfig = window.leadinConfig || {};
5
+ var i18n = window.leadinI18n || {};
6
  var hubspotBaseUrl = leadinConfig.hubspotBaseUrl;
7
  var portalId = leadinConfig.portalId;
8
 
15
  }
16
 
17
  Raven.config(
18
+ 'https://e9b8f382cdd130c0d415cd977d2be56f@exceptions.hubspot.com/1',
19
+ {
20
+ instrument: {
21
+ tryCatch: false,
22
+ },
23
+ }
24
  ).install();
25
 
26
+ Raven.setTagsContext({
27
+ leadin: leadinConfig.leadinPluginVersion,
28
+ php: leadinConfig.phpVersion,
29
+ wordpress: leadinConfig.wpVersion,
30
+ });
31
+
32
  Raven.setUserContext({
33
  hub: leadinConfig.portalId,
 
 
 
34
  plugins: Object.keys(leadinConfig.plugins)
35
  .map(function(name, index) {
36
  return name + '#' + leadinConfig.plugins[name].Version;
120
  var Interframe = (function() {
121
  var eventBus = new EventBus();
122
 
123
+ function postMessage(message) {
124
+ domElements.iframe.contentWindow.postMessage(
125
+ JSON.stringify(message),
126
+ hubspotBaseUrl
127
+ );
128
+ }
129
+
130
  function handleMessage(message) {
131
+ function reply(payload) {
132
+ const newMessage = Object.assign({}, message);
133
+ newMessage.response = payload;
134
+ postMessage(newMessage);
135
+ }
136
+
137
+ let key;
138
+ for (key in message) {
139
+ eventBus.trigger(key, [message[key], reply]);
140
+ }
141
  }
142
 
143
  function handleMessageEvent(event) {
151
  }
152
  }
153
 
 
 
 
 
 
 
 
154
  return {
155
  init: function() {
156
  window.addEventListener('message', handleMessageEvent);
157
  },
158
+ onMessage: function(key, callback) {
159
+ eventBus.on(key, function() {
160
+ callback.apply(null, Array.prototype.slice.call(arguments, 1));
161
+ });
162
  },
163
  postMessage: postMessage,
164
+ };
165
+ })();
166
+
167
+ /**
168
+ * WordPress plugin API
169
+ */
170
+ var WordPressPluginApi = (function() {
171
+ function makeRequest(action, method, payload, success, error) {
172
+ const url = leadinConfig.ajaxUrl + '?action=' + action;
173
+ const ajaxPayload = {
174
+ url: url,
175
+ method: method,
176
+ contentType: 'application/json',
177
+ success:
178
+ typeof success === 'function'
179
+ ? Raven.wrap(function(data) {
180
+ success(JSON.parse(data));
181
+ })
182
+ : undefined,
183
+ error: Raven.wrap(function(jqXHR) {
184
+ var message;
185
+
186
+ try {
187
+ message = JSON.parse(jqXHR.responseText).error;
188
+ } catch (e) {
189
+ message = jqXHR.responseText;
190
+ }
191
+
192
+ Raven.captureMessage(
193
+ 'AJAX request failed with code ' + jqXHR.status + ': ' + message
194
+ );
195
+
196
+ if (typeof error === 'function') {
197
+ error();
198
+ }
199
+ }),
200
+ };
201
+
202
+ if (payload) {
203
+ ajaxPayload.data = JSON.stringify(payload);
204
+ }
205
+
206
+ $.ajax(ajaxPayload);
207
+ }
208
+
209
+ function post(action, payload, success, error) {
210
+ return makeRequest(action, 'POST', payload, success, error);
211
+ }
212
+
213
+ function get(action, success, error) {
214
+ return makeRequest(action, 'GET', null, success, error);
215
+ }
216
+
217
+ return {
218
+ connect: function(portalId, success, error) {
219
+ post(
220
+ 'leadin_registration_ajax',
221
+ { portalId: portalId },
222
+ success,
223
+ error
224
+ );
225
  },
226
+ disconnect: post.bind(null, 'leadin_disconnect_ajax', {}),
227
+ getPortal: get.bind(null, 'leadin_get_portal'),
228
+ getDomain: get.bind(null, 'leadin_get_domain'),
229
+ markAsOutdated: get.bind(null, 'leadin_mark_outdated'),
230
  };
231
  })();
232
 
233
  /**
234
  * HubspotPluginUI API
235
  *
236
+ * All incoming and outgoing messages are defined here
237
  */
238
  var HubspotPluginAPI = (function() {
 
 
 
 
239
  function changeRoute(route) {
240
  Interframe.postMessage({ leadin_change_route: route });
241
  }
242
 
243
+ function createHandler(key) {
244
+ return Interframe.onMessage.bind(Interframe, key);
245
+ }
246
+
247
  var api = {
 
248
  changeRoute: changeRoute,
249
+ onInterframeReady: createHandler('leadin_interframe_ready'),
250
+ onConnect: createHandler('leadin_connect_portal'),
251
+ onDisconnect: createHandler('leadin_disconnect_portal'),
252
+ onPageReload: createHandler('leadin_page_reload'),
253
+ onInitNavigation: createHandler('leadin_init_navigation'),
254
+ onClearQueryParam: createHandler('leadin_clear_query_param'),
255
+ onGetDomain: createHandler('leadin_get_wp_domain'),
256
+ onMarkAsOutdated: createHandler('leadin_mark_outdated'),
257
+ onUpgrade: createHandler('leadin_upgrade'),
258
  };
259
 
260
  return api;
261
  })();
262
 
263
  /**
264
+ * Messages handlers
265
  *
266
  * All incoming messages are handled here
267
  */
268
+ var initMessageHandlers = function() {
269
+ HubspotPluginAPI.onInterframeReady(function(message, reply) {
270
+ reply('Interframe Ready');
271
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
+ HubspotPluginAPI.onConnect(function(portalId, reply) {
274
+ WordPressPluginApi.connect(
275
+ portalId,
276
+ function() {
277
+ PortalPoll.clear();
278
+ reply({ success: true });
279
  },
280
+ reply.bind(null, { success: false })
281
  );
 
282
  });
283
 
284
+ HubspotPluginAPI.onDisconnect(function(message, reply) {
285
+ WordPressPluginApi.disconnect(
286
+ reply.bind(null, { success: true }),
287
+ reply.bind(null, { success: false })
288
+ );
289
+ });
290
+
291
+ HubspotPluginAPI.onMarkAsOutdated(function(message, reply) {
292
+ WordPressPluginApi.markAsOutdated(function() {
293
+ reply();
294
+ });
295
+ });
296
+
297
+ HubspotPluginAPI.onUpgrade(function(message, reply) {
298
+ reply();
299
+ location.href = leadinConfig.adminUrl + 'plugins.php';
300
+ });
301
+
302
+ HubspotPluginAPI.onPageReload(function() {
303
  window.location.reload();
304
  });
305
 
306
+ HubspotPluginAPI.onInitNavigation(function(message, reply) {
307
+ initNavigation();
308
+ reply('SPA Navigation Started');
309
  });
310
 
311
+ HubspotPluginAPI.onClearQueryParam(function() {
312
  var currentWindowLocation = window.location.toString();
313
  if (currentWindowLocation.indexOf('?') > 0) {
314
  currentWindowLocation = currentWindowLocation.substring(
320
  window.history.pushState({}, '', newWindowLocation);
321
  });
322
 
323
+ HubspotPluginAPI.onGetDomain(function(message, reply) {
324
+ WordPressPluginApi.getDomain(function(data) {
325
+ if (data.domain) {
326
+ reply(data.domain);
327
+ }
328
+ });
329
+ });
330
+ };
331
 
332
+ /**
333
+ * Reload as soon as a portal was assigned. This prevents multiple registration happening
334
+ */
335
+ const PortalPoll = (function() {
336
+ let timeout;
337
+ let stop = false;
338
+
339
+ return {
340
+ init: function() {
341
+ timeout = setTimeout(function() {
342
+ WordPressPluginApi.getPortal(function(data) {
343
+ if (data.portalId) {
344
+ location.reload();
345
+ } else if (!stop) {
346
+ PortalPoll.init();
347
+ }
348
+ }, PortalPoll.init);
349
+ }, 5000);
350
+ },
351
+ clear: function() {
352
+ clearTimeout(timeout);
353
+ stop = true;
354
  },
355
  };
356
  })();
359
  * Main
360
  */
361
  function main() {
362
+ initMessageHandlers();
363
  Interframe.init();
364
 
365
  // Enable App Navigation only when viewing the plugin
366
  if (window.location.search.indexOf('page=leadin') !== -1) {
367
+ if (!leadinConfig.portalId) {
368
+ PortalPoll.init();
369
+ }
370
  }
371
 
372
  initChatflows();