This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathleadin.php
More file actions
221 lines (176 loc) · 5.79 KB
/
Copy pathleadin.php
File metadata and controls
221 lines (176 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
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
<?php
/*
Plugin Name: Leadin
Plugin URI: http://leadin.com
Description: Leadin is an easy-to-use marketing automation and lead tracking plugin for WordPress that helps you better understand your web site visitors.
Version: 4.3.0
Author: Leadin
Author URI: http://leadin.com
Text Domain: leadin
License: GPL2
*/
//=============================================
// Define Constants
//=============================================
if ( !defined('LEADIN_PATH') )
define('LEADIN_PATH', untrailingslashit(plugins_url('', __FILE__ )));
if ( !defined('LEADIN_PLUGIN_DIR') )
define('LEADIN_PLUGIN_DIR', untrailingslashit(dirname( __FILE__ )));
if ( !defined('LEADIN_PLUGIN_SLUG') )
define('LEADIN_PLUGIN_SLUG', basename(dirname(__FILE__)));
if ( file_exists(LEADIN_PLUGIN_DIR . '/inc/leadin-overrides.php'))
include_once(LEADIN_PLUGIN_DIR . '/inc/leadin-overrides.php');
if ( !defined('LEADIN_DB_VERSION') )
define('LEADIN_DB_VERSION', '2.2.5');
if ( !defined('LEADIN_PLUGIN_VERSION') )
define('LEADIN_PLUGIN_VERSION', '4.3.0');
if ( !defined('LEADIN_SOURCE') )
define('LEADIN_SOURCE', 'leadin.com');
if ( !defined('LEADIN_ADMIN_ASSETS_BASE_URL') )
define('LEADIN_ADMIN_ASSETS_BASE_URL', "//appjs.leadin.com/leadin_admin_static_live");
if ( !defined('LEADIN_API_BASE_URL') )
define('LEADIN_API_BASE_URL', "https://api.leadin.com");
if ( !defined('LEADIN_EMBED_DOMAIN') )
define('LEADIN_EMBED_DOMAIN', "js.leadin.com");
if ( !defined('LEADIN_ENV') )
define('LEADIN_ENV', "prod");
//=============================================
// Include Needed Files
//=============================================
if ( file_exists(LEADIN_PLUGIN_DIR . '/inc/leadin-constants.php') )
include_once(LEADIN_PLUGIN_DIR . '/inc/leadin-constants.php');
require_once(LEADIN_PLUGIN_DIR . '/inc/leadin-functions.php');
require_once(LEADIN_PLUGIN_DIR . '/inc/leadin-proxy.php');
require_once(LEADIN_PLUGIN_DIR . '/inc/leadin-registration.php');
require_once(LEADIN_PLUGIN_DIR . '/admin/leadin-admin.php');
require_once(LEADIN_PLUGIN_DIR . '/lib/segment/lib/Segment.php');
require_once(LEADIN_PLUGIN_DIR . '/inc/class-leadin.php');
//=============================================
// Hooks & Filters
//=============================================
/**
* Activate the plugin
*/
function activate_leadin ( $network_wide )
{
// Check activation on entire network or one blog
if ( is_multisite() && $network_wide )
{
global $wpdb;
// Get this so we can switch back to it later
$current_blog = $wpdb->blogid;
// For storing the list of activated blogs
$activated = array();
// Get all blogs in the network and activate plugin on each one
$q = "SELECT blog_id FROM $wpdb->blogs";
$blog_ids = $wpdb->get_col($q);
foreach ( $blog_ids as $blog_id )
{
switch_to_blog($blog_id);
add_leadin_defaults();
$activated[] = $blog_id;
}
// Switch back to the current blog
switch_to_blog($current_blog);
// Store the array for a later function
update_site_option('leadin_activated', $activated);
}
else
{
add_leadin_defaults();
}
}
/**
* Check Leadin installation and set options
*/
function add_leadin_defaults ( )
{
global $wpdb;
$options = get_option('leadin_options');
leadin_maybe_add_migration_db_columns();
if ( ($options['li_installed'] != 1) || (!is_array($options)) )
{
$opt = array(
'li_installed' => 1,
'leadin_version' => LEADIN_PLUGIN_VERSION,
'li_email' => get_bloginfo('admin_email'),
'li_updates_subscription' => 1,
'onboarding_step' => 1,
'onboarding_complete' => 0,
'ignore_settings_popup' => 0,
'data_recovered' => 1,
'delete_flags_fixed' => 1,
'beta_tester' => 0,
'converted_to_tags' => 1,
'names_added_to_contacts' => 1
);
// Add the Pro flag if this is a pro installation
if ( ( defined('LEADIN_UTM_SOURCE') && LEADIN_UTM_SOURCE != 'leadin%20repo%20plugin' ) || ! defined('LEADIN_UTM_SOURCE') )
$opt['pro'] = 1;
// this is a hack because multisite doesn't recognize local options using either update_option or update_site_option...
if ( is_multisite() )
{
$multisite_prefix = ( is_multisite() ? $wpdb->prefix : '' );
$q = $wpdb->prepare("
INSERT INTO " . $multisite_prefix . "options
( option_name, option_value )
VALUES ('leadin_options', %s)", serialize($opt));
$wpdb->query($q);
// TODO: Glob settings for multisite
}
else
update_option('leadin_options', $opt);
}
setcookie ( "ignore_social_share" , "1", 2592000, "/" );
}
/**
* Deactivate Leadin plugin hook
*/
function deactivate_leadin ( $network_wide )
{
if ( is_multisite() && $network_wide )
{
global $wpdb;
// Get this so we can switch back to it later
$current_blog = $wpdb->blogid;
// Get all blogs in the network and activate plugin on each one
$q = "SELECT blog_id FROM $wpdb->blogs";
$blog_ids = $wpdb->get_col($q);
foreach ( $blog_ids as $blog_id )
{
switch_to_blog($blog_id);
leadin_track_plugin_registration_hook(FALSE);
}
// Switch back to the current blog
switch_to_blog($current_blog);
}
}
function activate_leadin_on_new_blog ( $blog_id, $user_id, $domain, $path, $site_id, $meta )
{
global $wpdb;
if ( is_plugin_active_for_network('leadin/leadin.php') )
{
$current_blog = $wpdb->blogid;
switch_to_blog($blog_id);
add_leadin_defaults();
switch_to_blog($current_blog);
}
}
/**
* Checks the stored database version against the current data version + updates if needed
*/
function leadin_init ()
{
$leadin_wp = new WPLeadIn();
}
add_action( 'plugins_loaded', 'leadin_init', 14 );
if ( is_admin() )
{
// Activate + install Leadin
register_activation_hook( __FILE__, 'activate_leadin');
// Deactivate Leadin
register_deactivation_hook( __FILE__, 'deactivate_leadin');
// Activate on newly created wpmu blog
add_action('wpmu_new_blog', 'activate_leadin_on_new_blog', 10, 6);
}
?>