Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show an error message and return early if no list is chosen #40

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,16 @@ 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 ( ! isset( $_POST['mc_list_id'] ) ) {
dkotter marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if ( empty( $_POST['mc_list_id'] ) ) {
$msg = '<p class="error_msg">' . esc_html__( 'Please choose a valid list', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
return;
}

// Simple permission check before going through all this
if ( ! current_user_can( MCSF_CAP_THRESHOLD ) ) { return; }

Expand All @@ -649,7 +659,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)
Expand Down
6 changes: 3 additions & 3 deletions views/setup_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<p class="mc-p"><?php esc_html_e( 'Please select the Mailchimp list you\'d like to connect to your form.', 'mailchimp_i18n' ); ?></p>
<p class="mc-list-note"><strong><?php esc_html_e( 'Note:', 'mailchimp_i18n' ); ?></strong> <?php esc_html_e( 'Updating your list will not remove list settings in this plugin, but changing lists will.', 'mailchimp_i18n' ); ?></p>

<form method="post" action="options-general.php?page=mailchimp_sf_options">
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'page' => 'mailchimp_sf_options' ), admin_url( 'admin.php' ) ) ); ?>">
dkotter marked this conversation as resolved.
Show resolved Hide resolved
<?php
// we *could* support paging, but few users have that many lists (and shouldn't)
$lists = $api->get( 'lists', 100, array( 'fields' => 'lists.id,lists.name,lists.email_type_option' ) );
Expand Down Expand Up @@ -179,7 +179,7 @@
?>

<p class="submit">
<form method="post" action="options-general.php?page=mailchimp_sf_options">
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'page' => 'mailchimp_sf_options' ), admin_url( 'admin.php' ) ) ); ?>">
<input type="hidden" name="mcsf_action" value="reset_list" />
<input type="submit" name="reset_list" value="<?php esc_attr_e( 'Reset List Options and Select again', 'mailchimp_i18n' ); ?>" class="button" />
<?php wp_nonce_field( 'reset_mailchimp_list', '_mcsf_nonce_action' ); ?>
Expand All @@ -200,7 +200,7 @@
?>

<div>
<form method="post" action="options-general.php?page=mailchimp_sf_options">
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'page' => 'mailchimp_sf_options' ), admin_url( 'admin.php' ) ) ); ?>">
<div class="mc-section">
<input type="hidden" name="mcsf_action" value="change_form_settings">
<?php wp_nonce_field( 'update_general_form_settings', '_mcsf_nonce_action' ); ?>
Expand Down
Loading