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

Bug/double opt in triggered despite being disabled in settings #115

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

MaxwellGarceau
Copy link
Collaborator

@MaxwellGarceau MaxwellGarceau commented Jan 9, 2025

Description of the Change

This PR bundles a two related issues.

Closes #113
Closes #114

How to test the Change

Double Opt-In triggered despite being disabled in settings

double-opt-in-triggered-despite-being-disabled-testing.mp4
  1. Ensure that Double Opt-In is disabled in the Mailchimp WP settings page
  2. Navigate to the FE and submit a new form submission with an email address you control (e.g. max.garceau+newsubmission@10up.com)
  3. Check your email and ensure that you haven't received an email
  4. Check your Mailchimp account to ensure the contact has been created
If Double Opt-In is enabled and a pending user tries to update their information, then their status will still be pending and they will have to confirm the original confirmation email (bug fix/logic change)

Previously, the conditional check was attempting to skip Double Opt-in for any emails with an existing status.

double-opt-in-enabled-with-pending-user.mp4
  1. Turn on Double Opt-In in the Mailchimp WP settings
  2. Turn on "Update Existing Subscribers?" in the Mailchimp WP settings
  3. Sign up with a new subscriber
  4. DO NOT CONFIRM THE EMAIL
  5. Check your Mailchimp account to confirm that the contact has not been created
  6. Sign up and change some information with that same email
  7. You WILL NOT receive another confirmation email. Confirm the original confirmation email.
  8. Verify that the new contact is created in the Mailchimp account with the changes you've entered

Fix: Existing subscriber could sign up even if "Update Existing Subscriber?" is turned off

update-existing-subscriber-is-off-should-prevent-subscriber-from-signing-up-multiple-times.mp4
  1. Turn "Update Existing Subscriber?" off in the Mailchimp WP settings
  2. Sign up with a new subscriber on the FE submission form
  3. Sign up a second time
  4. You should receive an error stating "This email address has already been subscribed to this list"
If "Update Existing Subscriber?" is disabled and the email does not belong to a new subscriber then don't let them sign up (changed logic)

Previously, the conditional check would only check for subscribed emails to throw an error. Now, any existing email type will throw the error.

existing-emails-can-not-signup-if-update-existing-subscribers-is-not-enabled.mp4
  1. Turn "Update Existing Subscriber?" off in the Mailchimp WP settings
  2. subscribed - Sign up with an already subscribed email on the FE submission form. You should see "This email address has already been subscribed to this list."
  3. unsubscribed - Sign up with an email that has been unsubscribed from this list. You should see "This email address has already been subscribed to this list."
  4. Enable Double Opt-In
  5. Sign up with a new email
  6. DO NOT CONFIRM THE EMAIL
  7. pending - Try signing up again with the email. You should see "This email address has already been subscribed to this list."

Other statuses include cleaned, transactional, and archived, but I don't think we need to worry about testing those.

Changelog Entry

Fixed - Fix bug causing all new subscribers to receive a double opt-in email
Fixed - Fix bug causing any contact with a Mailchimp status (subscribed, unsubscribed, pending, etc) to be able to submit the sign up form even if "Update Existing Subscriber?" was disabled
Fixed - Pending contacts will now still be required to confirm their original confirmation email if they try to update their contact while "Update Existing Subscribers?" is enabled and "Double Opt-in" is enabled

Credits

Props Nathan Tetzlaff, @MaxwellGarceau, pluckvermont.

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Remove the user status from double opt-in since it's not clear that logic affects why a user should receive a confirmation email or not
…sting user check

get_option( 'mc_update_existing' ) returns '1' or '', but never false
@github-actions github-actions bot added this to the 1.7.0 milestone Jan 9, 2025
Comment on lines +907 to +910
// If update existing is turned off and the subscriber is not new, error out.
$is_new_subscriber = false === $status;
if ( ! get_option( 'mc_update_existing' ) && ! $is_new_subscriber ) {
$msg = esc_html__( 'This email address has already been subscribed to this list.', 'mailchimp' );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‼️ ‼️ I changed the functionality slightly here according to my interpretation of the use case.

If "Update Existing Subscriber?" is disabled and the email does not belong to a new subscriber then don't let them sign up.

The previously functionality only checked for emails with a subscribed status. This missed unsubscribed, pending, and the other possible Mailchimp statuses.

‼️ Question: Do we want to update unsubscribed and pending users as well? If we don't update unsubscribed users then it will be functionally impossible for any user to resubscribe once unsubscribed. This directly relates to #93.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we'll want to allow other statuses to work here besides just subscribed. As a user, I think I'd consider it a bug if someone that has unsubscribed can't resubscribe if that setting is on. The way I think this should work is if someone is subscribed or is in a pending state (I would assume that means they subscribed but haven't verified that yet), we shouldn't allow them to resubscribe if this option is enabled. But if they have never subscribed or if they have unsubscribed, they should be allowed to subscribe

Copy link
Collaborator Author

@MaxwellGarceau MaxwellGarceau Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I think this should work is if someone is subscribed or is in a pending state, we shouldn't allow them to resubscribe if this option is enabled mc_update_existing

I 100% agree with you.

  • In the case of subscribed, the sign up request will update the existing contact instead of creating a duplicate.
  • In the case of pending (subscribed, but haven't verified), their information will also be updated. However, the user must still confirm the email before the contact is created. The exception to this is if single opt-in has been enabled then the pending contact will be created immediately without needing to verify the original email.

[If mc_update_existing is enabled or disabled] But if they have never subscribed they should be allowed to subscribe

Yes! Current functionality.

[If mc_update_existing is disabled] If they have unsubscribed they should be allowed to subscribe

I agree as well. The current Mailchimp functionality is that contacts can not be resubscribed through the API. However, there's a solution in #117 to still address this scenario.

I added a comment directly after "Update Existing Subscriber?" check to make an API request for the native Mailchimp sign up form if the contact has a status of unsubscribed and "Update Existing Subscriber?" is enabled.

wordpress/mailchimp.php

Lines 916 to 917 in 8e1e3f4

// TODO: If get_option( 'mc_update_existing' ) && 'unsubscribed' === $status then
// make an API request to fetch Mailchimp hosted sign up form and display to user

@MaxwellGarceau MaxwellGarceau marked this pull request as ready for review January 9, 2025 04:08
@github-actions github-actions bot added the needs:code-review This requires code review. label Jan 9, 2025
@MaxwellGarceau MaxwellGarceau requested a review from dkotter January 9, 2025 04:08
@MaxwellGarceau
Copy link
Collaborator Author

Some of the logic around setting a subscribers status as well as what type of subscribers should be allowed to update their contact info in Mailchimp are a bit hard to remember. I think those would be good candidates for unit tests. What does everyone else think?

@dkotter
Copy link
Collaborator

dkotter commented Jan 9, 2025

I think those would be good candidates for unit tests. What does everyone else think?

I'm fine with adding unit tests here

@MaxwellGarceau
Copy link
Collaborator Author

Update on the unit tests. I've been prioritizing wrapping up other in progress tickets. The unit tests may not be ready before I move onto another project next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-review This requires code review.
Projects
None yet
2 participants