forked from JustinSainton/AffiliateWP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
affiliate-wp.php
585 lines (513 loc) · 18.4 KB
/
affiliate-wp.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
581
582
583
584
585
<?php
/**
* Plugin Name: AffiliateWP
* Plugin URI: https://affiliatewp.com
* Description: Affiliate Plugin for WordPress
* Author: AffiliateWP, LLC
* Author URI: https://affiliatewp.com
* Version: 2.1.2
* Text Domain: affiliate-wp
* Domain Path: languages
*
* AffiliateWP is distributed under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* AffiliateWP 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.
*
* You should have received a copy of the GNU General Public License
* along with AffiliateWP. If not, see <http://www.gnu.org/licenses/>.
*
* @package AffiliateWP
* @category Core
* @author Pippin Williamson
* @version 2.1.2
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Affiliate_WP' ) ) :
/**
* Main Affiliate_WP Class
*
* @since 1.0
*/
final class Affiliate_WP {
/** Singleton *************************************************************/
/**
* AffiliateWP instance.
*
* @access private
* @since 1.0
* @var Affiliate_WP The one true Affiliate_WP
*/
private static $instance;
/**
* The version number of AffiliateWP.
*
* @access private
* @since 1.0
* @var string
*/
private $version = '2.1.2';
/**
* The affiliates DB instance variable.
*
* @access public
* @since 1.0
* @var Affiliate_WP_DB_Affiliates
*/
public $affiliates;
/**
* The affiliate meta DB instance variable.
*
* @access public
* @since 1.6
* @var Affiliate_WP_Affiliate_Meta_DB
*/
public $affiliate_meta;
/**
* The referrals instance variable.
*
* @access public
* @since 1.0
* @var Affiliate_WP_Referrals_DB
*/
public $referrals;
/**
* The campaigns instance variable.
*
* @access public
* @since 1.7
* @var Affiliate_WP_Campaigns_DB
*/
public $campaigns;
/**
* The visits DB instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Visits_DB
*/
public $visits;
/**
* The settings instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Settings
*/
public $settings;
/**
* The affiliate tracking handler instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Tracking
*/
public $tracking;
/**
* The template loader instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Templates
*/
public $templates;
/**
* The affiliate login handler instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Login
*/
public $login;
/**
* The affiliate registration handler instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Register
*/
public $register;
/**
* The integrations handler instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Integrations
*/
public $integrations;
/**
* The email notification handler instance variable
*
* @access public
* @since 1.0
* @var Affiliate_WP_Emails
*/
public $emails;
/**
* The creatives instance variable
*
* @access public
* @since 1.2
* @var Affiliate_WP_Creatives_DB
*/
public $creatives;
/**
* The creative class instance variable
*
* @access public
* @since 1.3
* @var Affiliate_WP_Creatives
*/
public $creative;
/**
* The rewrite class instance variable
*
* @access public
* @since 1.7.8
* @var Affiliate_WP_Rewrites
*/
public $rewrites;
/**
* REST API bootstrap.
*
* @access public
* @since 1.9
* @var Affiliate_WP_REST
*/
public $REST;
/**
* The capabilities class instance variable.
*
* @access public
* @since 2.0
* @var Affiliate_WP_Capabilities
*/
public $capabilities;
/**
* The utilities class instance variable.
*
* @access public
* @since 2.0
* @var Affiliate_WP_Utilities
*/
public $utils;
/**
* Main Affiliate_WP Instance
*
* Insures that only one instance of Affiliate_WP exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0
* @static
* @staticvar array $instance
* @uses Affiliate_WP::setup_globals() Setup the globals needed
* @uses Affiliate_WP::includes() Include the required files
* @uses Affiliate_WP::setup_actions() Setup the hooks and actions
* @uses Affiliate_WP::updater() Setup the plugin updater
* @return Affiliate_WP
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Affiliate_WP ) ) {
self::$instance = new Affiliate_WP;
if( version_compare( PHP_VERSION, '5.3', '<' ) ) {
add_action( 'admin_notices', array( 'Affiliate_WP', 'below_php_version_notice' ) );
return self::$instance;
}
self::$instance->setup_constants();
self::$instance->includes();
add_action( 'plugins_loaded', array( self::$instance, 'setup_objects' ), -1 );
add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
}
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.
*
* @since 1.0
* @access protected
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliate-wp' ), '1.0' );
}
/**
* Disable unserializing of the class
*
* @since 1.0
* @access protected
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliate-wp' ), '1.0' );
}
/**
* Show a warning to sites running PHP < 5.3
*
* @static
* @access private
* @since 1.0
* @return void
*/
public static function below_php_version_notice() {
echo '<div class="error"><p>' . __( 'Your version of PHP is below the minimum version of PHP required by AffiliateWP. Please contact your host and request that your version be upgraded to 5.3 or later.', 'affiliate-wp' ) . '</p></div>';
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0
* @return void
*/
private function setup_constants() {
// Plugin version
if ( ! defined( 'AFFILIATEWP_VERSION' ) ) {
define( 'AFFILIATEWP_VERSION', $this->version );
}
// Plugin Folder Path
if ( ! defined( 'AFFILIATEWP_PLUGIN_DIR' ) ) {
define( 'AFFILIATEWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL
if ( ! defined( 'AFFILIATEWP_PLUGIN_URL' ) ) {
define( 'AFFILIATEWP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File
if ( ! defined( 'AFFILIATEWP_PLUGIN_FILE' ) ) {
define( 'AFFILIATEWP_PLUGIN_FILE', __FILE__ );
}
// Make sure CAL_GREGORIAN is defined.
if ( ! defined( 'CAL_GREGORIAN' ) ) {
define( 'CAL_GREGORIAN', 1 );
}
}
/**
* Include required files
*
* @access private
* @since 1.0
* @return void
*/
private function includes() {
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/abstracts/class-affwp-object.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-affwp-affiliate.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-affwp-creative.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-affwp-payout.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-affwp-referral.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-affwp-visit.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/actions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/abstracts/class-affwp-registry.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/settings/class-settings.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/abstracts/class-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-affiliates-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-payouts-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-capabilities.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-utilities.php';
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
// Bootstrap.
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/AFFWP_Plugin_Updater.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/abstracts/class-affwp-list-table.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/interfaces/interface-meta-box-base.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/affiliates/actions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/ajax-actions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/class-addon-updater.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/class-menu.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/affiliates/affiliates.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/class-notices.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/creatives/actions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/creatives/creatives.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/class-meta-box-base.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/overview/overview.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/referrals/actions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/referrals/referrals.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/payouts/payouts.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/reports/reports.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/settings/display-settings.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/visits/visits.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/tools/tools.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/plugins.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/tools/class-migrate.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/add-ons.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/user-profile.php';
}
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-shortcodes.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/emails/class-affwp-emails.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/emails/functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/emails/actions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-graph.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-referrals-graph.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-visits-graph.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/reports/class-payouts-graph.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-integrations.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-login.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-referrals-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-register.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-templates.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-tracking.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-rewrites.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-visits-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-campaigns-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-creatives-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-creatives.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/class-affiliate-meta-db.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/affiliate-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/affiliate-meta-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/reports/class-registrations-graph.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/misc-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/payout-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/referral-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/visit-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/creative-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/install.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/plugin-compatibility.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/scripts.php';
// REST bootstrap.
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/rest-functions.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/class-rest-consumer.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/class-rest.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/class-rest-authentication.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/class-rest-consumers-db.php';
// REST endpoints.
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/v1/class-rest-controller.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/v1/class-affiliates-endpoints.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/v1/class-creatives-endpoints.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/v1/class-payouts-endpoints.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/v1/class-referrals-endpoints.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/REST/v1/class-visits-endpoints.php';
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/class-command.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/class-sub-commands-base.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/utils/class-affiliate-fetcher.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/utils/class-creative-fetcher.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/utils/class-payout-fetcher.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/utils/class-referral-fetcher.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/utils/class-visit-fetcher.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/class-affiliate-sub-commands.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/class-creative-sub-commands.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/class-payout-sub-commands.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/class-referral-sub-commands.php';
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/cli/class-visit-sub-commands.php';
}
}
/**
* Setup all objects
*
* @access public
* @since 1.6.2
* @return void
*/
public function setup_objects() {
self::$instance->affiliates = new Affiliate_WP_DB_Affiliates;
self::$instance->affiliate_meta = new Affiliate_WP_Affiliate_Meta_DB;
self::$instance->referrals = new Affiliate_WP_Referrals_DB;
self::$instance->visits = new Affiliate_WP_Visits_DB;
self::$instance->campaigns = new Affiliate_WP_Campaigns_DB;
self::$instance->settings = new Affiliate_WP_Settings;
self::$instance->tracking = new Affiliate_WP_Tracking;
self::$instance->templates = new Affiliate_WP_Templates;
self::$instance->login = new Affiliate_WP_Login;
self::$instance->register = new Affiliate_WP_Register;
self::$instance->integrations = new Affiliate_WP_Integrations;
self::$instance->emails = new Affiliate_WP_Emails;
self::$instance->creatives = new Affiliate_WP_Creatives_DB;
self::$instance->creative = new Affiliate_WP_Creatives;
self::$instance->rewrites = new Affiliate_WP_Rewrites;
self::$instance->REST = new Affiliate_WP_REST;
self::$instance->capabilities = new Affiliate_WP_Capabilities;
self::$instance->utils = new Affiliate_WP_Utilities;
self::$instance->updater();
}
/**
* Plugin Updater
*
* @access private
* @since 1.0
* @return void
*/
private function updater() {
if( ! is_admin() || ! class_exists( 'AFFWP_Plugin_Updater' ) ) {
return;
}
$license_key = $this->settings->get( 'license_key' );
// setup the updater
$affwp_updater = new AFFWP_Plugin_Updater( 'https://affiliatewp.com', __FILE__, array(
'version' => AFFILIATEWP_VERSION,
'license' => $license_key,
'item_name' => 'AffiliateWP',
'item_id' => 17,
'author' => 'Pippin Williamson',
'beta' => $this->settings->get( 'betas', false )
)
);
}
/**
* Loads the plugin language files
*
* @access public
* @since 1.0
* @return void
*/
public function load_textdomain() {
// Set filter for plugin's languages directory
$lang_dir = dirname( plugin_basename( AFFILIATEWP_PLUGIN_FILE ) ) . '/languages/';
/**
* Filters the languages directory path to use for AffiliateWP.
*
* @param string $lang_dir The languages directory path.
*/
$lang_dir = apply_filters( 'aff_wp_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter
global $wp_version;
$get_locale = get_locale();
if ( $wp_version >= 4.7 ) {
$get_locale = get_user_locale();
}
/**
* Defines the plugin language locale used in AffiliateWP.
*
* @var $get_locale The locale to use. Uses get_user_locale()` in WordPress 4.7 or greater,
* otherwise uses `get_locale()`.
*/
$locale = apply_filters( 'plugin_locale', $get_locale, 'affiliate-wp' );
$mofile = sprintf( '%1$s-%2$s.mo', 'affiliate-wp', $locale );
// Setup paths to current locale file
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/affiliate-wp/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/affiliate-wp/ folder
load_textdomain( 'affiliate-wp', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/affiliate-wp/languages/ folder
load_textdomain( 'affiliate-wp', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'affiliate-wp', false, $lang_dir );
}
}
}
endif; // End if class_exists check
/**
* The main function responsible for returning the one true Affiliate_WP
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $affiliate_wp = affiliate_wp(); ?>
*
* @since 1.0
* @return Affiliate_WP The one true Affiliate_WP Instance
*/
function affiliate_wp() {
return Affiliate_WP::instance();
}
affiliate_wp();