From 7be906016ec77bc5e85d25ef3bd58e4ef91e533a Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:56:49 -0300 Subject: [PATCH 1/3] WIP: issue-1153 From cd50df48d8f1ee075781e9009827765a4249a470 Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:00:05 -0300 Subject: [PATCH 2/3] A new hook fired when a post fails to be pushed to Apple News --- admin/apple-actions/index/class-push.php | 8 ++++++++ includes/apple-push-api/request/class-request.php | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/admin/apple-actions/index/class-push.php b/admin/apple-actions/index/class-push.php index b679e598..bed4261a 100644 --- a/admin/apple-actions/index/class-push.php +++ b/admin/apple-actions/index/class-push.php @@ -451,6 +451,14 @@ private function push( $user_id = null ): void { $error_message = __( 'There has been an error with the Apple News API: ', 'apple-news' ) . esc_html( $original_error_message ); } + /** + * Actions to be taken after an article failed to be pushed to Apple News. + * + * @param int $post_id The ID of the post. + * @param string $original_error_message The original error message. + */ + do_action( 'apple_news_after_push_failure', $this->id, $original_error_message ); + throw new Action_Exception( esc_html( $error_message ) ); } diff --git a/includes/apple-push-api/request/class-request.php b/includes/apple-push-api/request/class-request.php index 1c29a018..844904cb 100644 --- a/includes/apple-push-api/request/class-request.php +++ b/includes/apple-push-api/request/class-request.php @@ -173,6 +173,7 @@ private function parse_response( $response, $json = true, $type = 'post', $meta // Get the admin email. $admin_email = filter_var( $settings['apple_news_admin_email'], FILTER_VALIDATE_EMAIL ); + if ( empty( $admin_email ) ) { return; // TODO Fix inconsistent return value. } @@ -191,8 +192,8 @@ private function parse_response( $response, $json = true, $type = 'post', $meta if ( 'yes' === $settings['use_remote_images'] ) { $body .= esc_html__( 'Use Remote images enabled ', 'apple-news' ); } elseif ( ! empty( $bundles ) ) { - $body .= "\n" . esc_html__( 'Bundled images', 'apple-news' ) . ":\n"; - $body .= implode( "\n", $bundles ); + $body .= "\n" . esc_html__( 'Bundled images', 'apple-news' ) . ":\n"; + $body .= implode( "\n", $bundles ); } else { $body .= esc_html__( 'No bundled images found.', 'apple-news' ); } @@ -210,7 +211,7 @@ private function parse_response( $response, $json = true, $type = 'post', $meta * * @since 1.4.4 * - * @param string|array $headers Optional. Additional headers. + * @param string|array $headers Optional. Additional headers. */ $headers = apply_filters( 'apple_news_notification_headers', '' ); From c49c0aa58b4be6a3e2a00f4fde089c308d7c488a Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:00:15 -0300 Subject: [PATCH 3/3] Ready for review