From 07341014325764757fc30829fd4e92f21e8cbf46 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Fri, 28 Jun 2024 10:02:52 -0600 Subject: [PATCH 1/5] Show an error message and return early if no list is chosen --- mailchimp.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mailchimp.php b/mailchimp.php index 4dba8f7..dad2713 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -634,6 +634,12 @@ function mailchimp_sf_save_general_form_settings() { * Sees if the user changed the list, and updates options accordingly **/ function mailchimp_sf_change_list_if_necessary() { + if ( empty( $_POST['mc_list_id'] ) ) { + $msg = '

' . esc_html( __( 'Please choose a valid list', 'mailchimp_i18n' ) ) . '

'; + mailchimp_sf_global_msg( $msg ); + return; + } + // Simple permission check before going through all this if ( ! current_user_can( MCSF_CAP_THRESHOLD ) ) { return; } @@ -649,7 +655,7 @@ function mailchimp_sf_change_list_if_necessary() { $lists = $lists['lists']; - if ( is_array( $lists ) && ! empty( $lists ) && isset( $_POST['mc_list_id'] ) ) { + if ( is_array( $lists ) && ! empty( $lists ) ) { /** * If our incoming list ID (the one chosen in the select dropdown) From 05b34b570e9a31defe3b225bb4ba2abeb78aeb26 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Fri, 28 Jun 2024 10:06:27 -0600 Subject: [PATCH 2/5] Simplify code a bit --- mailchimp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailchimp.php b/mailchimp.php index dad2713..cd188c2 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -635,7 +635,7 @@ function mailchimp_sf_save_general_form_settings() { **/ function mailchimp_sf_change_list_if_necessary() { if ( empty( $_POST['mc_list_id'] ) ) { - $msg = '

' . esc_html( __( 'Please choose a valid list', 'mailchimp_i18n' ) ) . '

'; + $msg = '

' . esc_html__( 'Please choose a valid list', 'mailchimp' ) . '

'; mailchimp_sf_global_msg( $msg ); return; } From 8c0152f6d899d671c0fe8216ec2071679c019dec Mon Sep 17 00:00:00 2001 From: Nate Conley Date: Fri, 28 Jun 2024 08:10:31 -1000 Subject: [PATCH 3/5] Update settings form URL --- views/setup_page.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/views/setup_page.php b/views/setup_page.php index 5da18ff..3acfae1 100644 --- a/views/setup_page.php +++ b/views/setup_page.php @@ -124,7 +124,7 @@

-
+ get( 'lists', 100, array( 'fields' => 'lists.id,lists.name,lists.email_type_option' ) ); @@ -179,7 +179,7 @@ ?>

- + @@ -200,7 +200,7 @@ ?>

- +
From 3619ac5182acc990cd780816760834f8bbafb0bb Mon Sep 17 00:00:00 2001 From: Nate Conley Date: Fri, 28 Jun 2024 08:10:46 -1000 Subject: [PATCH 4/5] Check that list data is sent --- mailchimp.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mailchimp.php b/mailchimp.php index cd188c2..a28cc47 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -634,7 +634,11 @@ function mailchimp_sf_save_general_form_settings() { * Sees if the user changed the list, and updates options accordingly **/ function mailchimp_sf_change_list_if_necessary() { - if ( empty( $_POST['mc_list_id'] ) ) { + if ( ! isset( $_POST['mc_list_id'] ) ) { + return; + } + + if ( isset( $_POST['mc_list_id'] ) && empty( $_POST['mc_list_id'] ) ) { $msg = '

' . esc_html__( 'Please choose a valid list', 'mailchimp' ) . '

'; mailchimp_sf_global_msg( $msg ); return; From 06b96e50cc871d1264c22a94fe0bdba6fd44fdd2 Mon Sep 17 00:00:00 2001 From: Nate Conley Date: Fri, 28 Jun 2024 08:45:03 -1000 Subject: [PATCH 5/5] Removes redundant check --- mailchimp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailchimp.php b/mailchimp.php index a28cc47..dd22d17 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -638,7 +638,7 @@ function mailchimp_sf_change_list_if_necessary() { return; } - if ( isset( $_POST['mc_list_id'] ) && empty( $_POST['mc_list_id'] ) ) { + if ( empty( $_POST['mc_list_id'] ) ) { $msg = '

' . esc_html__( 'Please choose a valid list', 'mailchimp' ) . '

'; mailchimp_sf_global_msg( $msg ); return;