Skip to content

Add user synchronization #156

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

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

Add user synchronization #156

wants to merge 19 commits into from

Conversation

iamdharmesh
Copy link
Collaborator

@iamdharmesh iamdharmesh commented May 14, 2025

Description of the Change

This PR adds functionality to sync WordPress users to Mailchimp. It provides options to select user roles to sync and to choose the subscription status for users in the user sync settings.

The feature allows manual syncing of all users at once using background processing and also listens for new user registrations and updates to existing users. Currently, the sync is one-way (WordPress → Mailchimp). The feature also includes a UI to view users that failed to sync, along with the associated error messages. I have created #157, to handle update subscription status from user profile separately.

screencapture-mailchimp-local-wp-admin-admin-php-2025-05-15-15_23_15

Quick Demo:

Screen.Recording.2025-05-15.at.3.46.56.PM.mov

Closes #155

How to test the Change

Prerequisites:

  • Connect your Mailchimp account and select a list.
  • Create some users in WordPress to test user synchronization.
  1. Go to Mailchimp > Settings > User Sync tab. You will see a "Start Sync" CTA.

Manual Sync:

  1. Save the user sync settings (select appropriate user roles and subscriber status).
  2. Click on "Synchronize All Users" and verify that the sync process starts.
  3. Confirm that the total user count is displayed correctly based on the selected roles.
  4. Once the sync is complete, verify from the Mailchimp dashboard that users are synced correctly (with correct status).
  5. Enable "Sync Existing Contacts Only" and run the sync.
  6. Verify that only existing Mailchimp contacts are synced.
  7. Test the sync with a large number of users and confirm the process completes without issues.
  8. Add a user with a non-valid email (e.g., example.com or test.com) and run the sync.
  9. Confirm that the sync fails for that user, the error appears below the user sync settings, and you can delete the error entry if needed.

Auto Sync:

  1. Enable "Enable Auto User Sync".
  2. Create a new user and verify it is synced properly with Mailchimp.
  3. Update an existing user and confirm the changes are synced correctly to Mailchimp.

Changelog Entry

Added - Added user synchronization to allow syncing WordPress users to Mailchimp.

Credits

Props @dkotter @jeffpaul @iamdharmesh

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.

@iamdharmesh iamdharmesh self-assigned this May 14, 2025
@github-actions github-actions bot added this to the 1.9.0 milestone May 14, 2025
@iamdharmesh iamdharmesh changed the title [WIP] Add user synchronization Add user synchronization May 15, 2025
Comment on lines +277 to +297
if ( $current_status ) {
switch ( $current_status ) {
// If user is already subscribed, unsubscribed or transactional, don't change the status.
case 'subscribed':
case 'unsubscribed':
case 'transactional':
$subscribe_status = $current_status;
break;

// If user is cleaned, set the status as pending.
case 'cleaned':
$subscribe_status = 'pending';
break;

// If user is archived, pending or anything else, set the status as per the subscribe status in settings.
case 'archived':
case 'pending':
default:
break;
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For existing Mailchimp contacts, we mostly don't update the status according to the settings on the WP side. However, for statuses like cleaned, archived, and pending, we do consider updating them based on the user sync settings.

Please let me know if you think we should handle this differently. Thanks!

@iamdharmesh iamdharmesh requested a review from dkotter May 15, 2025 14:30
@iamdharmesh iamdharmesh marked this pull request as ready for review May 15, 2025 14:30
@github-actions github-actions bot added the needs:code-review This requires code review. label May 15, 2025
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
Development

Successfully merging this pull request may close these issues.

Add user synchronization feature
1 participant