-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathwp-init.php
More file actions
2635 lines (2447 loc) · 88.3 KB
/
wp-init.php
File metadata and controls
2635 lines (2447 loc) · 88.3 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
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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* wp-init.php
*
* Copyright (c) 2010, 2011 "kento" Karim Rahimpur www.itthinx.com
*
* This code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*
* This code 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.
*
* This header and all notices must be kept intact.
*
* @author Karim Rahimpur
* @package affiliates
* @since affiliates 1.1.2
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
global $affiliates_options, $affiliates_version, $affiliates_admin_messages;
if ( !isset( $affiliates_admin_messages ) ) {
$affiliates_admin_messages = array();
}
if ( !isset( $affiliates_version ) ) {
$affiliates_version = AFFILIATES_CORE_VERSION;
}
// base class
require_once AFFILIATES_CORE_LIB . '/class-affiliates.php';
// math class
require_once AFFILIATES_CORE_LIB . '/class-affiliates-math.php';
// options
require_once AFFILIATES_CORE_LIB . '/class-affiliates-options.php';
if ( $affiliates_options == null ) {
$affiliates_options = new Affiliates_Options();
}
// utilities
require_once AFFILIATES_CORE_LIB . '/class-affiliates-utility.php';
require_once AFFILIATES_CORE_LIB . '/class-affiliates-ui-elements.php';
require_once AFFILIATES_CORE_LIB . '/class-affiliates-log.php';
// ajax
require_once AFFILIATES_CORE_LIB . '/class-affiliates-ajax.php';
// robot cleaner
require_once AFFILIATES_CORE_LIB . '/class-affiliates-robot-cleaner.php';
// forms, shortcodes, widgets
require_once AFFILIATES_CORE_LIB . '/class-affiliates-contact.php';
require_once AFFILIATES_CORE_LIB . '/class-affiliates-registration.php';
require_once AFFILIATES_CORE_LIB . '/class-affiliates-registration-widget.php';
require_once AFFILIATES_CORE_LIB . '/class-affiliates-shortcodes.php'; // don't make it conditional on is_admin(), get_total() is used in Manage Affiliates
// templates and dashboard
require_once AFFILIATES_CORE_LIB . '/class-affiliates-templates.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/interface-affiliates-dashboard.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-factory.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-section-factory.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/interface-affiliates-dashboard-section.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/interface-affiliates-dashboard-section-table.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-section.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-section-table.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-login.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-login-block.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-login-shortcode.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-registration.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-registration-block.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-registration-shortcode.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-overview.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-overview-block.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-overview-shortcode.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-earnings.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-earnings-block.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-earnings-shortcode.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-profile.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-profile-block.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-profile-shortcode.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-block.php';
require_once AFFILIATES_CORE_LIB . '/dashboard/class-affiliates-dashboard-shortcode.php';
// built-in user registration integration
if (
( get_option( 'aff_user_registration_enabled', 'no' ) == 'yes' ) ||
( get_option( 'aff_customer_registration_enabled', 'no' ) == 'yes' )
) {
require_once AFFILIATES_CORE_LIB . '/class-affiliates-user-registration.php';
}
// affiliates excluded
require_once AFFILIATES_CORE_LIB . '/class-affiliates-exclusion.php';
// affiliates notifications
require_once AFFILIATES_CORE_LIB . '/class-affiliates-notifications.php';
if ( is_admin() ) {
if ( AFFILIATES_PLUGIN_NAME == 'affiliates' ) {
require_once AFFILIATES_CORE_LIB . '/class-affiliates-admin-notifications.php';
}
}
// affiliates notice
require_once AFFILIATES_CORE_LIB . '/class-affiliates-notice.php';
add_action( 'widgets_init', 'affiliates_widgets_init' );
/**
* Register widgets
*/
function affiliates_widgets_init() {
register_widget( 'Affiliates_Contact' );
register_widget( 'Affiliates_Registration_Widget' );
}
add_action( 'admin_init', 'affiliates_admin_init' );
/**
* Hook into admin_init. Used to get our styles at the right place.
* @see affiliates_admin_menu()
* @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages
*/
function affiliates_admin_init() {
global $affiliates_version;
wp_register_style( 'smoothness', AFFILIATES_PLUGIN_URL . 'css/smoothness/jquery-ui.min.css', array(), $affiliates_version );
wp_register_style( 'affiliates_admin', AFFILIATES_PLUGIN_URL . 'css/affiliates_admin.css', array(), $affiliates_version );
}
/**
* Load styles.
* @see affiliates_admin_menu()
*/
function affiliates_admin_print_styles() {
wp_enqueue_style( 'smoothness' );
wp_enqueue_style( 'affiliates_admin' );
}
/**
* Load scripts.
*/
function affiliates_admin_print_scripts() {
global $post_type, $affiliates_version;
// load datepicker scripts for all
wp_enqueue_script( 'datepicker', AFFILIATES_PLUGIN_URL . 'js/jquery-ui.min.js', array( 'jquery', 'jquery-ui-core' ), $affiliates_version );
wp_enqueue_script( 'datepickers', AFFILIATES_PLUGIN_URL . 'js/datepickers.js', array( 'jquery', 'jquery-ui-core', 'datepicker' ), $affiliates_version );
// add more dates used for trips and events
wp_enqueue_script( 'affiliates', AFFILIATES_PLUGIN_URL . 'js/affiliates.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-button' ), $affiliates_version );
// and thus are the translations of the buttons used
wp_enqueue_script( 'excanvas', AFFILIATES_PLUGIN_URL . 'js/graph/flot/excanvas.min.js', array( 'jquery' ), $affiliates_version );
wp_enqueue_script( 'flot', AFFILIATES_PLUGIN_URL . 'js/graph/flot/jquery.flot.min.js', array( 'jquery' ), $affiliates_version );
wp_enqueue_script( 'flot-resize', AFFILIATES_PLUGIN_URL . 'js/graph/flot/jquery.flot.resize.min.js', array( 'jquery', 'flot' ), $affiliates_version );
// Selectize
$screen = get_current_screen();
if ( isset( $screen->id ) ) {
switch( $screen->id ) {
case 'affiliates_page_affiliates-admin-referrals' :
case 'affiliates_page_affiliates-admin-hits-uri' :
case 'affiliates_page_affiliates-admin-hits-affiliate' :
case 'affiliates_page_affiliates-admin-hits' :
Affiliates_UI_Elements::enqueue( 'select' );
break;
}
}
// echo '
// <script type="text/javascript">
// var fooText = "' . __( 'Foo', 'affiliates' ) . '";
// </script>
// ';
}
add_action( 'wp_enqueue_scripts', 'affiliates_wp_enqueue_scripts' );
function affiliates_wp_enqueue_scripts() {
global $affiliates_version;
wp_register_style( 'affiliates', AFFILIATES_PLUGIN_URL . 'css/affiliates.css', array(), $affiliates_version );
}
// ---
register_activation_hook( AFFILIATES_FILE, 'affiliates_activate' );
add_action( 'wpmu_new_blog', 'affiliates_wpmu_new_blog', 10, 2 );
add_action( 'delete_blog', 'affiliates_delete_blog', 10, 2 );
add_action( 'init', 'affiliates_version_check' );
function affiliates_version_check() {
global $affiliates_version, $affiliates_admin_messages;
$previous_version = get_option( 'affiliates_plugin_version', '' );
$affiliates_version = AFFILIATES_CORE_VERSION;
if ( version_compare( $previous_version, $affiliates_version ) < 0 ) {
$update_result = affiliates_update( $previous_version );
if ( $update_result === true ) {
update_option( 'affiliates_plugin_version', $affiliates_version );
} else {
if ( $update_result === false ) {
affiliates_log_error( 'There were errors during update (core) – this might only be a temporary issue, unless this message comes up permanently.' );
}
}
}
}
function affiliates_admin_notices() {
global $affiliates_admin_messages;
if ( !empty( $affiliates_admin_messages ) ) {
foreach ( $affiliates_admin_messages as $msg ) {
echo $msg;
}
}
}
add_action( 'admin_notices', 'affiliates_admin_notices' );
/**
* Tasks performed upon plugin activation.
*/
function affiliates_activate( $network_wide = false ) {
if ( is_multisite() && $network_wide ) {
$blog_ids = affiliates_get_blogs();
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
affiliates_setup();
restore_current_blog();
}
} else {
affiliates_setup();
}
}
/**
* Setup for a new creat blog.
* @param int $blog_id
*/
function affiliates_wpmu_new_blog( $blog_id, $user_id ) {
if ( is_multisite() ) {
if ( affiliates_is_sitewide_plugin() ) {
switch_to_blog( $blog_id );
affiliates_setup();
restore_current_blog();
}
}
}
/**
* Clean up for a given blog.
*
* @param int $blog_id
* @param boolean $drop
*/
function affiliates_delete_blog( $blog_id, $drop = false ) {
if ( is_multisite() ) {
if ( affiliates_is_sitewide_plugin() ) {
switch_to_blog( $blog_id );
affiliates_cleanup( $drop );
restore_current_blog();
}
}
}
/**
* Returns true if the plugin is site-wide.
* @return boolean true if site-wide plugin
*/
function affiliates_is_sitewide_plugin() {
$result = false;
if ( is_multisite() ) {
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins', array() );
$active_sitewide_plugins = array_keys( $active_sitewide_plugins );
$components = explode( DIRECTORY_SEPARATOR, AFFILIATES_FILE );
$plugin = '';
$n = count( $components );
if ( isset( $components[$n - 2] ) ) {
$plugin .= $components[$n - 2] . DIRECTORY_SEPARATOR;
}
$plugin .= $components[$n - 1];
$result = in_array( $plugin, $active_sitewide_plugins );
}
return $result;
}
/**
* Retrieve current blogs' ids.
* @return array blog ids
*/
function affiliates_get_blogs() {
global $wpdb;
$result = array();
if ( is_multisite() ) {
$blogs = $wpdb->get_results( $wpdb->prepare(
"SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0'",
$wpdb->siteid
) );
if ( is_array( $blogs ) ) {
foreach( $blogs as $blog ) {
$result[] = $blog->blog_id;
}
}
} else {
$result[] = get_current_blog_id();
}
return $result;
}
/**
* Create tables and prepare data.
*/
function affiliates_setup() {
global $wpdb, $wp_roles;
_affiliates_set_default_capabilities();
$charset_collate = '';
if ( ! empty( $wpdb->charset ) ) {
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
}
if ( ! empty( $wpdb->collate ) ) {
$charset_collate .= " COLLATE $wpdb->collate";
}
$affiliates_table = _affiliates_get_tablename('affiliates');
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $affiliates_table . "'" ) != $affiliates_table ) {
$queries[] = "CREATE TABLE " . $affiliates_table . "(
affiliate_id bigint(20) unsigned NOT NULL auto_increment,
name varchar(100) NOT NULL,
email varchar(512) default NULL,
from_date date NOT NULL,
thru_date date default NULL,
status varchar(10) NOT NULL DEFAULT 'active',
type varchar(10) NULL,
PRIMARY KEY (affiliate_id),
INDEX affiliates_afts (affiliate_id, from_date, thru_date, status),
INDEX affiliates_sft (status, from_date, thru_date)
) $charset_collate;";
}
// email @see http://tools.ietf.org/html/rfc5321
// 2.3.11. Mailbox and Address
// ... The standard mailbox naming convention is defined to
// be "local-part@domain"; ...
// 4.1.2. Command Argument Syntax
// ...
// Mailbox = Local-part "@" ( Domain / address-literal )
// ...
// 4.5.3. Sizes and Timeouts
// 4.5.3.1.1. Local-part
// The maximum total length of a user name or other local-part is 64 octets.
// 4.5.3.1.2. Domain
// The maximum total length of a domain name or number is 255 octets.
// 4.5.3.1.3. Path
// The maximum total length of a reverse-path or forward-path is 256
// octets (including the punctuation and element separators).
// So the maximum size of an email address is ... ?
// 64 + 1 + 255 = 320 octets
// Then again, people change their minds ... we'll assume 512 as sufficient.
// Note: WP's user.user_email is varchar(100) @see wp-admin/includes/schema.php
// IPv6 addr
// FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF = 340282366920938463463374607431768211455
// Note that ipv6 is not part of the PK but can be handled using
// the lower bits of the ipv6 address to fill in ip and using the
// complete IPv6 address on ipv6.
// Note also, that currently Affiliates does NOT use ipv6.
$referrals_table = _affiliates_get_tablename( 'referrals' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $referrals_table . "'" ) != $referrals_table ) {
$queries[] = "CREATE TABLE " . $referrals_table . "(
referral_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
affiliate_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
campaign_id BIGINT(20) UNSIGNED DEFAULT NULL,
post_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
datetime DATETIME NOT NULL,
description VARCHAR(5000),
ip INT(10) UNSIGNED DEFAULT NULL,
ipv6 DECIMAL(39,0) UNSIGNED DEFAULT NULL,
user_id BIGINT(20) UNSIGNED DEFAULT NULL,
amount DECIMAL(24,6) DEFAULT NULL,
reference_amount DECIMAL(24,6) DEFAULT NULL,
currency_id CHAR(3) DEFAULT NULL,
data LONGTEXT DEFAULT NULL,
status VARCHAR(10) NOT NULL DEFAULT '" . AFFILIATES_REFERRAL_STATUS_ACCEPTED . "',
type VARCHAR(10) NULL,
reference VARCHAR(100) DEFAULT NULL,
hit_id BIGINT(20) UNSIGNED DEFAULT NULL,
integration VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (referral_id),
INDEX aff_referrals_apd (affiliate_id, post_id, datetime),
INDEX aff_referrals_da (datetime, affiliate_id),
INDEX aff_referrals_sda (status, datetime, affiliate_id),
INDEX aff_referrals_tda (type, datetime, affiliate_id),
INDEX aff_referrals_ref (reference(20)),
INDEX aff_referrals_ac (affiliate_id, campaign_id),
INDEX aff_referrals_c (campaign_id),
INDEX aff_referrals_h (hit_id),
INDEX integration (integration(20))
) $charset_collate;";
// @see http://bugs.mysql.com/bug.php?id=27645 as of now (2011-03-19) NOW() can not be specified as the default value for a datetime column
}
$referral_items_table = _affiliates_get_tablename( 'referral_items' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $referral_items_table . "'" ) != $referral_items_table ) {
$queries[] = "CREATE TABLE " . $referral_items_table . "(
referral_item_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
referral_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
amount DECIMAL(24,6) DEFAULT NULL,
line_amount DECIMAL(24,6) DEFAULT NULL,
currency_id CHAR(3) DEFAULT NULL,
rate_id BIGINT(20) UNSIGNED DEFAULT NULL,
type VARCHAR(20) NULL,
reference VARCHAR(100) DEFAULT NULL,
object_id BIGINT(20) UNSIGNED DEFAULT NULL,
PRIMARY KEY (referral_item_id),
INDEX referral_id (referral_id),
INDEX reference (reference(20)),
INDEX object_id (object_id)
) $charset_collate;";
}
// IMPORTANT:
// datetime -- records the datetime with respect to the server's timezone
// date and datetime are are also with respect to the server's timezone
// date is used for better performance in queries, datetime to provide detail when viewed
// We DO use the datetime (adjusted to the user's timezone using
// DateHelper's s2u() function to display the date and time
// in accordance to the user's date and time.
// @todo ip/ipv6 (also for referrals table) : create new table and map hits.ip_id to ip.ip_id instead of storing those
$hits_table = _affiliates_get_tablename( 'hits' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $hits_table . "'" ) != $hits_table ) {
$queries[] = "CREATE TABLE " . $hits_table . "(
hit_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
hash CHAR(64) DEFAULT NULL,
affiliate_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
campaign_id BIGINT(20) UNSIGNED DEFAULT NULL,
date DATE NOT NULL,
datetime DATETIME NOT NULL,
ip INT(10) UNSIGNED NOT NULL DEFAULT 0,
src_uri_id BIGINT(20) UNSIGNED DEFAULT NULL,
dest_uri_id BIGINT(20) UNSIGNED DEFAULT NULL,
user_agent_id BIGINT(20) UNSIGNED DEFAULT NULL,
is_robot TINYINT DEFAULT 0,
user_id BIGINT(20) UNSIGNED DEFAULT NULL,
type VARCHAR(10) DEFAULT NULL,
PRIMARY KEY (hit_id),
INDEX hash (hash),
INDEX idx_date (date),
INDEX aff_hits_acm (affiliate_id, campaign_id),
INDEX aff_hits_src_uri (src_uri_id),
INDEX aff_hits_dest_uri (dest_uri_id),
INDEX aff_hits_ua (user_agent_id)
) $charset_collate;";
}
$uris_table = _affiliates_get_tablename( 'uris' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $uris_table . "'" ) != $uris_table ) {
$queries[] = "CREATE TABLE " . $uris_table . "(
uri_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
uri VARCHAR(2048) NOT NULL,
type VARCHAR(10) DEFAULT NULL,
PRIMARY KEY (uri_id),
INDEX uri (uri(100)),
INDEX type (type)
) $charset_collate;";
}
// add the user_agents table
$user_agents_table = _affiliates_get_tablename( 'user_agents' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $user_agents_table . "'" ) != $user_agents_table ) {
$queries[] = "CREATE TABLE " . $user_agents_table . "(
user_agent_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
user_agent VARCHAR(255) NOT NULL,
PRIMARY KEY (user_agent_id),
INDEX user_agent (user_agent(32))
) $charset_collate;";
}
$robots_table = _affiliates_get_tablename( 'robots' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $robots_table . "'" ) != $robots_table ) {
$queries[] = "CREATE TABLE " . $robots_table . "(
robot_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
name VARCHAR(100) NOT NULL,
PRIMARY KEY (robot_id),
INDEX aff_robots_n (name)
) $charset_collate;";
}
$affiliates_users_table = _affiliates_get_tablename( 'affiliates_users' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $affiliates_users_table . "'" ) != $affiliates_users_table ) {
$queries[] = "CREATE TABLE " . $affiliates_users_table . "(
affiliate_id BIGINT(20) UNSIGNED NOT NULL,
user_id BIGINT(20) UNSIGNED NOT NULL,
PRIMARY KEY (affiliate_id, user_id)
) $charset_collate;";
}
if ( !empty( $queries ) ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $queries );
}
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $affiliates_table . "'" ) == $affiliates_table ) {
$today = date( 'Y-m-d', time() );
$direct = intval( $wpdb->get_var( "SELECT COUNT(affiliate_id) FROM $affiliates_table WHERE type = '" . AFFILIATES_DIRECT_TYPE . "';" ) );
if ( $direct <= 0 ) {
$wpdb->query( "INSERT INTO $affiliates_table (name, from_date, type) VALUES ('" . AFFILIATES_DIRECT_NAME . "','$today','" . AFFILIATES_DIRECT_TYPE . "');" );
}
}
affiliates_update();
affiliates_update_rewrite_rules();
}
/**
* Determines the default capabilities for the administrator role.
* In lack of an administrator role, these capabilities are assigned
* to any role that can manage_options.
* This is also used to assure a minimum set of capabilities is
* assigned to an appropriate role, so that it's not possible
* to lock yourself out (although deactivating and then activating
* the plugin would have the same effect but with the danger of
* deleting all plugin data).
* @param boolean $activate defaults to true, when this function is called upon plugin activation
* @access private
*/
function _affiliates_set_default_capabilities() {
global $wp_roles;
// The administrator role should be there, if it's not, assign privileges to
// any role that can manage_options:
if ( $administrator_role = $wp_roles->get_role( 'administrator' ) ) {
$administrator_role->add_cap( AFFILIATES_ACCESS_AFFILIATES );
$administrator_role->add_cap( AFFILIATES_ADMINISTER_AFFILIATES );
$administrator_role->add_cap( AFFILIATES_ADMINISTER_OPTIONS );
} else {
foreach ( $wp_roles->role_objects as $role ) {
if ($role->has_cap( 'manage_options' ) ) {
$role->add_cap( AFFILIATES_ACCESS_AFFILIATES );
$role->add_cap( AFFILIATES_ADMINISTER_AFFILIATES );
$role->add_cap( AFFILIATES_ADMINISTER_OPTIONS );
}
}
}
}
/**
* There must be at least one role with the minimum set of capabilities
* to access and manage the Affiliates plugin's options.
* If this condition is not met, the minimum set of capabilities is
* reestablished.
*/
function _affiliates_assure_capabilities() {
global $wp_roles;
$complies = false;
$roles = $wp_roles->role_objects;
foreach( $roles as $role ) {
if ( $role->has_cap( AFFILIATES_ACCESS_AFFILIATES ) && ( $role->has_cap( AFFILIATES_ADMINISTER_OPTIONS ) ) ) {
$complies = true;
break;
}
}
if ( !$complies ) {
_affiliates_set_default_capabilities();
}
}
/**
* Update from a previous version or repair on activation (within 2.x).
*
* This is called from affiliates_setup() on plugin activation and affiliates_version_check()
* when a previous version is detected.
*
* @param string $previous_version
*
* @return boolean or null if update procedure was skipped (DOING_AJAX or DOING_CRON)
*/
function affiliates_update( $previous_version = null ) {
global $wpdb;
$result = true;
$queries = array();
if (
defined( 'DOING_AJAX' ) && DOING_AJAX ||
defined( 'DOING_CRON' ) && DOING_CRON
) {
return null;
}
$charset_collate = '';
if ( ! empty( $wpdb->charset ) ) {
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
}
if ( ! empty( $wpdb->collate ) ) {
$charset_collate .= " COLLATE $wpdb->collate";
}
$hits_table = _affiliates_get_tablename( 'hits' );
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'campaign_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $hits_table . "
ADD COLUMN campaign_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD INDEX aff_hits_acm (affiliate_id, campaign_id);";
}
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'hit_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $hits_table . "
ADD COLUMN hit_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
ADD COLUMN hash CHAR(64) DEFAULT NULL,
DROP PRIMARY KEY,
ADD PRIMARY KEY (hit_id),
ADD INDEX hash (hash);";
}
// from 4.0.0 drop indexes : aff_hits_dtd, aff_hits_ddt, aid_d_t_ip
$index = $wpdb->get_results( "SHOW INDEX FROM $hits_table WHERE Key_name = 'aff_hits_dtd'" );
if ( is_array( $index ) && count( $index ) > 0 ) {
$queries[] = "ALTER TABLE $hits_table DROP INDEX aff_hits_dtd;";
}
$index = $wpdb->get_results( "SHOW INDEX FROM $hits_table WHERE Key_name = 'aff_hits_ddt'" );
if ( is_array( $index ) && count( $index ) > 0 ) {
$queries[] = "ALTER TABLE $hits_table DROP INDEX aff_hits_ddt;";
}
$index = $wpdb->get_results( "SHOW INDEX FROM $hits_table WHERE Key_name = 'aid_d_t_ip'" );
if ( is_array( $index ) && count( $index ) > 0 ) {
$queries[] = "ALTER TABLE $hits_table DROP INDEX aid_d_t_ip;";
}
// from 4.0.0 add index : idx_date
$index = $wpdb->get_results( "SHOW INDEX FROM $hits_table WHERE Key_name = 'idx_date'" );
if ( $index === null || is_array( $index ) && count( $index ) === 0 ) {
$queries[] = "ALTER TABLE $hits_table ADD INDEX idx_date (date);";
}
// from 4.0.0 drop the time column
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'time'" );
if ( !empty( $column ) ) {
$queries[] = "ALTER TABLE $hits_table DROP COLUMN time;";
}
// from 4.0.0 drop the ipv6 column
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'ipv6'" );
if ( !empty( $column ) ) {
$queries[] = "ALTER TABLE $hits_table DROP COLUMN ipv6;";
}
// from 4.0.0 drop the count column
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'count'" );
if ( !empty( $column ) ) {
$queries[] = "ALTER TABLE $hits_table DROP COLUMN count;";
}
// URIs ... from 2.17.0
// add the uris table
$uris_table = _affiliates_get_tablename( 'uris' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $uris_table . "'" ) != $uris_table ) {
$queries[] = "CREATE TABLE " . $uris_table . "(
uri_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
uri VARCHAR(2048) NOT NULL,
type VARCHAR(10) DEFAULT NULL,
PRIMARY KEY (uri_id),
INDEX uri (uri(100)),
INDEX type (type)
) $charset_collate;";
}
// add uri columns and indexes to the hits table
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'src_uri_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $hits_table . "
ADD COLUMN src_uri_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD COLUMN dest_uri_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD INDEX aff_hits_src_uri (src_uri_id),
ADD INDEX aff_hits_dest_uri (dest_uri_id);";
}
// add the user_agents table
$user_agents_table = _affiliates_get_tablename( 'user_agents' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $user_agents_table . "'" ) != $user_agents_table ) {
$queries[] = "CREATE TABLE " . $user_agents_table . "(
user_agent_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
user_agent VARCHAR(255) NOT NULL,
PRIMARY KEY (user_agent_id),
INDEX user_agent (user_agent(32))
) $charset_collate;";
}
// add the user_agent_id column to the hits table
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'user_agent_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $hits_table . "
ADD COLUMN user_agent_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD INDEX aff_hits_ua (user_agent_id);";
}
$referrals_table = _affiliates_get_tablename( 'referrals' );
$column = $wpdb->get_row( "SHOW COLUMNS FROM $referrals_table LIKE 'campaign_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $referrals_table . "
ADD COLUMN campaign_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD INDEX aff_referrals_ac (affiliate_id, campaign_id),
ADD INDEX aff_referrals_c (campaign_id);";
}
$column = $wpdb->get_row( "SHOW COLUMNS FROM $referrals_table LIKE 'hit_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $referrals_table . "
ADD COLUMN hit_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD INDEX aff_referrals_h (hit_id);";
}
// Referrals amount precision to DECIMAL(24,6) ... from 2.18.0
if ( !empty( $previous_version ) && version_compare( $previous_version, '2.18.0' ) < 0 ) {
$queries[] = "ALTER TABLE " . $referrals_table . "
MODIFY amount DECIMAL(24,6) DEFAULT NULL;";
}
// add the reference_amount and integration columns to the referrals table ... from 3.0.0
// if ( !empty( $previous_version ) && version_compare( $previous_version, '3.0.0' ) < 0 ) {
$column = $wpdb->get_row( "SHOW COLUMNS FROM $referrals_table LIKE 'reference_amount'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $referrals_table . "
ADD COLUMN reference_amount DECIMAL(24,6) DEFAULT NULL,
ADD COLUMN integration VARCHAR(255) DEFAULT NULL,
ADD INDEX integration (integration(20));";
}
// }
// add the referral_items table ... from 3.0.0
$referral_items_table = _affiliates_get_tablename( 'referral_items' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $referral_items_table . "'" ) != $referral_items_table ) {
$queries[] = "CREATE TABLE " . $referral_items_table . "(
referral_item_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
referral_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
amount DECIMAL(24,6) DEFAULT NULL,
line_amount DECIMAL(24,6) DEFAULT NULL,
currency_id CHAR(3) DEFAULT NULL,
rate_id BIGINT(20) UNSIGNED DEFAULT NULL,
type VARCHAR(20) NULL,
reference VARCHAR(100) DEFAULT NULL,
object_id BIGINT(20) UNSIGNED DEFAULT NULL,
PRIMARY KEY (referral_item_id),
INDEX referral_id (referral_id),
INDEX reference (reference(20)),
INDEX object_id (object_id)
) $charset_collate;";
}
// MySQL 5.7.3 PK requirements
if ( !empty( $previous_version ) && version_compare( $previous_version, '2.15.10' ) < 0 ) {
$queries[] = "ALTER TABLE " . $hits_table . "
MODIFY ip INT(10) UNSIGNED NOT NULL DEFAULT 0;";
}
foreach ( $queries as $query ) {
// don't use dbDelta, it doesn't handle ALTER
if ( $wpdb->query( $query ) === false ) {
$result = false;
}
}
if ( !empty( $previous_version ) && version_compare( $previous_version, '2.1.5' ) < 0 ) {
affiliates_update_rewrite_rules();
}
return $result;
}
register_deactivation_hook( AFFILIATES_FILE, 'affiliates_deactivate' );
/**
* Drop tables and clear data if the plugin is deactivated.
* This will happen only if the user chooses to delete data upon deactivation.
*/
function affiliates_deactivate( $network_wide = false ) {
if ( is_multisite() && $network_wide ) {
if ( get_option( 'aff_delete_network_data', false ) ) {
$blog_ids = affiliates_get_blogs();
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
affiliates_cleanup( true );
restore_current_blog();
}
}
} else {
affiliates_cleanup();
}
}
/**
* Cleans up tables, data, capabilities if the option is set.
*
* @param boolean $delete force deletion
*/
function affiliates_cleanup( $delete = false ) {
global $wpdb, $affiliates_options, $wp_roles;
$delete_data = get_option( 'aff_delete_data', false ) || $delete;
if ( $delete_data ) {
foreach ( $wp_roles->role_objects as $role ) {
$role->remove_cap( AFFILIATES_ACCESS_AFFILIATES );
$role->remove_cap( AFFILIATES_ADMINISTER_AFFILIATES );
$role->remove_cap( AFFILIATES_ADMINISTER_OPTIONS );
}
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'referral_items' ) );
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'referrals' ) );
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'hits' ) );
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'uris' ) );
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'user_agents' ) );
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'affiliates' ) );
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'robots' ) );
$wpdb->query('DROP TABLE IF EXISTS ' . _affiliates_get_tablename( 'affiliates_users' ) );
flush_rewrite_rules();
$affiliates_options->flush_options();
delete_option( 'affiliates_plugin_version' );
delete_option( 'aff_allow_auto' );
delete_option( 'aff_allow_auto_coupons' );
delete_option( 'aff_cookie_timeout_days' );
delete_option( 'aff_customer_registration_enabled' );
delete_option( 'aff_default_referral_status' );
delete_option( 'aff_delete_data' );
delete_option( 'aff_delete_network_data' );
delete_option( 'aff_duplicates' );
delete_option( 'aff_id_encoding' );
delete_option( 'aff_notify_admin' );
delete_option( 'aff_pname' );
delete_option( 'aff_redirect' );
delete_option( 'aff_registration' );
delete_option( 'aff_registration_terms_post_id' );
delete_option( 'aff_registration_fields' );
delete_option( 'aff_setup_hide' );
delete_option( 'aff_status' );
delete_option( 'aff_use_direct' );
delete_option( 'aff_user_registration_amount' );
delete_option( 'aff_user_registration_base_amount' );
delete_option( 'aff_user_registration_currency' );
delete_option( 'aff_user_registration_enabled' );
delete_option( 'aff_user_registration_referral_status' );
delete_site_option( 'affiliates-init-time' );
delete_metadata( 'user', null, 'affiliates-hide-review-notice', null, true );
}
}
add_action( 'init', 'affiliates_init' );
/**
* Initialize.
* Loads the plugin's translations.
*/
function affiliates_init() {
load_plugin_textdomain( 'affiliates', null, AFFILIATES_PLUGIN_NAME . '/lib/core/languages' );
if ( class_exists( 'Affiliates_Affiliate' ) && method_exists( 'Affiliates_Affiliate', 'register_attribute_filter' ) ) {
Affiliates_Affiliate::register_attribute_filter( 'affiliates_attribute_filter' );
}
add_action( 'after_plugin_row_' . plugin_basename( AFFILIATES_FILE ), 'affiliates_after_plugin_row', 10, 3 );
// translators: the name of the pseudo-affiliate
_x( 'Direct', 'pseudo-affiliate name', 'affiliates' );
}
/**
* Prints a warning when data is deleted on deactivation.
*
* @param string $plugin_file
* @param array $plugin_data
* @param string $status
*/
function affiliates_after_plugin_row( $plugin_file, $plugin_data, $status ) {
if ( $plugin_file == plugin_basename( AFFILIATES_FILE ) ) {
$delete_data = get_option( 'aff_delete_data', false );
$delete_network_data = get_option( 'aff_delete_network_data', false );
if (
( is_plugin_active( $plugin_file ) && $delete_data && current_user_can( 'install_plugins' ) ) ||
( is_plugin_active_for_network( $plugin_file ) && $delete_network_data && current_user_can( 'manage_network_plugins' ) )
) {
echo '<tr class="active">';
echo '<td> </td>';
echo '<td colspan="2">';
echo '<div style="border: 2px solid #dc3232; padding: 1em">';
echo '<p>';
echo '<strong>';
echo esc_html( __( 'Warning!', 'affiliates' ) );
echo '</strong>';
echo '</p>';
echo '<p>';
echo esc_html( __( 'The plugin is configured to delete its data on deactivation.', 'affiliates' ) );
echo '</p>';
echo '</div>';
echo '</td>';
echo '</tr>';
}
}
}
add_filter( 'query_vars', 'affiliates_query_vars', 999 ); // filter acts late to avoid being messed with by others
/**
* Register the affiliate query variable.
* In addition to existing query variables, we'll use affiliates in the URL to track referrals.
* @see affiliates_update_rewrite_rules() for the rewrite rule that matches the affiliates id
*/
function affiliates_query_vars( $query_vars ) {
$pname = get_option( 'aff_pname', AFFILIATES_PNAME );
$query_vars[] = $pname;
return $query_vars;
}
/**
* Add a rewrite rule for pretty links.
* @deprecated
*/
function affiliates_update_rewrite_rules() {
$pname = get_option( 'aff_pname', AFFILIATES_PNAME );
add_rewrite_rule(
str_replace( AFFILIATES_PNAME, $pname, AFFILIATES_REGEX_PATTERN ),
'index.php?' . $pname . '=$matches[1]',
'top'
);
flush_rewrite_rules();
}
add_action( 'parse_request', 'affiliates_parse_request' );
/**
* Looks in the query variables and sets a cookie with the affiliate id.
* Hook into parse_request.
* @param WP $wp the WordPress environment
* @link http://php.net/manual/en/function.setcookie.php
*/
function affiliates_parse_request( &$wp ) {
global $wpdb, $affiliates_options, $affiliates_request_encoded_id;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
$pname = get_option( 'aff_pname', AFFILIATES_PNAME );
$affiliate_id = isset( $wp->query_vars[$pname] ) ? affiliates_check_affiliate_id_encoded( trim( $wp->query_vars[$pname] ) ) : null;
if ( isset( $wp->query_vars[$pname] ) ) {
$maybe_affiliate_id = $affiliate_id;
if ( has_filter( 'affiliates_parse_request_affiliate_id' ) ) {
/**
* @deprecated The affiliates_parse_request_affiliate_id filter is deprecated since 4.2.0, use affiliates_parse_request_assess_affiliate_id instead.
*/
$maybe_affiliate_id = intval( apply_filters( 'affiliates_parse_request_affiliate_id', $wp->query_vars[$pname], $affiliate_id ) );
}
// @since 4.2.0
$maybe_affiliate_id = apply_filters(
'affiliates_parse_request_assess_affiliate_id',
$maybe_affiliate_id,
$wp->query_vars[$pname],
$pname
);
if ( intval( $maybe_affiliate_id ) > 0 && $maybe_affiliate_id !== $affiliate_id ) {
$maybe_affiliate_id = affiliates_check_affiliate_id( $maybe_affiliate_id );
if ( $maybe_affiliate_id !== false ) {
$affiliate_id = $maybe_affiliate_id;
}
}
}
if ( $affiliate_id ) {
$encoded_id = affiliates_encode_affiliate_id( $affiliate_id );
$days = apply_filters( 'affiliates_cookie_timeout_days', get_option( 'aff_cookie_timeout_days', AFFILIATES_COOKIE_TIMEOUT_DAYS ), $affiliate_id );
if ( $days > 0 ) {
$expire = time() + AFFILIATES_COOKIE_TIMEOUT_BASE * $days;
} else {
$expire = 0;
}
if ( class_exists( 'Affiliates_Campaign' ) && method_exists( 'Affiliates_Campaign', 'evaluate' ) ) {
if ( !empty( $_REQUEST['cmid'] ) ) {
if ( $cmid = Affiliates_Campaign::evaluate( $_REQUEST['cmid'], $affiliate_id ) ) {
$encoded_id .= '.' . $cmid;
}
}
}
$affiliates_request_encoded_id = $encoded_id;
$hit = affiliates_record_hit( $affiliate_id );
$cookiepaths = array( COOKIEPATH );
if ( SITECOOKIEPATH != COOKIEPATH ) {
$cookiepaths[] = SITECOOKIEPATH;
}
foreach ( $cookiepaths as $cookiepath ) {
setcookie(
AFFILIATES_COOKIE_NAME,
$encoded_id,
$expire,
$cookiepath,
COOKIE_DOMAIN
);
if ( !empty( $hit['hash'] ) ) {
setcookie(
AFFILIATES_HASH_COOKIE_NAME,
$hit['hash'],
$expire,
$cookiepath,
COOKIE_DOMAIN
);
}
}
affiliates_pixel_request();
unset( $wp->query_vars[$pname] ); // we use this to avoid ending up on the blog listing page
if ( get_option( 'aff_redirect', false ) !== false ) {