From e4dcc3d91842ac9d42e97c9c86f6adb9c783c60f Mon Sep 17 00:00:00 2001
From: Renato Alves <19148962+renatonascalves@users.noreply.github.com>
Date: Fri, 11 Oct 2024 17:31:31 -0300
Subject: [PATCH 1/3] WIP: issue-1161
From ed59dff7bab53e8552bbd349e9140a59756451d4 Mon Sep 17 00:00:00 2001
From: Renato Alves <19148962+renatonascalves@users.noreply.github.com>
Date: Fri, 11 Oct 2024 17:35:38 -0300
Subject: [PATCH 2/3] Support sending debug notifications to multiple emails
---
...in-apple-settings-section-developer-tools.php | 7 ++++---
.../class-admin-apple-settings-section.php | 13 +++++++++++--
.../apple-push-api/request/class-request.php | 16 ++++++++++++----
3 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/admin/settings/class-admin-apple-settings-section-developer-tools.php b/admin/settings/class-admin-apple-settings-section-developer-tools.php
index 77db19a5..7e372794 100644
--- a/admin/settings/class-admin-apple-settings-section-developer-tools.php
+++ b/admin/settings/class-admin-apple-settings-section-developer-tools.php
@@ -41,10 +41,11 @@ public function __construct( $page ) {
'type' => [ 'no', 'yes' ],
],
'apple_news_admin_email' => [
- 'label' => __( 'Administrator Email', 'apple-news' ),
+ 'label' => __( 'Email(s)', 'apple-news' ),
'required' => false,
- 'type' => 'string',
+ 'type' => 'email',
'size' => 40,
+ 'multiple' => true,
],
];
@@ -70,7 +71,7 @@ public function __construct( $page ) {
*/
public function get_section_info() {
return __(
- 'If debugging is enabled, emails will be sent to an administrator for every publish, update or delete action with a detailed API response.',
+ 'If debugging is enabled (and valid emails are provided), emails will be sent for every publish, update or delete action with a detailed API response.',
'apple-news'
);
}
diff --git a/admin/settings/class-admin-apple-settings-section.php b/admin/settings/class-admin-apple-settings-section.php
index 5ad1c7d6..fdb292fe 100644
--- a/admin/settings/class-admin-apple-settings-section.php
+++ b/admin/settings/class-admin-apple-settings-section.php
@@ -126,6 +126,7 @@ class Admin_Apple_Settings_Section extends Apple_News {
'max' => [],
'step' => [],
'type' => [],
+ 'multiple' => [],
'required' => [],
'size' => [],
'id' => [],
@@ -324,6 +325,14 @@ public function render_field( $args ) {
$field = '';
} elseif ( 'number' === $type ) {
$field = '';
+ } elseif ( 'email' === $type ) {
+ $field = 'is_multiple( $name ) ) {
+ $field .= ' multiple %s>';
+ } else {
+ $field .= ' %s>';
+ }
} else {
// If nothing else matches, it's a string.
$field = '';
@@ -403,9 +412,9 @@ public function render_field( $args ) {
protected function get_type_for( $name ) {
if ( $this->hidden ) {
return 'hidden';
- } else {
- return empty( $this->settings[ $name ]['type'] ) ? 'string' : $this->settings[ $name ]['type'];
}
+
+ return empty( $this->settings[ $name ]['type'] ) ? 'string' : $this->settings[ $name ]['type'];
}
/**
diff --git a/includes/apple-push-api/request/class-request.php b/includes/apple-push-api/request/class-request.php
index 1c29a018..5271eb6f 100644
--- a/includes/apple-push-api/request/class-request.php
+++ b/includes/apple-push-api/request/class-request.php
@@ -171,9 +171,17 @@ private function parse_response( $response, $json = true, $type = 'post', $meta
&& 'yes' === $settings['apple_news_enable_debugging']
&& 'get' !== $type ) {
- // Get the admin email.
- $admin_email = filter_var( $settings['apple_news_admin_email'], FILTER_VALIDATE_EMAIL );
- if ( empty( $admin_email ) ) {
+ $emails = $settings['apple_news_admin_email'] ?? '';
+
+ if ( str_contains( $emails, ',' ) ) {
+ $emails = array_map( 'trim', explode( ',', $emails ) );
+ } else {
+ $emails = [ $emails ];
+ }
+
+ $to = array_filter( $emails, 'is_email' );
+
+ if ( empty( $to ) ) {
return; // TODO Fix inconsistent return value.
}
@@ -217,7 +225,7 @@ private function parse_response( $response, $json = true, $type = 'post', $meta
// Send the email.
if ( ! empty( $body ) ) {
wp_mail( // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_mail_wp_mail
- $admin_email,
+ $to,
esc_html__( 'Apple News Notification', 'apple-news' ),
$body,
$headers
From 456463b7dd64efa81a69790f5e1179d85c4503ea Mon Sep 17 00:00:00 2001
From: Renato Alves <19148962+renatonascalves@users.noreply.github.com>
Date: Fri, 11 Oct 2024 17:35:48 -0300
Subject: [PATCH 3/3] Ready for review