@@ -404,7 +404,7 @@ protected function register_fields_general() {
404
404
$ cmb ->add_field ( [
405
405
'name ' => esc_html__ ( 'Add subscribers to ' , 'constant-contact-forms ' ),
406
406
'id ' => '_ctct_optin_list ' ,
407
- 'type ' => 'select ' ,
407
+ 'type ' => 'multicheck ' ,
408
408
'show_option_none ' => false ,
409
409
'default ' => esc_html__ ( 'Select a list ' , 'constant-contact-forms ' ),
410
410
'options ' => $ lists ,
@@ -692,14 +692,19 @@ public function optin_form_field() {
692
692
}
693
693
694
694
$ saved_label = constant_contact_get_option ( '_ctct_optin_label ' , '' );
695
- $ list = constant_contact_get_option ( '_ctct_optin_list ' , '' );
695
+
696
+ $ lists = $ this ->get_optin_list_options ();
696
697
$ label = $ saved_label ?: esc_html__ ( 'Sign up to our newsletter. ' , 'constant-contact-forms ' );
698
+
697
699
?>
698
700
<p class="ctct-optin-wrapper" style="padding: 0 0 1em 0;">
699
- <label for="ctct_optin">
700
- <input type="checkbox" value="<?php echo esc_attr ( $ list ); ?> " class="checkbox" id="ctct_optin" name="ctct_optin_list" />
701
- <?php echo esc_attr ( $ label ); ?>
702
- </label>
701
+ <p><?php echo esc_attr ( $ label ); ?> </p>
702
+ <?php foreach ( $ lists as $ key => $ list ) { ?>
703
+ <label for="ctct_optin_<?php echo esc_attr ( $ key ); ?> ">
704
+ <input type="checkbox" value="<?php echo esc_attr ( $ key ); ?> " class="checkbox" id="ctct_optin_<?php echo esc_attr ( $ key ); ?> " name="ctct_optin_list[]" /> <?php echo esc_attr ( $ list ); ?>
705
+ </label>
706
+ <br/>
707
+ <?php } ?>
703
708
<?php echo wp_kses_post ( constant_contact ()->display ->get_disclose_text () ); ?>
704
709
</p>
705
710
<?php
@@ -715,9 +720,9 @@ public function optin_form_field() {
715
720
* @return array Comment form data.
716
721
*/
717
722
public function process_optin_comment_form ( $ comment_data ) {
718
- $ ctct_optin_list = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING );
723
+ $ ctct_optin_lists = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING , FILTER_REQUIRE_ARRAY );
719
724
720
- if ( empty ( $ ctct_optin_list ) ) {
725
+ if ( empty ( $ ctct_optin_lists ) ) {
721
726
return $ comment_data ;
722
727
}
723
728
@@ -738,21 +743,23 @@ public function process_comment_data_for_optin( $comment_data ) {
738
743
739
744
$ name = isset ( $ comment_data ['comment_author ' ] ) ? $ comment_data ['comment_author ' ] : '' ;
740
745
$ website = isset ( $ comment_data ['comment_author_url ' ] ) ? $ comment_data ['comment_author_url ' ] : '' ;
741
- $ list = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING );
746
+ $ lists = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING , FILTER_REQUIRE_ARRAY );
742
747
743
- if ( empty ( $ list ) ) {
748
+ if ( empty ( $ lists ) ) {
744
749
return $ comment_data ;
745
750
}
746
751
747
- $ args = [
748
- 'list ' => sanitize_text_field ( wp_unslash ( $ list ) ),
749
- 'email ' => sanitize_email ( $ comment_data ['comment_author_email ' ] ),
750
- 'first_name ' => sanitize_text_field ( $ name ),
751
- 'last_name ' => '' ,
752
- 'website ' => sanitize_text_field ( $ website ),
753
- ];
752
+ foreach ( $ lists as $ list ) {
753
+ $ args = [
754
+ 'list ' => sanitize_text_field ( wp_unslash ( $ list ) ),
755
+ 'email ' => sanitize_email ( $ comment_data ['comment_author_email ' ] ),
756
+ 'first_name ' => sanitize_text_field ( $ name ),
757
+ 'last_name ' => '' ,
758
+ 'website ' => sanitize_text_field ( $ website ),
759
+ ];
760
+ constantcontact_api ()->add_contact ( $ args );
761
+ }
754
762
755
- constantcontact_api ()->add_contact ( $ args );
756
763
}
757
764
758
765
return $ comment_data ;
@@ -769,9 +776,9 @@ public function process_comment_data_for_optin( $comment_data ) {
769
776
* @return object|array CTCT return API for contact or original $user array.
770
777
*/
771
778
public function process_optin_login_form ( $ user , $ username , $ password ) {
772
- $ ctct_optin_list = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING );
779
+ $ ctct_optin_lists = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING , FILTER_REQUIRE_ARRAY );
773
780
774
- if ( empty ( $ ctct_optin_list ) ) {
781
+ if ( empty ( $ ctct_optin_lists ) ) {
775
782
return $ user ;
776
783
}
777
784
@@ -793,7 +800,9 @@ public function process_optin_login_form( $user, $username, $password ) {
793
800
*/
794
801
public function process_optin_register_form ( $ user_id ) {
795
802
796
- if ( ! isset ( $ _POST ['ctct_optin_list ' ] ) ) {
803
+ $ ctct_optin_lists = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING , FILTER_REQUIRE_ARRAY );
804
+
805
+ if ( empty ( $ ctct_optin_lists ) ) {
797
806
return $ user_id ;
798
807
}
799
808
@@ -842,21 +851,22 @@ private function add_user_to_list( $user ) {
842
851
return ;
843
852
}
844
853
845
- $ list = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING );
854
+ $ lists = filter_input ( INPUT_POST , 'ctct_optin_list ' , FILTER_SANITIZE_STRING , FILTER_REQUIRE_ARRAY );
846
855
847
- if ( empty ( $ list ) ) {
856
+ if ( empty ( $ lists ) ) {
848
857
return ;
849
858
}
850
859
851
860
if ( $ email ) {
852
- $ args = [
853
- 'email ' => $ email ,
854
- 'list ' => sanitize_text_field ( wp_unslash ( $ list ) ),
855
- 'first_name ' => $ name ,
856
- 'last_name ' => '' ,
857
- ];
858
-
859
- constantcontact_api ()->add_contact ( $ args );
861
+ foreach ( $ lists as $ list ) {
862
+ $ args = [
863
+ 'email ' => $ email ,
864
+ 'list ' => sanitize_text_field ( wp_unslash ( $ list ) ),
865
+ 'first_name ' => $ name ,
866
+ 'last_name ' => '' ,
867
+ ];
868
+ constantcontact_api ()->add_contact ( $ args );
869
+ }
860
870
}
861
871
862
872
}
@@ -1061,6 +1071,33 @@ public function sanitize_recaptcha_api_key_string( $value, $field_args, $field )
1061
1071
private function get_default_spam_error () {
1062
1072
return __ ( 'We do not think you are human ' , 'constant-contact-forms ' );
1063
1073
}
1074
+
1075
+ /**
1076
+ * Returns formated list of available lists during opt-in.
1077
+ *
1078
+ * @author Scott Anderson <scott.anderson@webdevstudios.com>
1079
+ * @since NEXT
1080
+ *
1081
+ * @return array
1082
+ */
1083
+ private function get_optin_list_options () {
1084
+ $ lists = constant_contact_get_option ( '_ctct_optin_list ' , '' );
1085
+
1086
+ $ formatted_lists = [];
1087
+ foreach ( $ lists as $ list_id ) {
1088
+
1089
+ $ list_args = array (
1090
+ 'numberposts ' => 1 ,
1091
+ 'post_type ' => 'ctct_lists ' ,
1092
+ 'meta_key ' => '_ctct_list_id ' ,
1093
+ 'meta_value ' => $ list_id
1094
+ );
1095
+ $ list = get_posts ( $ list_args );
1096
+
1097
+ $ formatted_lists [ $ list_id ] = $ list [0 ]->post_title ;
1098
+ }
1099
+ return $ formatted_lists ;
1100
+ }
1064
1101
}
1065
1102
1066
1103
/**
0 commit comments