forked from verygoodplugins/wp-fusion-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-fusion-lite.php
580 lines (437 loc) · 12.8 KB
/
wp-fusion-lite.php
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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<?php
/*
Plugin Name: WP Fusion Lite
Description: WP Fusion connects your website to your CRM or marketing automation system.
Plugin URI: https://wpfusion.com/
Version: 3.25
Author: Very Good Plugins
Author URI: https://verygoodplugins.com/
Text Domain: wp-fusion
*/
/**
* @copyright Copyright (c) 2018. All rights reserved.
*
* @license Released under the GPL license http://www.opensource.org/licenses/gpl-license.php
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
define( 'WP_FUSION_VERSION', '3.25' );
// deny direct access
if ( ! function_exists( 'add_action' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
final class WP_Fusion_Lite {
/** Singleton *************************************************************/
/**
* @var WP_Fusion_Lite The one true WP_Fusion_Lite
* @since 1.0
*/
private static $instance;
/**
* Contains all active integrations classes
*
* @since 3.0
*/
public $integrations;
/**
* Manages configured CRMs
*
* @var WPF_CRM_Base
* @since 2.0
*/
public $crm_base;
/**
* Access to the currently selected CRM
*
* @var crm
* @since 2.0
*/
public $crm;
/**
* Handler for AJAX and and asynchronous functions
*
* @var crm
* @since 2.0
*/
public $ajax;
/**
* Handler for batch processing
*
* @var batch
* @since 3.0
*/
public $batch;
/**
* Logging and diagnostics class
*
* @var logger
* @since 3.0
*/
public $logger;
/**
* User handler - registration, sync, and updates
*
* @var WPF_User
* @since 2.0
*/
public $user;
/**
* Stores configured admin meta boxes and other admin interfaces
*
* @var WPF_Admin_Interfaces
* @since 2.0
*/
public $admin_interfaces;
/**
* Handles resticted content and redirects
*
* @var WPF_Access_Control
* @since 3.12
*/
public $access;
/**
* Handles auto login sessions
*
* @var WPF_Admin_Interfaces
* @since 3.12
*/
public $auto_login;
/**
* The settings instance variable
*
* @var WPF_Settings
* @since 1.0
*/
public $settings;
/**
* Main WP_Fusion_Lite Instance
*
* Insures that only one instance of WP_Fusion_Lite exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0
* @static
* @static var array $instance
* @return WP_Fusion_Lite The one true WP_Fusion_Lite
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Fusion_Lite ) ) {
self::$instance = new WP_Fusion_Lite();
self::$instance->setup_constants();
// If PHP version not met
if ( ! self::$instance->check_install() ) {
add_action( 'admin_notices', array( self::$instance, 'php_version_notice' ) );
}
self::$instance->init_includes();
// Create settings
self::$instance->settings = new WPF_Settings();
// Load active CRM
self::$instance->crm_base = new WPF_CRM_Base();
self::$instance->crm = self::$instance->crm_base->crm;
// Only useful if a CRM is selected and valid
if ( ! empty( self::$instance->crm ) ) {
self::$instance->setup_crm_constants();
self::$instance->includes();
self::$instance->logger = new WPF_Log_Handler();
self::$instance->user = new WPF_User();
self::$instance->access = new WPF_Access_Control();
self::$instance->auto_login = new WPF_Auto_Login();
self::$instance->ajax = new WPF_AJAX();
self::$instance->batch = new WPF_Batch();
add_action( 'plugins_loaded', array( self::$instance, 'integrations_includes' ), 10 ); // This has to be 10 for Elementor
add_action( 'after_setup_theme', array( self::$instance, 'integrations_includes_theme' ) );
add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
if ( self::$instance->is_full_version() ) {
add_action( 'after_setup_theme', array( self::$instance, 'updater' ), 20 );
}
}
}
return self::$instance;
}
/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @access protected
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wp-fusion' ), WP_FUSION_VERSION );
}
/**
* Disable unserializing of the class
*
* @access protected
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wp-fusion' ), WP_FUSION_VERSION );
}
/**
* Setup plugin constants
*
* @access private
* @return void
*/
private function setup_constants() {
if ( ! defined( 'WPF_MIN_WP_VERSION' ) ) {
define( 'WPF_MIN_WP_VERSION', '4.0' );
}
if ( ! defined( 'WPF_MIN_PHP_VERSION' ) ) {
define( 'WPF_MIN_PHP_VERSION', '5.6' );
}
if ( ! defined( 'WPF_DIR_PATH' ) ) {
define( 'WPF_DIR_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'WPF_PLUGIN_PATH' ) ) {
define( 'WPF_PLUGIN_PATH', plugin_basename( __FILE__ ) );
}
if ( ! defined( 'WPF_DIR_URL' ) ) {
define( 'WPF_DIR_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'WPF_STORE_URL' ) ) {
define( 'WPF_STORE_URL', 'https://wpfusion.com' );
}
}
/**
* Check min PHP version
*
* @access private
* @return bool
*/
private function check_install() {
if ( version_compare( phpversion(), WPF_MIN_PHP_VERSION, '>=' ) ) {
return true;
} else {
return false;
}
}
/**
* Setup CRM related constants
*
* @access private
* @return void
*/
private function setup_crm_constants() {
if ( ! defined( 'WPF_CRM_NAME' ) ) {
define( 'WPF_CRM_NAME', self::$instance->crm->name );
}
}
/**
* Defines default supported plugin integrations
*
* @access public
* @return array Integrations
*/
public function get_integrations() {
return apply_filters( 'wpf_integrations', array() );
}
/**
* Defines default supported theme integrations
*
* @access public
* @return array Integrations
*/
public function get_integrations_theme() {
return apply_filters( 'wpf_integrations_theme', array() );
}
/**
* Defines supported CRMs
*
* @access private
* @return array CRMS
*/
public function get_crms() {
return apply_filters(
'wpf_crms', array(
'infusionsoft' => 'WPF_Infusionsoft_iSDK',
'activecampaign' => 'WPF_ActiveCampaign',
'ontraport' => 'WPF_Ontraport',
'drip' => 'WPF_Drip',
'convertkit' => 'WPF_ConvertKit',
'agilecrm' => 'WPF_AgileCRM',
'salesforce' => 'WPF_Salesforce',
'mautic' => 'WPF_Mautic',
'intercom' => 'WPF_Intercom',
'aweber' => 'WPF_AWeber',
'mailerlite' => 'WPF_MailerLite',
'capsule' => 'WPF_Capsule',
'zoho' => 'WPF_Zoho',
'kartra' => 'WPF_Kartra',
'userengage' => 'WPF_UserEngage',
'convertfox' => 'WPF_ConvertFox',
'salesflare' => 'WPF_Salesflare',
'vtiger' => 'WPF_Vtiger',
'flexie' => 'WPF_Flexie',
'tubular' => 'WPF_Tubular',
'maropost' => 'WPF_Maropost',
'mailchimp' => 'WPF_MailChimp',
'sendinblue' => 'WPF_SendinBlue',
'hubspot' => 'WPF_HubSpot',
'platformly' => 'WPF_Platformly',
'drift' => 'WPF_Drift',
'staging' => 'WPF_Staging',
'autopilot' => 'WPF_Autopilot',
'customerly' => 'WPF_Customerly',
'copper' => 'WPF_Copper',
'nationbuilder' => 'WPF_NationBuilder',
'groundhogg' => 'WPF_Groundhogg',
'mailjet' => 'WPF_Mailjet',
'sendlane' => 'WPF_Sendlane',
'getresponse' => 'WPF_GetResponse',
'mailpoet' => 'WPF_MailPoet',
)
);
}
/**
* Include required files
*
* @access private
* @return void
*/
private function init_includes() {
// Settings
require_once WPF_DIR_PATH . 'includes/admin/class-settings.php';
// CRM base class
require_once WPF_DIR_PATH . 'includes/crms/class-base.php';
if ( is_admin() ) {
require_once WPF_DIR_PATH . 'includes/admin/class-notices.php';
require_once WPF_DIR_PATH . 'includes/admin/admin-functions.php';
require_once WPF_DIR_PATH . 'includes/admin/class-admin-interfaces.php';
self::$instance->admin_interfaces = new WPF_Admin_Interfaces();
}
}
/**
* Includes classes applicable for after the connection is configured
*
* @access private
* @return void
*/
private function includes() {
require_once WPF_DIR_PATH . 'includes/admin/logging/class-log-handler.php';
require_once WPF_DIR_PATH . 'includes/class-user.php';
require_once WPF_DIR_PATH . 'includes/class-ajax.php';
require_once WPF_DIR_PATH . 'includes/class-access-control.php';
require_once WPF_DIR_PATH . 'includes/class-auto-login.php';
require_once WPF_DIR_PATH . 'includes/admin/class-batch.php';
require_once WPF_DIR_PATH . 'includes/admin/gutenberg/class-gutenberg.php';
if ( is_admin() && $this->is_full_version() ) {
require_once WPF_DIR_PATH . 'includes/admin/class-updater.php';
} else {
require_once WPF_DIR_PATH . 'includes/class-shortcodes.php';
}
// Admin bar tools
if ( ! is_admin() && self::$instance->settings->get( 'enable_admin_bar', true ) == true ) {
require_once WPF_DIR_PATH . 'includes/admin/class-admin-bar.php';
}
if ( $this->is_full_version() ) {
require_once WPF_DIR_PATH . 'includes/class-api.php';
}
}
/**
* Includes plugin integrations after all plugins have loaded
*
* @access private
* @return void
*/
public function integrations_includes() {
// Integrations base
require_once WPF_DIR_PATH . 'includes/integrations/class-base.php';
// Store integrations for public access
self::$instance->integrations = new stdClass();
// Integrations autoloader
foreach ( wp_fusion()->get_integrations() as $filename => $dependency_class ) {
if ( class_exists( $dependency_class ) || function_exists( $dependency_class ) ) {
if ( file_exists( WPF_DIR_PATH . 'includes/integrations/class-' . $filename . '.php' ) ) {
require_once WPF_DIR_PATH . 'includes/integrations/class-' . $filename . '.php';
}
}
}
}
/**
* Includes theme integrations after all theme has loaded
*
* @access private
* @return void
*/
public function integrations_includes_theme() {
// Integrations base
require_once WPF_DIR_PATH . 'includes/integrations/class-base.php';
// Integrations autoloader
foreach ( wp_fusion()->get_integrations_theme() as $filename => $dependency_class ) {
if ( class_exists( $dependency_class ) || function_exists( $dependency_class ) ) {
if ( file_exists( WPF_DIR_PATH . 'includes/integrations/class-' . $filename . '.php' ) ) {
require_once WPF_DIR_PATH . 'includes/integrations/class-' . $filename . '.php';
}
}
}
}
/**
* Load internationalization files
*
* @access public
* @return void
*/
public function load_textdomain() {
load_plugin_textdomain( 'wp-fusion', false, 'wp-fusion/languages' );
}
/**
* Check to see if this is WPF Lite or regular
*
* @access public
* @return bool
*/
public function is_full_version() {
$integrations = $this->get_integrations();
if ( ! empty( $integrations ) ) {
return true;
} else {
return false;
}
}
/**
* Returns error message and deactivates plugin when error returned.
*
* @access public
* @return mixed error message.
*/
public function php_version_notice() {
echo '<div class="notice notice-error">';
echo '<p><strong>Warning:</strong> WP Fusion requires at least PHP version ' . WPF_MIN_PHP_VERSION . ' in order to function properly. You are currently using PHP version ' . phpversion() . '. Please update your version of PHP, or contact your web host for assistance.</p>';
echo '</div>';
}
}
/**
* The main function responsible for returning the one true WP Fusion
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $wpf = wp_fusion(); ?>
*
* @return object The one true WP Fusion Instance
*/
if ( ! function_exists( 'wp_fusion' ) ) {
function wp_fusion() {
return WP_Fusion_Lite::instance();
}
// Get WP Fusion Running
wp_fusion();
}