Skip to content

Commit

Permalink
fix(segmentation): handle bad MC API key
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Sep 3, 2024
1 parent 6ea02d3 commit aecc659
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions includes/class-newspack-popups-segmentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,23 @@ public static function reindex_segments( $segments ) {
* @param array $data Data associated with the event.
*/
public static function reader_logged_in( $timestamp, $data ) {
$user_id = $data['user_id'];
$email = $data['email'];

// See newspack-newsletters/includes/class-newspack-newsletters.php:827.
$api_key = \get_option( 'newspack_mailchimp_api_key', false );

if ( ! $api_key ) {
return;
}

$mailchimp = new Mailchimp( $api_key );
$contacts = $mailchimp->get(
try {
$mailchimp = new Mailchimp( $api_key );
} catch ( \Exception $th ) {
return;
}

$user_id = $data['user_id'];
$email = $data['email'];

$contacts = $mailchimp->get(
'search-members',
[
'fields' => [ 'members.email_address', 'members.merge_fields' ],
Expand Down

0 comments on commit aecc659

Please sign in to comment.