Skip to content

Commit

Permalink
fix: send content to mailchimp immediately before sending campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonrabb committed Apr 15, 2020
1 parent 33fc00a commit 0d0bb5a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion includes/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ public static function send_campaign( $id, $post ) {
);
}


$mc_campaign_id = get_post_meta( $id, 'mc_campaign_id', true );
if ( ! $mc_campaign_id ) {
return new WP_Error(
Expand All @@ -556,6 +555,24 @@ public static function send_campaign( $id, $post ) {

$mc = new Mailchimp( self::mailchimp_api_key() );

$payload = [
'type' => 'regular',
'content_type' => 'template',
'settings' => [
'subject_line' => $post->post_title,
'title' => $post->post_title,
],
];

$mc->patch( "campaigns/$mc_campaign_id", $payload );

$renderer = new Newspack_Newsletters_Renderer();
$content_payload = [
'html' => $renderer->render_html_email( $post ),
];

$mc->put( "campaigns/$mc_campaign_id/content", $content_payload );

$payload = [
'send_type' => 'html',
];
Expand Down

0 comments on commit 0d0bb5a

Please sign in to comment.