Fix Brevo list_modules pagination to return all lists#192
Merged
Conversation
davidperezgar
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The fc_crm_module dropdown in Contact Form 7 (and other form plugins) only displayed 10 lists from Brevo, even though the account had 87 lists. The API response showed count: 87, confirming all lists existed but weren't being fetched.
Root Cause
The api() method in CRMLIB_Brevo had three chained bugs in its GET pagination logic:
Missing URL parameters: Query string params ?limit=N&offset=N were commented out, so every API request hit the same endpoint without pagination parameters. Brevo defaults to 10 items when no limit is specified.
Loop never repeats: The repeat_query condition compared count($result['data']) (which was 10) against a hardcoded $limit of 100, causing the loop to exit after one iteration.
Broken data accumulation: The method tried to merge entire response envelopes ({lists: [...], count: 87}) instead of just the nested items array, then list_modules() looked for ['data']['lists'] in a structure that no longer had that nesting.
Solution
Modified /includes/crm-library/class-crmlib-brevo.php:
In api() GET block:
Append ?limit=50&offset=N to the URL for each request
Extract nested items ($result['data']['lists']) from the response, or fall back to $result['data'] if not nested
Accumulate only items (not envelopes) in $result_data
Use $offset < $total to control pagination loop continuation
In list_modules():
Read $result_lists['data'] directly as a flat array (changed from $result_lists['data']['lists'])
Impact
✅ Dropdown now displays all 87 lists instead of 10
✅ Backwards compatible: Other Brevo endpoints like contacts/attributes continue working because the extraction logic safely detects nested vs flat responses
✅ Pagination now works for any endpoint with paginated results
Testing
Open Contact Form 7 with Brevo connected
Navigate to CRM settings
Verify CRM Module dropdown shows all 87 lists (scroll through dropdown)
Verify field mapping still works (check that custom fields load correctly)