Skip to content

Commit

Permalink
fix: when trashing post allow mailchimp api call to fail silently
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson Rabb authored May 11, 2020
2 parents eb100b8 + 8257451 commit 7e2d9c4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions includes/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,15 +796,22 @@ public static function trash_post( $id ) {
return;
}

$api_key = self::mailchimp_api_key();
$mc = new Mailchimp( $api_key );
$campaign = $mc->get( "campaigns/$mc_campaign_id" );
if ( $campaign ) {
$status = $campaign['status'];
if ( ! in_array( $status, [ 'sent', 'sending' ] ) ) {
$result = $mc->delete( "campaigns/$mc_campaign_id" );
delete_post_meta( $id, 'mc_campaign_id', $mc_campaign_id );
$api_key = self::mailchimp_api_key();
if ( ! $api_key ) {
return;
}
try {
$mc = new Mailchimp( $api_key );
$campaign = $mc->get( "campaigns/$mc_campaign_id" );
if ( $campaign ) {
$status = $campaign['status'];
if ( ! in_array( $status, [ 'sent', 'sending' ] ) ) {
$result = $mc->delete( "campaigns/$mc_campaign_id" );
delete_post_meta( $id, 'mc_campaign_id', $mc_campaign_id );
}
}
} catch ( Exception $e ) {
return; // Fail silently.
}
}

Expand Down

0 comments on commit 7e2d9c4

Please sign in to comment.