Version Description
(2019.03.25) = - Add helpers for acceptance tests - Remove dialog on settings page - Load forms script from right environment - Test on PHP 5.6 - Design fixes on the intro page
Download this release
Release Info
Developer | leadin |
Plugin | HubSpot – Free Marketing Plugin for WordPress |
Version | 7.0.7 |
Comparing to | |
See all releases |
Code changes from version 7.0.5 to 7.0.7
- admin/leadin-admin.php +246 -243
- inc/class-leadin.php +126 -126
- inc/leadin-constants.php +4 -4
- inc/leadin-disconnect.php +16 -18
- inc/leadin-functions.php +80 -81
- inc/leadin-oauth-refresh.php +3 -6
- inc/leadin-registration.php +43 -39
- leadin.php +125 -114
- readme.txt +13 -3
admin/leadin-admin.php
CHANGED
@@ -1,15 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
4 |
-
|
5 |
-
die;
|
6 |
}
|
7 |
|
8 |
// =============================================
|
9 |
// Define Constants
|
10 |
// =============================================
|
11 |
if ( ! defined( 'LEADIN_ADMIN_PATH' ) ) {
|
12 |
-
|
13 |
}
|
14 |
|
15 |
// =============================================
|
@@ -28,98 +27,98 @@ function action_required_notice(){
|
|
28 |
class WPLeadInAdmin {
|
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 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
|
124 |
$notificationIcon = '';
|
125 |
if ( ! get_option( 'leadin_portalId' ) ) {
|
@@ -127,154 +126,158 @@ class WPLeadInAdmin {
|
|
127 |
add_action('admin_notices', 'action_required_notice');
|
128 |
}
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
|
|
|
|
|
|
|
|
278 |
|
279 |
}
|
280 |
|
1 |
<?php
|
2 |
|
3 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
4 |
+
wp_die( '', '', 403 );
|
|
|
5 |
}
|
6 |
|
7 |
// =============================================
|
8 |
// Define Constants
|
9 |
// =============================================
|
10 |
if ( ! defined( 'LEADIN_ADMIN_PATH' ) ) {
|
11 |
+
define( 'LEADIN_ADMIN_PATH', untrailingslashit( __FILE__ ) );
|
12 |
}
|
13 |
|
14 |
// =============================================
|
27 |
class WPLeadInAdmin {
|
28 |
|
29 |
|
30 |
+
var $li_viewers;
|
31 |
+
var $stats_dashboard;
|
32 |
+
var $action;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Class constructor
|
36 |
+
*/
|
37 |
+
function __construct() {
|
38 |
+
// =============================================
|
39 |
+
// Hooks & Filters
|
40 |
+
// =============================================
|
41 |
+
$plugin_version = get_option( 'leadin_pluginVersion' );
|
42 |
+
|
43 |
+
$this->action = $this->leadin_current_action();
|
44 |
+
|
45 |
+
// If the plugin version matches the latest version escape the update function
|
46 |
+
if ( $plugin_version != LEADIN_PLUGIN_VERSION ) {
|
47 |
+
self::leadin_update_check();
|
48 |
+
}
|
49 |
+
|
50 |
+
add_action( 'admin_menu', array( &$this, 'leadin_add_menu_items' ) );
|
51 |
+
add_action( 'admin_print_scripts', array( &$this, 'add_leadin_admin_scripts' ) );
|
52 |
+
add_action( 'admin_enqueue_scripts', array( &$this, 'add_leadin_global_admin_style' ) );
|
53 |
+
add_filter( 'plugin_action_links_' . 'leadin/leadin.php', array( $this, 'leadin_plugin_settings_link' ) );
|
54 |
+
|
55 |
+
if ($affiliate = $this->get_affiliate_code()) {
|
56 |
+
add_option( 'hubspot_affiliate_code', $affiliate );
|
57 |
+
}
|
58 |
+
$this->hydrate_acquisition_attribution();
|
59 |
+
}
|
60 |
+
|
61 |
+
function get_affiliate_code() {
|
62 |
+
$affiliate = get_option( 'hubspot_affiliate_code');
|
63 |
+
if (!$affiliate && file_exists(LEADIN_PLUGIN_DIR . '/hs_affiliate.txt' )) {
|
64 |
+
$affiliate = trim(preg_replace('/\s\s+/', ' ', file_get_contents(LEADIN_PLUGIN_DIR . '/hs_affiliate.txt')));
|
65 |
+
}
|
66 |
+
if ($affiliate) {
|
67 |
+
return $affiliate;
|
68 |
+
}
|
69 |
+
return false;
|
70 |
+
}
|
71 |
+
|
72 |
+
function get_acquisition_attribution_option() {
|
73 |
+
return get_option('hubspot_acquisition_attribution');
|
74 |
+
}
|
75 |
+
|
76 |
+
function hydrate_acquisition_attribution() {
|
77 |
+
if ($this->get_acquisition_attribution_option()) {
|
78 |
+
return;
|
79 |
+
}
|
80 |
+
|
81 |
+
if (file_exists(LEADIN_PLUGIN_DIR . '/hs_attribution.txt' )) {
|
82 |
+
$acquisition_attribution = trim(file_get_contents(LEADIN_PLUGIN_DIR . '/hs_attribution.txt'));
|
83 |
+
add_option('hubspot_acquisition_attribution', $acquisition_attribution);
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
function leadin_update_check() {
|
88 |
+
update_option( 'leadin_pluginVersion', LEADIN_PLUGIN_VERSION );
|
89 |
+
}
|
90 |
+
|
91 |
+
// =============================================
|
92 |
+
// Menus
|
93 |
+
// =============================================
|
94 |
+
/**
|
95 |
+
* Adds Leadin menu to /wp-admin sidebar
|
96 |
+
*/
|
97 |
+
function leadin_add_menu_items() {
|
98 |
+
$options = get_option( 'leadin_options' );
|
99 |
+
|
100 |
+
global $submenu;
|
101 |
+
global $wp_version;
|
102 |
+
|
103 |
+
// Block non-sanctioned users from accessing Leadin
|
104 |
+
$capability = 'activate_plugins';
|
105 |
+
if ( ! current_user_can( 'activate_plugins' ) ) {
|
106 |
+
if ( ! array_key_exists( 'li_grant_access_to_' . leadin_get_user_role(), $options ) ) {
|
107 |
+
return false;
|
108 |
+
} else {
|
109 |
+
if ( current_user_can( 'manage_network' ) ) { // super admin
|
110 |
+
$capability = 'manage_network';
|
111 |
+
} elseif ( current_user_can( 'edit_pages' ) ) { // editor
|
112 |
+
$capability = 'edit_pages';
|
113 |
+
} elseif ( current_user_can( 'publish_posts' ) ) { // author
|
114 |
+
$capability = 'publish_posts';
|
115 |
+
} elseif ( current_user_can( 'edit_posts' ) ) { // contributor
|
116 |
+
$capability = 'edit_posts';
|
117 |
+
} elseif ( current_user_can( 'read' ) ) { // subscriber
|
118 |
+
$capability = 'read';
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
|
123 |
$notificationIcon = '';
|
124 |
if ( ! get_option( 'leadin_portalId' ) ) {
|
126 |
add_action('admin_notices', 'action_required_notice');
|
127 |
}
|
128 |
|
129 |
+
add_menu_page( 'HubSpot', 'HubSpot'.$notificationIcon, $capability, 'leadin', array( $this, 'leadin_build_app' ), 'dashicons-sprocket', '25.100713' );
|
130 |
+
|
131 |
+
$oAuthMode = get_option('leadin_oauth_mode');
|
132 |
+
if ($oAuthMode && $oAuthMode == '1') {
|
133 |
+
add_submenu_page('leadin', 'Forms', 'Forms', 'activate_plugins', 'leadin_forms', array($this, 'leadin_build_app'));
|
134 |
+
add_submenu_page('leadin', 'Settings', 'Settings', 'activate_plugins', 'leadin_settings', array($this, 'leadin_build_app'));
|
135 |
+
remove_submenu_page('leadin','leadin');
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
// =============================================
|
140 |
+
// Settings Page
|
141 |
+
// =============================================
|
142 |
+
/**
|
143 |
+
* Adds setting link for Leadin to plugins management page
|
144 |
+
*
|
145 |
+
* @param array $links
|
146 |
+
* @return array
|
147 |
+
*/
|
148 |
+
function leadin_plugin_settings_link( $links ) {
|
149 |
+
$oAuthMode = get_option('leadin_oauth_mode');
|
150 |
+
if ($oAuthMode && $oAuthMode == '1') {
|
151 |
+
$page = "leadin_settings";
|
152 |
+
} else {
|
153 |
+
$page = "leadin";
|
154 |
+
}
|
155 |
+
$url = get_admin_url( get_current_blog_id(), "admin.php?page=$page" );
|
156 |
+
$settings_link = '<a href="' . $url . '">Settings</a>';
|
157 |
+
array_unshift( $links, $settings_link );
|
158 |
+
return $links;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Creates leadin app
|
163 |
+
*/
|
164 |
+
|
165 |
+
function leadin_build_app() {
|
166 |
+
global $wp_version;
|
167 |
+
|
168 |
+
echo '<div id="leadin" class="wrap ' . ( $wp_version < 3.8 && ! is_plugin_active( 'mp6/mp6.php' ) ? 'pre-mp6' : '' ) . '"></div>';
|
169 |
+
|
170 |
+
wp_enqueue_style( 'leadin-bridge-css' );
|
171 |
+
wp_enqueue_script( 'leadin-bridge-app' );
|
172 |
+
|
173 |
+
}
|
174 |
+
|
175 |
+
function update_option_leadin_options_callback( $old_value, $new_value ) {
|
176 |
+
}
|
177 |
+
|
178 |
+
// =============================================
|
179 |
+
// Admin Styles & Scripts
|
180 |
+
// =============================================
|
181 |
+
/**
|
182 |
+
* Adds admin javascript
|
183 |
+
*/
|
184 |
+
function add_leadin_admin_scripts() {
|
185 |
+
global $pagenow;
|
186 |
+
global $wp_roles;
|
187 |
+
global $wp_version;
|
188 |
+
|
189 |
+
$ajaxUrl = get_admin_url( get_current_blog_id(), 'admin-ajax.php' );
|
190 |
+
$wpUser = wp_get_current_user();
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Note! Some of this information will be sent to Sentry on errors.
|
194 |
+
* If you add any sensitive information, make sure to delete it here
|
195 |
+
* https://git.hubteam.com/HubSpot/hubspot-plugin-ui/blob/cd3818adaa91fb83dc7f053956995247c878bb63/bridge/static/js/leadinWordPressShell.js#L14
|
196 |
+
*/
|
197 |
+
$leadin_config = array(
|
198 |
+
'portalId' => get_option( 'leadin_portalId' ),
|
199 |
+
'affiliateCode' => get_option( 'hubspot_affiliate_code' ),
|
200 |
+
'acquisitionAttributionParams' => $this->get_acquisition_attribution_option(),
|
201 |
+
'slumberMode' => get_option( 'leadin_slumber_mode' ),
|
202 |
+
'env' => constant( 'LEADIN_ENV' ),
|
203 |
+
'user' => $this->leadin_get_user_for_tracking(),
|
204 |
+
'allRoles' => $wp_roles->get_names(),
|
205 |
+
'leadinPluginVersion' => constant( 'LEADIN_PLUGIN_VERSION' ),
|
206 |
+
'wpVersion' => $wp_version,
|
207 |
+
'siteUrl' => get_site_url(),
|
208 |
+
'adminEmail' => get_option( 'admin_email' ),
|
209 |
+
'siteName' => get_bloginfo( 'name' ),
|
210 |
+
'adminBaseUrl' => get_admin_url( get_current_blog_id(), 'admin.php' ),
|
211 |
+
'leadinPluginDirectory' => LEADIN_PLUGIN_SLUG,
|
212 |
+
'ajaxUrl' => is_ssl() ? str_replace( 'http:', 'https:', $ajaxUrl ) : str_replace( 'https:', 'http:', $ajaxUrl ),
|
213 |
+
'locale' => get_locale(),
|
214 |
+
'timezone' => get_option( 'gmt_offset' ),
|
215 |
+
'timezoneString' => get_option( 'timezone_string' ), // If not set by the user manually it will be an empty string
|
216 |
+
'oAuthMode' => get_option( 'leadin_oauth_mode' ),
|
217 |
+
'connectionTimeInMs' => get_option( 'leadin_connectionTimeInMs' ),
|
218 |
+
'plugins' => get_plugins(),
|
219 |
+
'phpVersion' => phpversion(),
|
220 |
+
'wpUserFirstName' => $wpUser->user_firstname,
|
221 |
+
'wpUserLastName' => $wpUser->user_lastname,
|
222 |
+
'wpUserEmail' => $wpUser->user_email,
|
223 |
+
);
|
224 |
+
|
225 |
+
if ( ( $pagenow == 'admin.php' && isset( $_GET['page'] ) && strstr( $_GET['page'], 'leadin' ) ) ) { // WPCS: CSRF ok.
|
226 |
+
wp_register_script( 'leadin-head-js', leadin_get_resource_url( '/bundle/head/head.js' ), false, false, false );
|
227 |
+
wp_localize_script( 'leadin-head-js', 'leadin_config', $leadin_config );
|
228 |
+
wp_enqueue_script( 'leadin-head-js' );
|
229 |
+
|
230 |
+
wp_register_script( 'leadin-bridge-app', leadin_get_resource_url( '/bundle/app.js' ), array( 'backbone' ), false, true );
|
231 |
+
wp_register_style( 'leadin-bridge-css', leadin_get_resource_url( '/bundle/app.css' ) );
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
function add_leadin_global_admin_style() {
|
236 |
+
wp_register_style( 'leadin-css', LEADIN_PATH.'/assets/leadin.css' );
|
237 |
+
wp_enqueue_style( 'leadin-css' );
|
238 |
+
}
|
239 |
+
|
240 |
+
// =============================================
|
241 |
+
// Internal Class Functions
|
242 |
+
// =============================================
|
243 |
+
function leadin_get_user_for_tracking() {
|
244 |
+
$leadin_user = leadin_get_current_user();
|
245 |
+
$tracking_leadin_user = array(
|
246 |
+
'hashed_wp_url' => $leadin_user['user_id'],
|
247 |
+
'name' => $leadin_user['alias'],
|
248 |
+
'email' => $leadin_user['email'],
|
249 |
+
'wp-url' => $leadin_user['wp_url'],
|
250 |
+
'wp-version' => $leadin_user['wp_version'],
|
251 |
+
'li-source' => LEADIN_SOURCE,
|
252 |
+
'website' => $leadin_user['wp_url'],
|
253 |
+
'company' => $leadin_user['wp_url'],
|
254 |
+
'utm_source' => $leadin_user['utm_source'],
|
255 |
+
'utm_medium' => $leadin_user['utm_medium'],
|
256 |
+
'utm_term' => $leadin_user['utm_term'],
|
257 |
+
'utm_content' => $leadin_user['utm_term'],
|
258 |
+
'utm_campaign' => $leadin_user['utm_campaign'],
|
259 |
+
'referral_source' => $leadin_user['referral_source'],
|
260 |
+
'user_email' => $leadin_user['user_email'],
|
261 |
+
);
|
262 |
+
return $tracking_leadin_user;
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* GET and set url actions into readable strings
|
267 |
+
*
|
268 |
+
* @return string if actions are set, bool if no actions set
|
269 |
+
*/
|
270 |
+
function leadin_current_action() {
|
271 |
+
if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) { // WPCS: CSRF ok.
|
272 |
+
return $_REQUEST['action']; // WPCS: CSRF ok.
|
273 |
+
}
|
274 |
+
|
275 |
+
if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) { // WPCS: CSRF ok.
|
276 |
+
return $_REQUEST['action2']; // WPCS: CSRF ok.
|
277 |
+
}
|
278 |
+
|
279 |
+
return false;
|
280 |
+
}
|
281 |
|
282 |
}
|
283 |
|
inc/class-leadin.php
CHANGED
@@ -5,132 +5,132 @@
|
|
5 |
// =============================================
|
6 |
class WPLeadIn {
|
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 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
}
|
135 |
|
136 |
// =============================================
|
5 |
// =============================================
|
6 |
class WPLeadIn {
|
7 |
|
8 |
+
/**
|
9 |
+
* Class constructor
|
10 |
+
*/
|
11 |
+
function __construct() {
|
12 |
+
global $pagenow;
|
13 |
+
|
14 |
+
if ( is_user_logged_in() ) {
|
15 |
+
add_action( 'admin_bar_menu', array( $this, 'add_leadin_link_to_admin_bar' ), 999 );
|
16 |
+
}
|
17 |
+
|
18 |
+
if ( is_admin() ) {
|
19 |
+
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
|
20 |
+
$li_wp_admin = new WPLeadInAdmin();
|
21 |
+
}
|
22 |
+
} else {
|
23 |
+
// Adds the leadin-tracking script to wp-login.php page which doesnt hook into the enqueue logic
|
24 |
+
if ( $this->leadin_is_login_or_register_page() ) {
|
25 |
+
add_action( 'login_enqueue_scripts', array( $this, 'add_leadin_frontend_scripts' ) );
|
26 |
+
} else {
|
27 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'add_leadin_frontend_scripts' ) );
|
28 |
+
}
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
// =============================================
|
33 |
+
// Scripts & Styles
|
34 |
+
// =============================================
|
35 |
+
/**
|
36 |
+
* Adds front end javascript + initializes ajax object
|
37 |
+
*/
|
38 |
+
|
39 |
+
function add_leadin_frontend_scripts() {
|
40 |
+
|
41 |
+
add_filter( 'script_loader_tag', array( $this, 'leadin_add_embed_script_attributes' ), 10, 2 );
|
42 |
+
|
43 |
+
$embedDomain = constant( 'LEADIN_SCRIPT_LOADER_DOMAIN' );
|
44 |
+
$portalId = get_option( 'leadin_portalId' );
|
45 |
+
$slumberMode = get_option( 'leadin_slumber_mode' );
|
46 |
+
|
47 |
+
if ( empty( $portalId ) ) {
|
48 |
+
echo '<!-- HubSpot embed JS disabled as a portalId has not yet been configured -->';
|
49 |
+
return;
|
50 |
+
}
|
51 |
+
|
52 |
+
$embedUrl = '//' . $embedDomain . '/' . $portalId . '.js?integration=wordpress';
|
53 |
+
$embedId = 'leadin-scriptloader-js';
|
54 |
+
|
55 |
+
if ( is_single() ) {
|
56 |
+
$page_type = 'post';
|
57 |
+
} elseif ( is_front_page() ) {
|
58 |
+
$page_type = 'home';
|
59 |
+
} elseif ( is_archive() ) {
|
60 |
+
$page_type = 'archive';
|
61 |
+
} elseif ( $this->leadin_is_login_or_register_page() ) {
|
62 |
+
$page_type = 'login';
|
63 |
+
} elseif ( is_page() ) {
|
64 |
+
$page_type = 'page';
|
65 |
+
} else {
|
66 |
+
$page_type = 'other';
|
67 |
+
}
|
68 |
+
|
69 |
+
$leadin_wordpress_info = array(
|
70 |
+
'userRole' => ( is_user_logged_in() ) ? leadin_get_user_role() : 'visitor',
|
71 |
+
'pageType' => $page_type,
|
72 |
+
'leadinPluginVersion' => LEADIN_PLUGIN_VERSION,
|
73 |
+
);
|
74 |
+
|
75 |
+
wp_register_script( $embedId, $embedUrl, array( 'jquery' ), false, true );
|
76 |
+
wp_localize_script( $embedId, 'leadin_wordpress', $leadin_wordpress_info );
|
77 |
+
wp_enqueue_script( $embedId );
|
78 |
+
$this->add_page_analytics();
|
79 |
+
}
|
80 |
+
|
81 |
+
/* HubSpot page analytics */
|
82 |
+
function add_page_analytics() {
|
83 |
+
echo "\n".'<!-- DO NOT COPY THIS SNIPPET! Start of Page Analytics Tracking for HubSpot WordPress plugin v'.LEADIN_PLUGIN_VERSION.' -->'."\n";
|
84 |
+
echo '<script type="text/javascript">'."\n";
|
85 |
+
|
86 |
+
echo 'var _hsq = _hsq || [];'."\n";
|
87 |
+
// Pass along the correct content-type
|
88 |
+
if ( is_single () ) {
|
89 |
+
echo '_hsq.push(["setContentType", "blog-post"]);' . "\n";
|
90 |
+
} else if ( is_archive () || is_search() ) {
|
91 |
+
echo '_hsq.push(["setContentType", "listing-page"]);' . "\n";
|
92 |
+
} else {
|
93 |
+
echo '_hsq.push(["setContentType", "standard-page"]);' . "\n";
|
94 |
+
}
|
95 |
+
|
96 |
+
echo '</script>'."\n";
|
97 |
+
echo '<!-- DO NOT COPY THIS SNIPPET! End of Page Analytics Tracking for HubSpot WordPress plugin -->'."\n";
|
98 |
+
}
|
99 |
+
|
100 |
+
function leadin_add_embed_script_attributes( $tag, $handle ) {
|
101 |
+
if ( $handle == 'leadin-scriptloader-js' ) {
|
102 |
+
return str_replace( ' src', ' async defer src', $tag );
|
103 |
+
} else {
|
104 |
+
return $tag;
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Adds Leadin link to top-level admin bar
|
110 |
+
*/
|
111 |
+
function add_leadin_link_to_admin_bar( $wp_admin_bar ) {
|
112 |
+
global $wp_version;
|
113 |
+
|
114 |
+
if ( ! current_user_can( 'activate_plugins' ) ) {
|
115 |
+
if ( ! array_key_exists( 'li_grant_access_to_' . leadin_get_user_role(), get_option( 'leadin_options' ) ) ) {
|
116 |
+
return false;
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
$args = array(
|
121 |
+
'id' => 'leadin-admin-menu',
|
122 |
+
'title' => "<span class='ab-icon'></span><span class='ab-label'>HubSpot</span>", // alter the title of existing node
|
123 |
+
'parent' => false, // set parent to false to make it a top level (parent) node
|
124 |
+
'href' => get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=leadin',
|
125 |
+
'meta' => array( 'title' => 'HubSpot' ),
|
126 |
+
);
|
127 |
+
|
128 |
+
$wp_admin_bar->add_node( $args );
|
129 |
+
}
|
130 |
+
|
131 |
+
public static function leadin_is_login_or_register_page() {
|
132 |
+
return in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) );
|
133 |
+
}
|
134 |
}
|
135 |
|
136 |
// =============================================
|
inc/leadin-constants.php
CHANGED
@@ -1,19 +1,19 @@
|
|
1 |
<?php
|
2 |
|
3 |
if ( ! defined( 'LEADIN_UTM_SOURCE' ) ) {
|
4 |
-
|
5 |
}
|
6 |
|
7 |
if ( ! defined( 'LEADIN_UTM_MEDIUM' ) ) {
|
8 |
-
|
9 |
}
|
10 |
|
11 |
if ( ! defined( 'LEADIN_UTM_CONTENT' ) ) {
|
12 |
-
|
13 |
}
|
14 |
|
15 |
if ( ! defined( 'LEADIN_UTM_CAMPAIGN' ) ) {
|
16 |
-
|
17 |
}
|
18 |
|
19 |
|
1 |
<?php
|
2 |
|
3 |
if ( ! defined( 'LEADIN_UTM_SOURCE' ) ) {
|
4 |
+
define( 'LEADIN_UTM_SOURCE', 'leadin%20repo%20plugin' );
|
5 |
}
|
6 |
|
7 |
if ( ! defined( 'LEADIN_UTM_MEDIUM' ) ) {
|
8 |
+
define( 'LEADIN_UTM_MEDIUM', 'referral' );
|
9 |
}
|
10 |
|
11 |
if ( ! defined( 'LEADIN_UTM_CONTENT' ) ) {
|
12 |
+
define( 'LEADIN_UTM_CONTENT', 'e10' );
|
13 |
}
|
14 |
|
15 |
if ( ! defined( 'LEADIN_UTM_CAMPAIGN' ) ) {
|
16 |
+
define( 'LEADIN_UTM_CAMPAIGN', 'one%20click%20updater' );
|
17 |
}
|
18 |
|
19 |
|
inc/leadin-disconnect.php
CHANGED
@@ -1,31 +1,29 @@
|
|
1 |
<?php
|
2 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
3 |
-
|
4 |
-
wp_die();
|
5 |
}
|
6 |
|
7 |
if ( is_admin() ) {
|
8 |
-
|
9 |
}
|
10 |
|
11 |
function leadin_disconnect_ajax() {
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
}
|
29 |
|
30 |
}
|
31 |
|
1 |
<?php
|
2 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
3 |
+
wp_die( '', '', 403 );
|
|
|
4 |
}
|
5 |
|
6 |
if ( is_admin() ) {
|
7 |
+
add_action( 'wp_ajax_leadin_disconnect_ajax', 'leadin_disconnect_ajax' ); // Call when user in slumber mode would like to disconnect their account
|
8 |
}
|
9 |
|
10 |
function leadin_disconnect_ajax() {
|
11 |
+
if ( get_option( 'leadin_portalId' ) ) {
|
12 |
+
delete_option( 'leadin_portalId' );
|
13 |
+
delete_option( 'leadin_slumber_mode' );
|
14 |
+
delete_option( 'leadin_hapikey' );
|
15 |
|
16 |
+
delete_option( 'leadin_accessToken' );
|
17 |
+
delete_option( 'leadin_refreshToken' );
|
18 |
+
delete_option( 'leadin_oauth_mode' );
|
19 |
+
delete_option( 'leadin_userId' );
|
20 |
+
delete_option( 'leadin_connectionTimeInMs' );
|
21 |
|
22 |
+
wp_die( '{"message": "Success!"}' );
|
23 |
+
} else {
|
24 |
+
error_log( 'Disconnect error' );
|
25 |
+
wp_die( '{"error": "No leadin_portalId found, cannot disconnect."}', '', 400 );
|
26 |
+
}
|
|
|
27 |
|
28 |
}
|
29 |
|
inc/leadin-functions.php
CHANGED
@@ -1,18 +1,17 @@
|
|
1 |
<?php
|
2 |
|
3 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
4 |
-
|
5 |
-
die;
|
6 |
}
|
7 |
|
8 |
if ( ! defined( 'LEADIN_PORTAL_ID' ) ) {
|
9 |
-
|
10 |
}
|
11 |
|
12 |
function leadin_get_resource_url( $path ) {
|
13 |
-
|
14 |
|
15 |
-
|
16 |
}
|
17 |
|
18 |
/**
|
@@ -21,71 +20,71 @@ function leadin_get_resource_url( $path ) {
|
|
21 |
* @return array
|
22 |
*/
|
23 |
function leadin_get_current_user() {
|
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 |
/**
|
@@ -94,25 +93,25 @@ function leadin_get_current_user() {
|
|
94 |
* @param string
|
95 |
*/
|
96 |
function leadin_log_debug( $message ) {
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
* Returns the user role for the current user
|
108 |
*/
|
109 |
function leadin_get_user_role() {
|
110 |
-
|
111 |
|
112 |
-
|
113 |
-
|
114 |
|
115 |
-
|
116 |
}
|
117 |
|
118 |
|
1 |
<?php
|
2 |
|
3 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
4 |
+
wp_die( '', '', 403 );
|
|
|
5 |
}
|
6 |
|
7 |
if ( ! defined( 'LEADIN_PORTAL_ID' ) ) {
|
8 |
+
DEFINE( 'LEADIN_PORTAL_ID', intval( get_option( 'leadin_portalId' ) ) );
|
9 |
}
|
10 |
|
11 |
function leadin_get_resource_url( $path ) {
|
12 |
+
$resource_root = constant( 'LEADIN_ADMIN_ASSETS_BASE_URL' );
|
13 |
|
14 |
+
return $resource_root . $path;
|
15 |
}
|
16 |
|
17 |
/**
|
20 |
* @return array
|
21 |
*/
|
22 |
function leadin_get_current_user() {
|
23 |
+
global $wp_version;
|
24 |
+
|
25 |
+
$current_user = wp_get_current_user();
|
26 |
+
$li_user_id = md5( get_bloginfo( 'wpurl' ) );
|
27 |
+
|
28 |
+
$li_options = get_option( 'leadin_options' );
|
29 |
+
$leadinPortalId = get_option( 'leadin_portalId' );
|
30 |
+
|
31 |
+
if ( isset( $li_options['li_email'] ) ) {
|
32 |
+
$li_user_email = $li_options['li_email'];
|
33 |
+
} else {
|
34 |
+
$li_user_email = $current_user->user_email;
|
35 |
+
}
|
36 |
+
|
37 |
+
$leadin_user = array(
|
38 |
+
'user_id' => $li_user_id,
|
39 |
+
'email' => $li_user_email,
|
40 |
+
'alias' => $current_user->display_name,
|
41 |
+
'wp_url' => get_bloginfo( 'wpurl' ),
|
42 |
+
'li_version' => LEADIN_PLUGIN_VERSION,
|
43 |
+
'wp_version' => $wp_version,
|
44 |
+
'user_email' => $current_user->user_email,
|
45 |
+
);
|
46 |
+
|
47 |
+
if ( defined( 'LEADIN_REFERRAL_SOURCE' ) ) {
|
48 |
+
$leadin_user['referral_source'] = LEADIN_REFERRAL_SOURCE;
|
49 |
+
} else {
|
50 |
+
$leadin_user['referral_source'] = '';
|
51 |
+
}
|
52 |
+
|
53 |
+
if ( defined( 'LEADIN_UTM_SOURCE' ) ) {
|
54 |
+
$leadin_user['utm_source'] = LEADIN_UTM_SOURCE;
|
55 |
+
} else {
|
56 |
+
$leadin_user['utm_source'] = '';
|
57 |
+
}
|
58 |
+
|
59 |
+
if ( defined( 'LEADIN_UTM_MEDIUM' ) ) {
|
60 |
+
$leadin_user['utm_medium'] = LEADIN_UTM_MEDIUM;
|
61 |
+
} else {
|
62 |
+
$leadin_user['utm_medium'] = '';
|
63 |
+
}
|
64 |
+
|
65 |
+
if ( defined( 'LEADIN_UTM_TERM' ) ) {
|
66 |
+
$leadin_user['utm_term'] = LEADIN_UTM_TERM;
|
67 |
+
} else {
|
68 |
+
$leadin_user['utm_term'] = '';
|
69 |
+
}
|
70 |
+
|
71 |
+
if ( defined( 'LEADIN_UTM_CONTENT' ) ) {
|
72 |
+
$leadin_user['utm_content'] = LEADIN_UTM_CONTENT;
|
73 |
+
} else {
|
74 |
+
$leadin_user['utm_content'] = '';
|
75 |
+
}
|
76 |
+
|
77 |
+
if ( defined( 'LEADIN_UTM_CAMPAIGN' ) ) {
|
78 |
+
$leadin_user['utm_campaign'] = LEADIN_UTM_CAMPAIGN;
|
79 |
+
} else {
|
80 |
+
$leadin_user['utm_campaign'] = '';
|
81 |
+
}
|
82 |
+
|
83 |
+
if ( ! empty( $leadinPortalId ) ) {
|
84 |
+
$leadin_user['portal_id'] = $leadinPortalId;
|
85 |
+
}
|
86 |
+
|
87 |
+
return $leadin_user;
|
88 |
}
|
89 |
|
90 |
/**
|
93 |
* @param string
|
94 |
*/
|
95 |
function leadin_log_debug( $message ) {
|
96 |
+
if ( WP_DEBUG === true ) {
|
97 |
+
if ( is_array( $message ) || is_object( $message ) ) {
|
98 |
+
error_log( print_r( $message, true ) );
|
99 |
+
} else {
|
100 |
+
error_log( $message );
|
101 |
+
}
|
102 |
+
}
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
* Returns the user role for the current user
|
107 |
*/
|
108 |
function leadin_get_user_role() {
|
109 |
+
global $current_user;
|
110 |
|
111 |
+
$user_roles = $current_user->roles;
|
112 |
+
$user_role = array_shift( $user_roles );
|
113 |
|
114 |
+
return $user_role;
|
115 |
}
|
116 |
|
117 |
|
inc/leadin-oauth-refresh.php
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
<?php
|
2 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
3 |
-
|
4 |
-
wp_die();
|
5 |
}
|
6 |
|
7 |
if ( is_admin() ) {
|
@@ -13,8 +12,7 @@ function leadin_oauth_refresh_ajax() {
|
|
13 |
|
14 |
if ( empty( $existingPortalId ) ) {
|
15 |
error_log( 'Refresh error' );
|
16 |
-
|
17 |
-
wp_die( '{"error": "No leadin_portalId found, cannot refresh."}' );
|
18 |
}
|
19 |
|
20 |
$data = json_decode( file_get_contents( 'php://input' ), true );
|
@@ -24,8 +22,7 @@ function leadin_oauth_refresh_ajax() {
|
|
24 |
|
25 |
if ( empty( $portalId ) || empty( $accessToken ) ) {
|
26 |
error_log( 'Refresh error' );
|
27 |
-
|
28 |
-
wp_die( '{"error": "Refresh missing required fields"}' );
|
29 |
}
|
30 |
|
31 |
update_option( 'leadin_accessToken', $accessToken );
|
1 |
<?php
|
2 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
3 |
+
wp_die( '', '', 403 );
|
|
|
4 |
}
|
5 |
|
6 |
if ( is_admin() ) {
|
12 |
|
13 |
if ( empty( $existingPortalId ) ) {
|
14 |
error_log( 'Refresh error' );
|
15 |
+
wp_die( '{"error": "No leadin_portalId found, cannot refresh."}', '', 400 );
|
|
|
16 |
}
|
17 |
|
18 |
$data = json_decode( file_get_contents( 'php://input' ), true );
|
22 |
|
23 |
if ( empty( $portalId ) || empty( $accessToken ) ) {
|
24 |
error_log( 'Refresh error' );
|
25 |
+
wp_die( '{"error": "Refresh missing required fields"}', '', 400 );
|
|
|
26 |
}
|
27 |
|
28 |
update_option( 'leadin_accessToken', $accessToken );
|
inc/leadin-registration.php
CHANGED
@@ -1,63 +1,67 @@
|
|
1 |
<?php
|
2 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
3 |
-
|
4 |
-
wp_die();
|
5 |
}
|
6 |
|
7 |
if ( is_admin() ) {
|
8 |
-
|
9 |
-
|
10 |
}
|
11 |
|
12 |
function leadin_registration_ajax() {
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
}
|
20 |
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
header( 'HTTP/1.0 400 Bad Request' );
|
28 |
-
wp_die( '{"error": "Registration missing required fields"}' );
|
29 |
-
}
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
$oAuthMode = $data['oAuthMode'];
|
36 |
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
|
49 |
function leadin_deregistration_ajax() {
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
}
|
62 |
|
63 |
|
1 |
<?php
|
2 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
3 |
+
wp_die( '', '', 403 );
|
|
|
4 |
}
|
5 |
|
6 |
if ( is_admin() ) {
|
7 |
+
add_action( 'wp_ajax_leadin_registration_ajax', 'leadin_registration_ajax' ); // Call when user logged in
|
8 |
+
add_action( 'wp_ajax_leadin_deregistration_ajax', 'leadin_deregistration_ajax' );
|
9 |
}
|
10 |
|
11 |
function leadin_registration_ajax() {
|
12 |
+
delete_option( 'leadin_hapikey' );
|
13 |
+
$existingPortalId = get_option( 'leadin_portalId' );
|
14 |
|
15 |
+
if ( ! empty( $existingPortalId ) ) {
|
16 |
+
wp_die( '{"error": "Registration is already complete for this portal"}', '', 400 );
|
17 |
+
}
|
|
|
18 |
|
19 |
+
$requestBody = file_get_contents( 'php://input' );
|
20 |
+
$data = json_decode( $requestBody, true );
|
21 |
|
22 |
+
$newPortalId = $data['portalId'];
|
23 |
|
24 |
+
if ( empty( $newPortalId ) ) {
|
25 |
+
error_log( 'Registration error' );
|
|
|
|
|
|
|
26 |
|
27 |
+
$errorBody = array(
|
28 |
+
"error" => "Registration missing required fields",
|
29 |
+
"request" => $requestBody,
|
30 |
+
);
|
|
|
31 |
|
32 |
+
wp_die( json_encode( $errorBody ), '', 400 );
|
33 |
+
}
|
34 |
|
35 |
+
$userId = $data['userId'];
|
36 |
+
$accessToken = $data['accessToken'];
|
37 |
+
$refreshToken = $data['refreshToken'];
|
38 |
+
$connectionTimeInMs = $data['connectionTimeInMs'];
|
39 |
+
$oAuthMode = $data['oAuthMode'];
|
40 |
|
41 |
+
add_option( 'leadin_portalId', $newPortalId );
|
42 |
+
add_option( 'leadin_slumber_mode', $oAuthMode ? '0' : '1' );
|
43 |
+
|
44 |
+
add_option( 'leadin_oauth_mode', $oAuthMode ? '1' : '0');
|
45 |
+
add_option( 'leadin_userId', $userId);
|
46 |
+
add_option( 'leadin_accessToken', $accessToken);
|
47 |
+
add_option( 'leadin_refreshToken', $refreshToken);
|
48 |
+
add_option( 'leadin_connectionTimeInMs', $connectionTimeInMs);
|
49 |
+
|
50 |
+
wp_die( '{"message": "Success!"}' );
|
51 |
}
|
52 |
|
53 |
function leadin_deregistration_ajax() {
|
54 |
+
delete_option( 'leadin_portalId' );
|
55 |
+
delete_option( 'leadin_hapikey' );
|
56 |
+
delete_option( 'leadin_slumber_mode' );
|
57 |
|
58 |
+
delete_option( 'leadin_accessToken' );
|
59 |
+
delete_option( 'leadin_refreshToken' );
|
60 |
+
delete_option( 'leadin_oauth_mode' );
|
61 |
+
delete_option( 'leadin_userId' );
|
62 |
+
delete_option( 'leadin_connectionTimeInMs' );
|
63 |
|
64 |
+
wp_die( '{"message": "Success!"}' );
|
65 |
}
|
66 |
|
67 |
|
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.0.
|
7 |
Author: HubSpot
|
8 |
Author URI: http://www.hubspot.com
|
9 |
License: GPL2
|
@@ -13,50 +13,50 @@ License: GPL2
|
|
13 |
// Define Constants
|
14 |
// =============================================
|
15 |
if ( ! defined( 'LEADIN_PATH' ) ) {
|
16 |
-
|
17 |
}
|
18 |
|
19 |
if ( ! defined( 'LEADIN_PLUGIN_DIR' ) ) {
|
20 |
-
|
21 |
}
|
22 |
|
23 |
if ( ! defined( 'LEADIN_PLUGIN_SLUG' ) ) {
|
24 |
-
|
25 |
}
|
26 |
|
27 |
if ( file_exists( LEADIN_PLUGIN_DIR . '/inc/leadin-overrides.php' ) ) {
|
28 |
-
|
29 |
}
|
30 |
|
31 |
if ( ! defined( 'LEADIN_DB_VERSION' ) ) {
|
32 |
-
|
33 |
}
|
34 |
|
35 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
36 |
-
|
37 |
}
|
38 |
|
39 |
if ( ! defined( 'LEADIN_SOURCE' ) ) {
|
40 |
-
|
41 |
}
|
42 |
|
43 |
if ( ! defined( 'LEADIN_ADMIN_ASSETS_BASE_URL' ) ) {
|
44 |
-
|
45 |
}
|
46 |
|
47 |
if ( ! defined( 'LEADIN_SCRIPT_LOADER_DOMAIN' ) ) {
|
48 |
-
|
49 |
}
|
50 |
|
51 |
if ( ! defined( 'LEADIN_ENV' ) ) {
|
52 |
-
|
53 |
}
|
54 |
|
55 |
// =============================================
|
56 |
// Include Needed Files
|
57 |
// =============================================
|
58 |
if ( file_exists( LEADIN_PLUGIN_DIR . '/inc/leadin-constants.php' ) ) {
|
59 |
-
|
60 |
}
|
61 |
|
62 |
require_once LEADIN_PLUGIN_DIR . '/inc/leadin-functions.php';
|
@@ -76,118 +76,118 @@ require_once LEADIN_PLUGIN_DIR . '/inc/class-leadin.php';
|
|
76 |
*/
|
77 |
function activate_leadin( $network_wide ) {
|
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 |
/**
|
109 |
* Check Leadin installation and set options
|
110 |
*/
|
111 |
function add_leadin_defaults() {
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
INSERT INTO %soptions
|
144 |
( option_name, option_value )
|
145 |
VALUES ('leadin_options', %s)",
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
}
|
158 |
|
159 |
/**
|
160 |
* Deactivate Leadin plugin hook
|
161 |
*/
|
162 |
function deactivate_leadin( $network_wide ) {
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
}
|
181 |
|
182 |
function activate_leadin_on_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
}
|
192 |
|
193 |
|
@@ -212,15 +212,26 @@ function addHubspotShortcode($attributes) {
|
|
212 |
$portalId = $parsedAttributes['portal'];
|
213 |
$id = $parsedAttributes['id'];
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
switch ($parsedAttributes['type']) {
|
216 |
case 'form':
|
217 |
return '
|
218 |
-
<script charset="utf-8" type="text/javascript" src="
|
219 |
<script>
|
220 |
hbspt.forms.create({
|
221 |
portalId: '. $portalId . ',
|
222 |
formId: "' . $id . '",
|
223 |
-
shortcode: "wp"
|
|
|
224 |
});
|
225 |
</script>
|
226 |
';
|
@@ -259,14 +270,14 @@ function leadin_init()
|
|
259 |
add_action( 'plugins_loaded', 'leadin_init', 14 );
|
260 |
|
261 |
if ( is_admin() ) {
|
262 |
-
|
263 |
-
|
264 |
|
265 |
-
|
266 |
-
|
267 |
|
268 |
-
|
269 |
-
|
270 |
}
|
271 |
|
272 |
|
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.0.7
|
7 |
Author: HubSpot
|
8 |
Author URI: http://www.hubspot.com
|
9 |
License: GPL2
|
13 |
// Define Constants
|
14 |
// =============================================
|
15 |
if ( ! defined( 'LEADIN_PATH' ) ) {
|
16 |
+
define( 'LEADIN_PATH', untrailingslashit( plugins_url( '', __FILE__ ) ) );
|
17 |
}
|
18 |
|
19 |
if ( ! defined( 'LEADIN_PLUGIN_DIR' ) ) {
|
20 |
+
define( 'LEADIN_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) );
|
21 |
}
|
22 |
|
23 |
if ( ! defined( 'LEADIN_PLUGIN_SLUG' ) ) {
|
24 |
+
define( 'LEADIN_PLUGIN_SLUG', basename( dirname( __FILE__ ) ) );
|
25 |
}
|
26 |
|
27 |
if ( file_exists( LEADIN_PLUGIN_DIR . '/inc/leadin-overrides.php' ) ) {
|
28 |
+
require_once LEADIN_PLUGIN_DIR . '/inc/leadin-overrides.php';
|
29 |
}
|
30 |
|
31 |
if ( ! defined( 'LEADIN_DB_VERSION' ) ) {
|
32 |
+
define( 'LEADIN_DB_VERSION', '2.2.5' );
|
33 |
}
|
34 |
|
35 |
if ( ! defined( 'LEADIN_PLUGIN_VERSION' ) ) {
|
36 |
+
define( 'LEADIN_PLUGIN_VERSION', '7.0.7' );
|
37 |
}
|
38 |
|
39 |
if ( ! defined( 'LEADIN_SOURCE' ) ) {
|
40 |
+
define( 'LEADIN_SOURCE', 'leadin.com' );
|
41 |
}
|
42 |
|
43 |
if ( ! defined( 'LEADIN_ADMIN_ASSETS_BASE_URL' ) ) {
|
44 |
+
define( 'LEADIN_ADMIN_ASSETS_BASE_URL', 'https://app.hubspot.com/leadin_admin_static_live' );
|
45 |
}
|
46 |
|
47 |
if ( ! defined( 'LEADIN_SCRIPT_LOADER_DOMAIN' ) ) {
|
48 |
+
define( 'LEADIN_SCRIPT_LOADER_DOMAIN', 'js.hs-scripts.com' );
|
49 |
}
|
50 |
|
51 |
if ( ! defined( 'LEADIN_ENV' ) ) {
|
52 |
+
define( 'LEADIN_ENV', 'prod' );
|
53 |
}
|
54 |
|
55 |
// =============================================
|
56 |
// Include Needed Files
|
57 |
// =============================================
|
58 |
if ( file_exists( LEADIN_PLUGIN_DIR . '/inc/leadin-constants.php' ) ) {
|
59 |
+
require_once LEADIN_PLUGIN_DIR . '/inc/leadin-constants.php';
|
60 |
}
|
61 |
|
62 |
require_once LEADIN_PLUGIN_DIR . '/inc/leadin-functions.php';
|
76 |
*/
|
77 |
function activate_leadin( $network_wide ) {
|
78 |
|
79 |
+
// Check activation on entire network or one blog
|
80 |
+
if ( is_multisite() && $network_wide ) {
|
81 |
+
global $wpdb;
|
82 |
+
|
83 |
+
// Get this so we can switch back to it later
|
84 |
+
$current_blog = $wpdb->blogid;
|
85 |
+
// For storing the list of activated blogs
|
86 |
+
$activated = array();
|
87 |
+
|
88 |
+
// Get all blogs in the network and activate plugin on each one
|
89 |
+
$blog_ids = $wpdb->get_col(
|
90 |
+
"SELECT blog_id FROM $wpdb->blogs"
|
91 |
+
);
|
92 |
+
foreach ( $blog_ids as $blog_id ) {
|
93 |
+
switch_to_blog( $blog_id );
|
94 |
+
add_leadin_defaults();
|
95 |
+
$activated[] = $blog_id;
|
96 |
+
}
|
97 |
+
|
98 |
+
// Switch back to the current blog
|
99 |
+
switch_to_blog( $current_blog );
|
100 |
+
|
101 |
+
// Store the array for a later function
|
102 |
+
update_site_option( 'leadin_activated', $activated );
|
103 |
+
} else {
|
104 |
+
add_leadin_defaults();
|
105 |
+
}
|
106 |
}
|
107 |
|
108 |
/**
|
109 |
* Check Leadin installation and set options
|
110 |
*/
|
111 |
function add_leadin_defaults() {
|
112 |
+
global $wpdb;
|
113 |
+
$options = get_option( 'leadin_options' );
|
114 |
+
|
115 |
+
if ( ( $options['li_installed'] != 1 ) || ( ! is_array( $options ) ) ) {
|
116 |
+
$opt = array(
|
117 |
+
'li_installed' => 1,
|
118 |
+
'leadin_version' => LEADIN_PLUGIN_VERSION,
|
119 |
+
'li_email' => get_bloginfo( 'admin_email' ),
|
120 |
+
'li_updates_subscription' => 1,
|
121 |
+
'onboarding_step' => 1,
|
122 |
+
'onboarding_complete' => 0,
|
123 |
+
'ignore_settings_popup' => 0,
|
124 |
+
'data_recovered' => 1,
|
125 |
+
'delete_flags_fixed' => 1,
|
126 |
+
'beta_tester' => 0,
|
127 |
+
'converted_to_tags' => 1,
|
128 |
+
'names_added_to_contacts' => 1,
|
129 |
+
'affiliate_code' => '',
|
130 |
+
);
|
131 |
+
|
132 |
+
// Add the Pro flag if this is a pro installation
|
133 |
+
if ( ( defined( 'LEADIN_UTM_SOURCE' ) && LEADIN_UTM_SOURCE != 'leadin%20repo%20plugin' ) || ! defined( 'LEADIN_UTM_SOURCE' ) ) {
|
134 |
+
$opt['pro'] = 1;
|
135 |
+
}
|
136 |
+
|
137 |
+
// this is a hack because multisite doesn't recognize local options using either update_option or update_site_option...
|
138 |
+
if ( is_multisite() ) {
|
139 |
+
$multisite_prefix = ( is_multisite() ? $wpdb->prefix : '' );
|
140 |
+
$wpdb->query(
|
141 |
+
$wpdb->prepare(
|
142 |
+
"
|
143 |
INSERT INTO %soptions
|
144 |
( option_name, option_value )
|
145 |
VALUES ('leadin_options', %s)",
|
146 |
+
$multisite_prefix,
|
147 |
+
serialize( $opt )
|
148 |
+
)
|
149 |
+
);
|
150 |
+
// TODO: Glob settings for multisite
|
151 |
+
} else {
|
152 |
+
update_option( 'leadin_options', $opt );
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
setcookie( 'ignore_social_share', '1', 2592000, '/' );
|
157 |
}
|
158 |
|
159 |
/**
|
160 |
* Deactivate Leadin plugin hook
|
161 |
*/
|
162 |
function deactivate_leadin( $network_wide ) {
|
163 |
+
if ( is_multisite() && $network_wide ) {
|
164 |
+
global $wpdb;
|
165 |
+
|
166 |
+
// Get this so we can switch back to it later
|
167 |
+
$current_blog = $wpdb->blogid;
|
168 |
+
|
169 |
+
// Get all blogs in the network and activate plugin on each one
|
170 |
+
$blog_ids = $wpdb->get_col(
|
171 |
+
"SELECT blog_id FROM $wpdb->blogs"
|
172 |
+
);
|
173 |
+
foreach ( $blog_ids as $blog_id ) {
|
174 |
+
switch_to_blog( $blog_id );
|
175 |
+
}
|
176 |
+
|
177 |
+
// Switch back to the current blog
|
178 |
+
switch_to_blog( $current_blog );
|
179 |
+
}
|
180 |
}
|
181 |
|
182 |
function activate_leadin_on_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
|
183 |
+
global $wpdb;
|
184 |
+
|
185 |
+
if ( is_plugin_active_for_network( 'leadin/leadin.php' ) ) {
|
186 |
+
$current_blog = $wpdb->blogid;
|
187 |
+
switch_to_blog( $blog_id );
|
188 |
+
add_leadin_defaults();
|
189 |
+
switch_to_blog( $current_blog );
|
190 |
+
}
|
191 |
}
|
192 |
|
193 |
|
212 |
$portalId = $parsedAttributes['portal'];
|
213 |
$id = $parsedAttributes['id'];
|
214 |
|
215 |
+
if (LEADIN_ENV != 'prod') {
|
216 |
+
$formsUrlSuffix = 'qa';
|
217 |
+
$formsPayloadQA = 'env: "qa",';
|
218 |
+
} else {
|
219 |
+
$formsUrlSuffix = '';
|
220 |
+
$formsPayloadQA = '';
|
221 |
+
}
|
222 |
+
|
223 |
+
$formsUrl = "//js.hsforms$formsUrlSuffix.net/forms/v2.js";
|
224 |
+
|
225 |
switch ($parsedAttributes['type']) {
|
226 |
case 'form':
|
227 |
return '
|
228 |
+
<script charset="utf-8" type="text/javascript" src="'.$formsUrl.'"></script>
|
229 |
<script>
|
230 |
hbspt.forms.create({
|
231 |
portalId: '. $portalId . ',
|
232 |
formId: "' . $id . '",
|
233 |
+
shortcode: "wp",
|
234 |
+
' . $formsPayloadQA . '
|
235 |
});
|
236 |
</script>
|
237 |
';
|
270 |
add_action( 'plugins_loaded', 'leadin_init', 14 );
|
271 |
|
272 |
if ( is_admin() ) {
|
273 |
+
// Activate + install Leadin
|
274 |
+
register_activation_hook( __FILE__, 'activate_leadin' );
|
275 |
|
276 |
+
// Deactivate Leadin
|
277 |
+
register_deactivation_hook( __FILE__, 'deactivate_leadin' );
|
278 |
|
279 |
+
// Activate on newly created wpmu blog
|
280 |
+
add_action( 'wpmu_new_blog', 'activate_leadin_on_new_blog', 10, 6 );
|
281 |
}
|
282 |
|
283 |
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: HubSpotDev, leadin
|
|
3 |
Tags: forms, popup, live chat, contact form, crm, newsletter, marketing, lead generation, hubspot, mailchimp, constant contact
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 5.0
|
6 |
-
Stable tag: 7.0.
|
7 |
|
8 |
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.
|
9 |
|
@@ -166,8 +166,18 @@ Please <a href="https://community.hubspot.com?utm_source=wordpress-plugin-listin
|
|
166 |
|
167 |
== Changelog ==
|
168 |
|
169 |
-
- Current version: 7.0.
|
170 |
-
- Current version release: 2019-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
= 7.0.5 (2019.03.05) =
|
173 |
- Update description to explain how plugin provides WordPress CRM
|
3 |
Tags: forms, popup, live chat, contact form, crm, newsletter, marketing, lead generation, hubspot, mailchimp, constant contact
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 5.0
|
6 |
+
Stable tag: 7.0.7
|
7 |
|
8 |
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.
|
9 |
|
166 |
|
167 |
== Changelog ==
|
168 |
|
169 |
+
- Current version: 7.0.7
|
170 |
+
- Current version release: 2019-03-25
|
171 |
+
|
172 |
+
= 7.0.7 (2019.03.25) =
|
173 |
+
- Add helpers for acceptance tests
|
174 |
+
- Remove dialog on settings page
|
175 |
+
- Load forms script from right environment
|
176 |
+
- Test on PHP 5.6
|
177 |
+
- Design fixes on the intro page
|
178 |
+
|
179 |
+
= 7.0.6 (2019.03.08) =
|
180 |
+
- Add debug helpers
|
181 |
|
182 |
= 7.0.5 (2019.03.05) =
|
183 |
- Update description to explain how plugin provides WordPress CRM
|