Skip to content

Commit

Permalink
Merge pull request #1347 from rocklobster-in/dev/5.8
Browse files Browse the repository at this point in the history
Brevo: Allow to retrieve more contact lists
  • Loading branch information
takayukister committed Jan 8, 2024
2 parents 9a59b72 + 0213a0a commit 078cba7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
38 changes: 37 additions & 1 deletion modules/sendinblue/contact-form-properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function wpcf7_sendinblue_editor_panels( $panels ) {
)
);

$lists = $service->get_lists();
$lists = wpcf7_sendinblue_get_lists();
$templates = $service->get_templates();

?>
Expand Down Expand Up @@ -301,3 +301,39 @@ function wpcf7_sendinblue_editor_panels( $panels ) {

return $panels;
}


/**
* Retrieves contact lists from Brevo's database.
*/
function wpcf7_sendinblue_get_lists() {
static $lists = array();

$service = WPCF7_Sendinblue::get_instance();

if ( ! empty( $lists ) or ! $service->is_active() ) {
return $lists;
}

$limit = 50;
$offset = 0;

while ( count( $lists ) < $limit * 10 ) {
$lists_next = (array) $service->get_lists( array(
'limit' => $limit,
'offset' => $offset,
) );

if ( ! empty( $lists_next ) ) {
$lists = array_merge( $lists, $lists_next );
}

if ( count( $lists_next ) < $limit ) {
break;
}

$offset += $limit;
}

return $lists;
}
12 changes: 7 additions & 5 deletions modules/sendinblue/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ public function confirm_key() {
}


public function get_lists() {
public function get_lists( $options = '' ) {
$options = wp_parse_args( $options, array(
'limit' => 50,
'offset' => 0,
) );

$endpoint = add_query_arg(
array(
'limit' => 50,
'offset' => 0,
),
$options,
'https://api.sendinblue.com/v3/contacts/lists'
);

Expand Down

0 comments on commit 078cba7

Please sign in to comment.