Skip to content

Add mailchimp_sf_list_limit filter to allow modifying the list limit.#210

Open
iamdharmesh wants to merge 5 commits intodevelopfrom
fix/186
Open

Add mailchimp_sf_list_limit filter to allow modifying the list limit.#210
iamdharmesh wants to merge 5 commits intodevelopfrom
fix/186

Conversation

@iamdharmesh
Copy link
Copy Markdown
Collaborator

Description of the Change

This pull request refactors how Mailchimp lists are fetched throughout the codebase by introducing a new helper function, mailchimp_sf_get_lists(). This change centralizes the logic for retrieving lists, making it easier to maintain and allowing for customization of the fetch limit via a filter. The update replaces direct API calls in several locations with the new helper function.

Centralization and Reusability:

  • Added a new function, mailchimp_sf_get_lists(), in mailchimp.php to encapsulate the logic for fetching Mailchimp lists, including support for customizing the fetch limit through the mailchimp_sf_list_limit filter.

Codebase Refactoring:

  • Replaced direct API calls to $api->get('lists', ...) with calls to the new mailchimp_sf_get_lists() function in the following places:
    • includes/admin/templates/settings.php
    • includes/blocks/class-mailchimp-list-subscribe-form-blocks.php (get_lists method)
    • includes/class-mailchimp-admin.php (verify_and_save_oauth_token method)
    • mailchimp.php (mailchimp_sf_change_list_if_necessary function)

Closes #186

How to test the Change

  1. Connect a Mailchimp account with more than one list.
  2. Add the following code snippet to the theme’s functions.php file:
// For testing purposes, set the limit to 1.
add_filter( 'mailchimp_sf_list_limit', function( $limit ) {
    return 1;
} );
  1. Check the list dropdown on the settings page and ensure that only one list is displayed.
  2. Perform overall smoke testing.

Changelog Entry

Added - The mailchimp_sf_list_limit filter to allow modifying the list limit.

Credits

Props @jonjennings @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 6, 2026
@iamdharmesh iamdharmesh requested a review from Copilot May 6, 2026 06:49
@github-actions github-actions Bot added this to the 2.1.0 milestone May 6, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes Mailchimp list retrieval behind a new mailchimp_sf_get_lists() helper and introduces a mailchimp_sf_list_limit filter so integrators can adjust how many lists are fetched, replacing several direct $api->get( 'lists', ... ) calls across admin UI, blocks, and token verification.

Changes:

  • Added mailchimp_sf_get_lists() in mailchimp.php, including the mailchimp_sf_list_limit filter.
  • Replaced direct Mailchimp API list-fetch calls with mailchimp_sf_get_lists() in admin settings, block list loading, OAuth token verification, and list-change handling.
  • Removed old inline comments around the hard-coded 100-list limit in multiple locations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
mailchimp.php Adds mailchimp_sf_get_lists() + filter, and refactors list-change logic to use the helper.
includes/class-mailchimp-admin.php Uses the helper when validating/refreshing saved list data during OAuth token verification.
includes/blocks/class-mailchimp-list-subscribe-form-blocks.php Uses the helper when populating block list data (and caching it to options).
includes/admin/templates/settings.php Uses the helper to populate the settings-page list dropdown.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mailchimp.php Outdated
Comment thread mailchimp.php Outdated
Comment thread mailchimp.php Outdated
Comment thread mailchimp.php
Comment thread mailchimp.php
Comment thread includes/blocks/class-mailchimp-list-subscribe-form-blocks.php Outdated
Comment thread includes/admin/templates/settings.php
@iamdharmesh iamdharmesh requested a review from alaca May 6, 2026 07:13
@iamdharmesh iamdharmesh marked this pull request as ready for review May 6, 2026 07:14
@github-actions github-actions Bot added the needs:code-review This requires code review. label May 6, 2026
@iamdharmesh iamdharmesh mentioned this pull request May 6, 2026
4 tasks
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.

Plugin limited to 100 lists

2 participants