-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrsvpmaker.php
1089 lines (648 loc) · 28.8 KB
/
rsvpmaker.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
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
/*
* Plugin Name: RSVPMaker
* Plugin URI: http://www.rsvpmaker.com
* Description: Schedule events, send invitations to your mailing list and track RSVPs. You get all your familiar WordPress editing tools with extra options for setting dates and RSVP options. Online payments with PayPal or Stripe can be added with a little extra configuration. Email invitations can be sent through MailChimp or to members of your website community who have user accounts. Recurring events can be tracked according to a schedule such as "First Monday" or "Every Friday" at a specified time, and the software will calculate future dates according to that schedule and let you track them together. <a href="options-general.php?page=rsvpmaker-admin.php">Options</a>
* Author: David F. Carr
* Author URI: http://www.carrcommunications.com
* Text Domain: rsvpmaker
* Domain Path: /translations
* Requires at least: 5.2
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Version: 11.4.4
*/
function get_rsvpversion() {
return '11.4.4';
}
global $wp_version;
global $default_tz;
$default_tz = date_default_timezone_get();
if ( version_compare( $wp_version, '3.0', '<' ) ) {
exit( __( 'RSVPmaker plugin requires WordPress 3.0 or greater', 'rsvpmaker' ) );
}
function rsvpmaker_load_plugin_textdomain() {
load_plugin_textdomain( 'rsvpmaker', false, basename( dirname( __FILE__ ) ) . '/translations/' );
}
global $rsvp_options;
$rsvp_options = get_option( 'RSVPMAKER_Options' );
$locale = get_locale();
function rsvp_options_defaults() {
global $rsvp_options;
if ( empty( $rsvp_options ) ) {
$rsvp_options = array();
}
// defaults
$rsvp_defaults = array(
'menu_security' => 'manage_options',
'rsvpmaker_template' => 'publish_rsvpmakers',
'recurring_event' => 'publish_rsvpmakers',
'multiple_events' => 'publish_rsvpmakers',
'documentation' => 'edit_rsvpmakers',
'calendar_icons' => 1,
'social_title_date' => 1,
'default_content' => '',
'rsvp_to' => get_bloginfo( 'admin_email' ),
'confirmation_include_event' => 0,
'rsvpmaker_send_confirmation_email' => 1,
'rsvp_instructions' => '',
'rsvp_count' => 1,
'rsvp_count_party' => 1,
'rsvp_yesno' => 1,
'send_payment_reminders' => 1,
'cancel_unpaid_hours' => 0,
'rsvp_on' => 0,
'rsvp_max' => 0,
'login_required' => 0,
'rsvp_captcha' => 0,
'show_attendees' => 0,
'convert_timezone' => 0,
'add_timezone' => 0,
'rsvp_form_title' => __( 'RSVP Now!', 'rsvpmaker' ),
'defaulthour' => 19,
'defaultmin' => 0,
'long_date' => 'l F j, Y',
'short_date' => 'M j',
'time_format' => 'g:i A',
'smtp' => '',
'paypal_currency' => 'USD',
'currency_decimal' => '.',
'currency_thousands' => ',',
'payment_minimum' => '5.00',
'paypal_invoiceno' => 1,
'stripe' => 0,
'show_screen_recurring' => 0,
'show_screen_multiple' => 0,
'dashboard_message' => '',
'rsvpmaker_send_confirmation_email' => 1,
'update_rsvp' => __( 'Update RSVP', 'rsvpmaker' ),
);
$rsvp_defaults = apply_filters( 'rsvpmaker_defaults', $rsvp_defaults );
foreach ( $rsvp_defaults as $index => $value ) {
if ( ! isset( $rsvp_options[ $index ] ) ) {
$rsvp_options[ $index ] = $rsvp_defaults[ $index ];
}
}
$rsvp_options['rsvplink'] = get_rsvp_link();
$rsvp_options['rsvplink_edit'] = admin_url('post.php?action=edit&post='.get_option('rsvpmaker_link_template_post'));
if ( empty( $rsvp_options['long_date'] ) || ( strpos( $rsvp_options['long_date'], '%' ) !== false ) ) {
$rsvp_options['long_date'] = 'l F j, Y';
$rsvp_options['short_date'] = 'M j';
$rsvp_options['time_format'] = 'g:i A';
update_option( 'RSVPMAKER_Options', $rsvp_options );
}
if ( isset( $rsvp_options['rsvp_to_current'] ) && $rsvp_options['rsvp_to_current'] && is_user_logged_in() ) {
global $current_user;
$rsvp_options['rsvp_to'] = $current_user->user_email;
}
if ( empty( $rsvp_options['rsvp_form'] ) || isset( $_GET['reset_form'] ) ) {
if ( function_exists( 'do_blocks' ) && ! class_exists( 'Classic_Editor' ) ) {
$form = '<!-- wp:rsvpmaker/formfield {"label":"First Name","slug":"first","guestform":true,"sluglocked":true,"required":"required"} /-->
<!-- wp:rsvpmaker/formfield {"label":"Last Name","slug":"last","guestform":true,"sluglocked":true,"required":"required"} /-->
<!-- wp:rsvpmaker/formfield {"label":"Email","slug":"email","sluglocked":true,"required":"required"} /-->
<!-- wp:rsvpmaker/formfield {"label":"Phone","slug":"phone"} /-->
<!-- wp:rsvpmaker/formselect {"label":"Phone Type","slug":"phone_type","choicearray":["Mobile Phone","Home Phone","Work Phone"]} /-->
<!-- wp:rsvpmaker/guests -->
<div class="wp-block-rsvpmaker-guests"><!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph --></div>
<!-- /wp:rsvpmaker/guests -->
<!-- wp:rsvpmaker/formnote /-->';
} else {
$form = '<p><label>' . __( 'Email', 'rsvpmaker' ) . ':</label> [rsvpfield textfield="email" required="1"]</p>
<p><label>' . __( 'First Name', 'rsvpmaker' ) . ':</label> [rsvpfield textfield="first" required="1"]</p>
<p><label>' . __( 'Last Name', 'rsvpmaker' ) . ':</label> [rsvpfield textfield="last" required="1"]</p>
[rsvpprofiletable show_if_empty="phone"]
<p><label>' . __( 'Phone', 'rsvpmaker' ) . ':</label> [rsvpfield textfield="phone" size="20"]</p>
<p><label>' . __( 'Phone Type', 'rsvpmaker' ) . ':</label> [rsvpfield selectfield="phone_type" options="Work Phone,Mobile Phone,Home Phone"]</p>
[/rsvpprofiletable]
[rsvpguests]
<p>' . __( 'Note', 'rsvpmaker' ) . ':<br />
<textarea name="note" cols="60" rows="2" id="note">[rsvpnote]</textarea></p>';
}
$data['post_title'] = 'Form:Default';
$data['post_content'] = $form;
$data['post_status'] = 'publish';
$data['post_author'] = 1;
$data['post_type'] = 'rsvpmaker';
$rsvp_options['rsvp_form'] = wp_insert_post( $data );
update_post_meta( $rsvp_options['rsvp_form'], '_rsvpmaker_special', 'RSVP Form' );
update_option( 'RSVPMAKER_Options', $rsvp_options );
} elseif ( ! is_numeric( $rsvp_options['rsvp_form'] ) ) {
$data['post_title'] = 'Form:Default';
$data['post_content'] = $rsvp_options['rsvp_form'];
$data['post_status'] = 'publish';
$data['post_type'] = 'rsvpmaker';
$data['post_author'] = 1;
$rsvp_options['rsvp_form'] = wp_insert_post( $data );
update_option( 'RSVPMAKER_Options', $rsvp_options );
}
$rsvp_defaults['rsvp_form'] = $rsvp_options['rsvp_form'];
if ( strpos( $rsvp_options['rsvplink'], '*|EMAIL|*' ) ) {
$rsvp_options['rsvplink'] = str_replace( '?e=*|EMAIL|*#rsvpnow', '', $rsvp_options['rsvplink'] );
update_option( 'RSVPMAKER_Options', $rsvp_options );
}
// if html removed (recover from error with sanitization on settings screen)
if ( ! strpos( $rsvp_options['rsvplink'], '</a>' ) ) {
$rsvp_options['rsvplink'] = '<p><a style="width: 8em; display: block; border: medium inset #FF0000; text-align: center; padding: 3px; background-color: #0000FF; color: #FFFFFF; font-weight: bolder; text-decoration: none;" class="rsvplink" href="%s">' . __( 'RSVP Now!', 'rsvpmaker' ) . '</a></p>';
update_option( 'RSVPMAKER_Options', $rsvp_options );
}
if ( empty( $rsvp_options['rsvp_confirm'] ) ) {
$message = '<!-- wp:paragraph -->
<p>' . __( 'Thank you!', 'rsvpmaker' ) . '</p>
<!-- /wp:paragraph -->';
$rsvp_options['rsvp_confirm'] = wp_insert_post(
array(
'post_title' => 'Confirmation:Default',
'post_content' => $message,
'post_status' => 'publish',
'post_type' => 'rsvpemail',
'post_parent' => 0,
)
);
update_option( 'RSVPMAKER_Options', $rsvp_options );
} elseif ( ! is_numeric( $rsvp_options['rsvp_confirm'] ) ) {
$rsvp_options['rsvp_confirm'] = wp_insert_post(
array(
'post_title' => 'Confirmation:Default',
'post_content' => rsvpautog( $rsvp_options['rsvp_confirm'] ),
'post_status' => 'publish',
'post_type' => 'rsvpemail',
'post_parent' => 0,
)
);
update_option( 'RSVPMAKER_Options', $rsvp_options );
}
}
function rsvpmaker_defaults_for_post( $post_id ) {
global $rsvp_options;
$defaults = array(
'calendar_icons' => '_calendar_icons',
'rsvp_on' => '_rsvp_on',
'rsvp_to' => '_rsvp_to',
'rsvp_confirm' => '_rsvp_confirm',
'rsvpmaker_send_confirmation_email' => '_rsvp_rsvpmaker_send_confirmation_email',
'confirmation_include_event' => '_rsvp_confirmation_include_event',
'rsvp_instructions' => '_rsvp_instructions',
'rsvp_count' => '_rsvp_count',
'rsvp_count_party' => '_rsvp_count_party',
'rsvp_yesno' => '_rsvp_yesno',
'rsvp_max' => '_rsvp_max',
'login_required' => '_rsvp_login_required',
'rsvp_captcha' => '_rsvp_captcha',
'show_attendees' => '_rsvp_show_attendees',
'convert_timezone' => '_convert_timezone',
'add_timezone' => '_add_timezone',
'rsvp_form' => '_rsvp_form',
);
foreach ( $defaults as $index => $label ) {
update_post_meta( $post_id, $label, $rsvp_options[ $index ] );
}
}
function get_rsvpmaker_custom( $post_id ) {
global $rsvp_options;
$defaults = array(
'calendar_icons' => '_calendar_icons',
'rsvp_to' => '_rsvp_to',
'rsvp_confirm' => '_rsvp_confirm',
'rsvpmaker_send_confirmation_email' => '_rsvp_rsvpmaker_send_confirmation_email',
'confirmation_include_event' => '_rsvp_confirmation_include_event',
'rsvp_instructions' => '_rsvp_instructions',
'rsvp_count' => '_rsvp_count',
'rsvp_count_party' => '_rsvp_count_party',
'rsvp_yesno' => '_rsvp_yesno',
'rsvp_max' => '_rsvp_max',
'login_required' => '_rsvp_login_required',
'rsvp_captcha' => '_rsvp_captcha',
'show_attendees' => '_rsvp_show_attendees',
'convert_timezone' => '_convert_timezone',
'add_timezone' => '_add_timezone',
'rsvp_form' => '_rsvp_form',
);
if ( strpos( $_SERVER['REQUEST_URI'], 'post-new.php' ) && ! isset( $_GET['clone'] ) ) {
$custom['_rsvp_on'][0] = $rsvp_options['rsvp_on'];
foreach ( $defaults as $default_key => $custom_key ) {
$custom[ $custom_key ][0] = $rsvp_options[ $default_key ];
}
return $custom;
} else {
$custom = get_post_custom( $post_id );
$custom['_rsvp_on'][0] = ( isset( $custom['_rsvp_on'][0] ) && $custom['_rsvp_on'][0] ) ? 1 : 0;
foreach ( $defaults as $default_key => $custom_key ) {
if ( ! isset( $custom[ $custom_key ][0] ) ) {
$custom[ $custom_key ][0] = $rsvp_options[ $default_key ];
}
}
return $custom;
}
}
rsvpmaker_includes();
function rsvpmaker_includes() {
$plugins_dir = plugin_dir_path( __DIR__ );
$rsvpmaker_dir = trailingslashit(plugin_dir_path( __FILE__ ));
if ( file_exists( $plugins_dir . 'rsvpmaker-custom.php' ) ) {
include_once $plugins_dir . 'rsvpmaker-custom.php';
}
include $rsvpmaker_dir . 'rsvpmaker-util.php';
include $rsvpmaker_dir . 'rsvpmaker-types.php';
include $rsvpmaker_dir . 'rsvpmaker-admin.php';
include $rsvpmaker_dir . 'rsvpmaker-api-endpoints.php';
include $rsvpmaker_dir . 'rsvpmaker-display.php';
include $rsvpmaker_dir . 'rsvpmaker-plugabble.php';
include $rsvpmaker_dir . 'mailchimp-api-master/src/MailChimp.php';
include $rsvpmaker_dir . 'rsvpmaker-email.php';
include $rsvpmaker_dir . 'rsvpmaker-privacy.php';
include $rsvpmaker_dir . 'rsvpmaker-actions.php';
include $rsvpmaker_dir . 'rsvpmaker-form.php';
include $rsvpmaker_dir . 'rsvpmaker-widgets.php';
include $rsvpmaker_dir . 'rsvpmaker-group-email.php';
include $rsvpmaker_dir . 'script.php';
include $rsvpmaker_dir . 'rsvpmaker-money.php';
include $rsvpmaker_dir . 'rsvpmaker-ical.php';
include $rsvpmaker_dir . 'rsvpmaker-postmark.php';
include $rsvpmaker_dir . 'holidays.php';
include $rsvpmaker_dir . '/admin/admin.php';
//include $rsvpmaker_dir . '/upcoming/upcoming.php';
}
$gateways = get_rsvpmaker_payment_options();
if ( in_array( 'Stripe', $gateways ) ) {
require WP_PLUGIN_DIR . '/rsvpmaker/rsvpmaker-stripe.php';
}
if ( in_array( 'PayPal REST API', $gateways ) ) {
require WP_PLUGIN_DIR . '/rsvpmaker/paypal-rest.php';
}
if ( version_compare( PHP_VERSION, '5.3.0' ) >= 0 ) {
include WP_PLUGIN_DIR . '/rsvpmaker/rsvpmaker-recaptcha.php';
}
// make sure new rules will be generated for custom post type - flush for admin but not for regular site visitors
function cpevent_activate() {
global $wpdb, $rsvp_options;
if(!$rsvp_options)
$rsvp_options = rsvp_options_defaults();
//load dbDelta
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$sql = "CREATE TABLE `{$wpdb->prefix}rsvpmaker` (
`id` int NOT NULL auto_increment,
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci default NULL,
`yesno` tinyint(4) NOT NULL default '0',
`first` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default '',
`last` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default '',
`details` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`event` int NOT NULL default '0',
`owed` float(6,2) NOT NULL default '0.00',
`amountpaid` float(6,2) NOT NULL default '0.00',
`fee_total` float(6,2) NOT NULL default '0.00',
`master_rsvp` int NOT NULL default '0',
`guestof` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci default NULL,
`note` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`participants` INT NOT NULL DEFAULT '0',
`user_id` INT NOT NULL DEFAULT '0',
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `{$wpdb->prefix}rsvpmaker_event` (
`event` int NOT NULL default '0',
`post_title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci default NULL,
`display_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci default NULL,
`date` datetime,
`enddate` datetime,
`ts_start` int NOT NULL default '0',
`ts_end` int NOT NULL default '0',
`timezone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci default NULL,
PRIMARY KEY (`event`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `{$wpdb->prefix}rsvp_volunteer_time` (
`id` int NOT NULL auto_increment,
`event` int NOT NULL default '0',
`rsvp` int NOT NULL default '0',
`time` int default '0',
`user_id` int default '0',
`participants` int NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `{$wpdb->prefix}rsvpmailer_blocked` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(100) NOT NULL DEFAULT '',
`code` varchar(50) NOT NULL DEFAULT '',
`timestamp` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
$dbversion = hash('sha256', $sql);
if(!empty($rsvp_options['dbversion']) && ($dbversion == $rsvp_options['dbversion']) )
{
return;
}
$rsvp_options['dbversion'] = $dbversion;
$result = dbDelta($sql);
error_log('rsvpmaker dbDelata '.var_export($result,true));
rsvpmail_problem_init();
$sql = 'SELECT slug FROM ' . $wpdb->prefix . 'terms JOIN `' . $wpdb->prefix . 'term_taxonomy` on ' . $wpdb->prefix . 'term_taxonomy.term_id= ' . $wpdb->prefix . "terms.term_id WHERE taxonomy='rsvpmaker-type' AND slug='featured'";
if ( ! $wpdb->get_var( $sql ) ) {
wp_insert_term(
'Featured', // the term
'rsvpmaker-type', // the taxonomy
array(
'description' => 'Featured event. Can be used to put selected events in a listing, for example on the home page',
'slug' => 'featured',
)
);
}
//update dbversion
update_option( 'RSVPMAKER_Options', $rsvp_options );
}
register_activation_hook( __FILE__, 'cpevent_activate' );
function rsvpmaker_deactivate() {
// Unregister the post type, so the rules are no longer in memory.
unregister_post_type( 'rsvpmaker' );
unregister_post_type( 'rsvpemail' );
// Clear the permalinks to remove our post type's rules from the database.
flush_rewrite_rules();
wp_unschedule_hook( 'rsvp_cleanup_hook' );
wp_unschedule_hook( 'rsvpmaker_relay_init_hook' );
wp_unschedule_hook( 'rsvpmaker_cron_email' );
wp_unschedule_hook( 'rsvpmaker_cron_email_preview' );
wp_unschedule_hook( 'rsvp_daily_reminder_event' );
}
register_deactivation_hook( __FILE__, 'rsvpmaker_deactivate' );
function rsvp_firsttime() {
global $rsvp_options;
if ( $rsvp_options['dbversion'] > 12 ) {
return;
}
$rsvp_options['dbversion'] = 13;
update_option( 'RSVPMAKER_Options', $rsvp_options );
$future = get_future_events();
if ( is_array( $future ) ) {
foreach ( $future as $event ) {
$post_id = $event->ID;
$datetime = get_rsvp_date( $post_id );
$end = get_post_meta( $post_id, '_end' . $datetime, true );
if ( empty( $end ) ) {
$t = rsvpmaker_strtotime( $datetime . ' +1 hour' );
$end = rsvpmaker_date( 'H:i', $t );
}
$duration = get_post_meta( $post_id, '_' . $datetime, true );
update_post_meta( $post_id, '_firsttime', $duration );
update_post_meta( $post_id, '_endfirsttime', $end );
}
}
}
add_filter('single_template_hierarchy','rsvpmaker_single_template_hierarchy');
function rsvpmaker_single_template_hierarchy($templates) {
global $post;
if(isset($post->post_type) && ($post->post_type == 'rsvpmaker'))
{
$index = array_search('single.php',$templates);
if($index) {
// prefer the page template, doesn't emphasize date posted as much in most themes
$templates[$index] = 'page.php';
$templates[] = 'single.php';
}
}
return $templates;
}
function log_paypal( $message ) {
global $post;
$ts = rsvpmaker_date( 'r' );
$invoice = sanitize_text_field($_SESSION['invoice']);
$message .= "\n<br /><br />Post ID: " . $post->ID;
$message .= "\n<br /><br />Invoice: " . $invoice;
$message .= "\n<br />Email: " . sanitize_text_field($_SESSION['payer_email']);
$message .= "\n<br />Time: " . $ts;
add_post_meta( $post->ID, '_paypal_log', $message );
}
if ( ! function_exists( 'rsvpmaker_permalink_query' ) ) {
function rsvpmaker_permalink_query( $id, $query = '' ) {
$key = 'pquery_' . $id;
$p = wp_cache_get( $key );
if ( ! $p ) {
$p = get_permalink( $id );
$p .= strpos( $p, '?' ) ? '&' : '?';
wp_cache_set( $key, $p );
}
if ( is_array( $query ) ) {
foreach ( $query as $name => $value ) {
$qstring .= $name . '=' . $value . '&';
}
} else {
$qstring = $query;
}
return $p . $qstring;
}
} // end function exists
function format_cddate( $year, $month, $day, $hours, $minutes ) {
$month = (int) $month;
if ( $month < 10 ) {
$month = '0' . $month;
}
$day = (int) $day;
if ( $day < 10 ) {
$day = '0' . $day;
}
return $year . '-' . $month . '-' . $day . ' ' . $hours . ':' . $minutes . ':00';
}
function delete_rsvpmaker_date( $post_id, $cddate ) {
delete_post_meta( $post_id, '_rsvp_dates', $cddate );
delete_post_meta( $post_id, '_' . $cddate );
delete_transient( 'rsvpmakerdates' );
}
function add_rsvpmaker_date( $post_id, $cddate, $duration = '', $end_time = '', $index = 0, $timezone = '' ) {
if($end_time && !strpos($end_time,'-')) {
$parts = explode(' ',$cddate);
$end_time = $parts[0].' '.$end_time;
}
add_rsvpmaker_event($post_id,$cddate,$end_time,$duration, $timezone);
}
function update_rsvpmaker_date( $post_id, $cddate, $duration = '', $end_time = '', $index = 0 ) {
rsvpmaker_update_event_field($post_id,'date',$cddate);
if(!strpos($end_time,'-'))
{
$parts = explode(' ',$cddate);
$end_time = $parts[0].' '.$end_time;
}
rsvpmaker_update_event_field($post_id,'enddate',$end_time);
rsvpmaker_update_event_field($post_id,'display_type',$duration);
}
function rsvpmaker_upcoming_data( $atts ) {
global $post;
global $dataloop;
$waspost = $post;
$dataloop = true; // prevent ui output of More Events link
$rsvp_query = rsvpmaker_upcoming_query( $atts );
$events = array();
if ( $rsvp_query->have_posts() ) {
while ( $rsvp_query->have_posts() ) :
$rsvp_query->the_post();
$events[] = $post;
endwhile;
}
wp_reset_postdata();
$post = $waspost;
return $events;
}
function rsvpmaker_duplicate_dates() {
global $wpdb;
$sql = "SELECT $wpdb->posts.ID as postID, $wpdb->posts.*, a1.meta_value as datetime, meta_id
FROM " . $wpdb->posts . '
JOIN ' . $wpdb->postmeta . ' a1 ON ' . $wpdb->posts . ".ID =a1.post_id AND a1.meta_key='_rsvp_dates'
ORDER BY postID, a1.meta_value";
$results = $wpdb->get_results( $sql );
if ( $results ) {
foreach ( $results as $row ) {
$slug = $row->datetime . $row->postID;
$dup = ( empty( $count[ $slug ] ) ) ? false : true;
if ( $dup ) {
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id=" . $row->meta_id );
}
if ( isset( $_GET['clean_duplicate_dates'] ) && isset( $_GET['debug'] ) ) {
printf( '<p>%s<br />%s %s</p>', $row->post_title, $row->datetime, $row->meta_id );
}
$count[ $slug ]++;
}
}
exit();
}
function rsvpmaker_menu_order( $menu_ord ) {
if ( ! $menu_ord || ! is_array( $menu_ord ) ) {
return true;
}
foreach ( $menu_ord as $menu_item ) {
if ( $menu_item == 'edit.php?post_type=page' ) {
$neworder[] = 'edit.php?post_type=page';
$neworder[] = 'edit.php?post_type=rsvpmaker';
$neworder[] = 'edit.php?post_type=rsvpemail';
} elseif ( ( $menu_item == 'edit.php?post_type=rsvpmaker' ) || ( $menu_item == 'edit.php?post_type=rsvpemail' ) ) {
} else {
$neworder[] = $menu_item;
}
}
return $neworder;
}
add_filter( 'custom_menu_order', 'rsvpmaker_menu_order' ); // Activate custom_menu_order
add_filter( 'menu_order', 'rsvpmaker_menu_order' );
function rsvpmaker_sc_after_charge( $charge_response ) {
global $post;
if ( $post->post_type != 'rsvpmaker' ) {
return;
}
$tx_id = $charge_response->id;
$charge = $paid = $charge_response->amount / 100;
if ( ! isset( $_COOKIE[ 'rsvp_for_' . $post->ID ] ) ) {
echo '<p style="color:red;">Error logging payment to RSVP record</p>';
}
$rsvp_id = intval($_COOKIE[ 'rsvp_for_' . $post->ID ]);
global $wpdb;
global $post;
$event = $post->ID;
if ( get_post_meta( $event, '_stripe_' . $tx_id, true ) ) {
echo '<p style="color:red;">Payment already recorded</p>';
return; // if transaction ID recorded, do not duplicate payment
}
$paid_amounts = get_post_meta( $event, '_paid_' . $rsvp_id );
if ( ! empty( $paid_amounts ) ) {
foreach ( $paid_amounts as $payment ) {
$paid += $payment;
}
}
$wpdb->query( 'UPDATE ' . $wpdb->prefix . "rsvpmaker SET amountpaid='$paid' WHERE id=$rsvp_id " );
add_post_meta( $event, '_stripe_' . $tx_id, $charge );
add_post_meta( $event, '_paid_' . $rsvp_id, $charge );
delete_post_meta( $event, '_open_invoice_' . $rsvp_id );
delete_post_meta( $event, '_invoice_' . $rsvp_id );
$row = $wpdb->get_row( 'SELECT * FROM ' . $wpdb->prefix . "rsvpmaker WHERE id=$rsvp_id ", ARRAY_A );
$message = sprintf( '<p>%s ' . __( 'payment for', 'rsvpmaker' ) . ' %s %s ' . __( ' c/o Stripe transaction', 'rsvpmaker' ) . ' %s<br />' . __( 'Post ID', 'rsvpmaker' ) . ': %s<br />' . __( 'Time', 'rsvpmaker' ) . ': %s</p>', esc_html( $charge ), esc_html( $row['first'] ), esc_html( $row['last'] ), esc_html( $tx_id ), esc_html( $event ), date( 'r' ) );
add_post_meta( $event, '_paypal_log', $message );
}
function rsvpmaker_custom_payment( $method, $paid, $rsvp_id, $event, $tx_id = 0 ) {
global $wpdb;
$charge = $paid;
$paid_amounts = get_post_meta( $event, '_paid_' . $rsvp_id );
if ( ! empty( $paid_amounts ) ) {
foreach ( $paid_amounts as $payment ) {
$paid += $payment;
}
}
$wpdb->query( 'UPDATE ' . $wpdb->prefix . "rsvpmaker SET amountpaid='$paid' WHERE id=$rsvp_id " );
add_post_meta( $event, '_' . $method . '_' . $tx_id, $charge );
add_post_meta( $event, '_paid_' . $rsvp_id, $charge );
delete_post_meta( $event, '_open_invoice_' . $rsvp_id );
delete_post_meta( $event, '_invoice_' . $rsvp_id );
$log = sprintf( '%s amount: %s rsvp_id: %s event: %s, tx: %s', $method, $paid, $rsvp_id, $event, $tx_id = 0 );
//rsvpmaker_debug_log( $log );
}
function add_rsvpmaker_roles() {
$rsvpmakereditor = get_role( 'rsvpmakereditor' );
if ( ! $rsvpmakereditor ) {
add_role(
'rsvpmakereditor',
'RSVPMaker Editor',
array(
'read' => true,
'upload_files' => true,
'delete_posts' => true,
'delete_private_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'edit_private_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'delete_others_rsvpmakers' => true,
'delete_rsvpmakers' => true,
'edit_rsvpmakers' => true,
'edit_others_rsvpmakers' => true,
'edit_published_rsvpmakers' => true,
'publish_rsvpmakers' => true,
'read_private_rsvpmakers' => true,
)
);
}