Skip to content

Commit

Permalink
chore(release): merge in release v1.46.1
Browse files Browse the repository at this point in the history
  • Loading branch information
matticbot committed May 25, 2022
2 parents 3246ed6 + ace1ec7 commit 3ebe7df
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 14 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [1.46.1](https://github.com/Automattic/newspack-newsletters/compare/v1.46.0...v1.46.1) (2022-05-25)


### Bug Fixes

* sending scheduled newsletters ([#831](https://github.com/Automattic/newspack-newsletters/issues/831)) ([f2028fb](https://github.com/Automattic/newspack-newsletters/commit/f2028fb7fd98163e78c00bc5c35bef20a05fde9f))

## [1.46.1-hotfix.1](https://github.com/Automattic/newspack-newsletters/compare/v1.46.0...v1.46.1-hotfix.1) (2022-05-25)


### Bug Fixes

* sending scheduled newsletters ([2a25225](https://github.com/Automattic/newspack-newsletters/commit/2a25225f79e032ae454fe3e47fd40708f3b8c6e9))

# [1.46.0](https://github.com/Automattic/newspack-newsletters/compare/v1.45.0...v1.46.0) (2022-05-18)


Expand Down
4 changes: 4 additions & 0 deletions includes/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,10 @@ public static function set_newsletter_sent( $post_id, $time = 0 ) {
* @return false|int False if not sent, or timestamp of when it was sent.
*/
public static function is_newsletter_sent( $post_id ) {
$scheduling_error = get_transient( sprintf( 'newspack_newsletters_scheduling_error_%s', $post_id ) );
if ( $scheduling_error ) {
return false;
}
$sent = get_post_meta( $post_id, 'newsletter_sent', true );
if ( 0 < $sent ) {
return $sent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct() {
add_action( 'rest_api_init', [ $this->controller, 'register_routes' ] );
}
add_action( 'pre_post_update', [ $this, 'pre_post_update' ], 10, 2 );
add_action( 'transition_post_status', [ $this, 'transition_post_status' ], 10, 3 );
add_filter( 'wp_insert_post_data', [ $this, 'insert_post_data' ], 10, 2 );
}

Expand Down Expand Up @@ -116,13 +117,8 @@ public function pre_post_update( $post_id, $data ) {
wp_die( $error ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

// Send if changing from any status to controlled statuses - 'publish' or 'private'.
if (
! $sent &&
$old_status !== $new_status &&
in_array( $new_status, self::$controlled_statuses, true ) &&
! in_array( $old_status, self::$controlled_statuses, true )
) {
// Send if changing from any status to publish.
if ( ! $sent && 'publish' === $new_status && 'publish' !== $old_status ) {
$result = $this->send_newsletter( $post );
if ( is_wp_error( $result ) ) {
$transient = sprintf( 'newspack_newsletters_error_%s_%s', $post->ID, get_current_user_id() );
Expand All @@ -132,6 +128,40 @@ public function pre_post_update( $post_id, $data ) {
}
}

/**
* Handle post status transition for scheduled newsletters.
*
* This is executed after the post is updated.
*
* Scheduling a post (future -> publish) does not trigger the
* `pre_post_update` action hook because it uses the `wp_publish_post()`
* function. Unfortunately, this function does not fire any action hook prior
* to updating the post, so, for this case, we need to handle sending after
* the post is published.
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param WP_Post $post Post object.
*/
public function transition_post_status( $new_status, $old_status, $post ) {
if ( 'publish' === $new_status && 'future' === $old_status ) {
$result = $this->send_newsletter( $post );
$error_transient_key = sprintf( 'newspack_newsletters_scheduling_error_%s', $post->ID );
if ( is_wp_error( $result ) ) {
set_transient( $error_transient_key, $result->get_error_message() );
wp_update_post(
[
'ID' => $post->ID,
'post_status' => 'draft',
]
);
wp_die( $result ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
delete_transient( $error_transient_key );
}
}
}

/**
* Handle newsletter post status changes.
*
Expand Down
2 changes: 1 addition & 1 deletion newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Author: Automattic
* Text Domain: newspack-newsletters
* Domain Path: /languages
* Version: 1.46.0
* Version: 1.46.1
*
* @package Newspack_Newsletters
*/
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newspack-newsletters",
"version": "1.46.0",
"version": "1.46.1",
"description": "",
"scripts": {
"cm": "newspack-scripts commit",
Expand Down
2 changes: 1 addition & 1 deletion src/components/send-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default compose( [
? __( 'Mark as sent and publish', 'newspack-newsletters' )
: __( 'Mark as sent', 'newspack-newsletters' );
} else {
modalSubmitLabel = __( 'Send', 'newspack-newsletters' );
modalSubmitLabel = label;
}

useEffect( () => {
Expand Down
2 changes: 1 addition & 1 deletion src/service-providers/constant_contact/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const renderPreSendInfo = newsletterData => {

return (
<p>
{ __( "You're about to send a newsletter to:", 'newspack-newsletters' ) }
{ __( "You're sending a newsletter to:", 'newspack-newsletters' ) }
<br />
<strong>{ campaignLists.map( list => list.name ).join( ', ' ) }</strong>
<br />
Expand Down
2 changes: 1 addition & 1 deletion src/service-providers/mailchimp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const renderPreSendInfo = newsletterData => {

return (
<p>
{ __( "You're about to send a newsletter to:", 'newspack-newsletters' ) }
{ __( "You're sending a newsletter to:", 'newspack-newsletters' ) }
<br />
<strong>{ listData.name }</strong>
<br />
Expand Down

0 comments on commit 3ebe7df

Please sign in to comment.