From 87eb8ec43a32f3d3e5b678b01b6a2469ce553d24 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Thu, 31 Oct 2019 20:39:57 -0500 Subject: [PATCH] Pledge Log: Capture email events. --- plugins/wporg-5ftf/includes/email.php | 20 +++++++++++++++-- plugins/wporg-5ftf/includes/pledge-form.php | 4 ++-- plugins/wporg-5ftf/includes/pledge-log.php | 24 +++++++++++++++++++++ plugins/wporg-5ftf/includes/pledge.php | 3 ++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/plugins/wporg-5ftf/includes/email.php b/plugins/wporg-5ftf/includes/email.php index 11f7743..31e6a2c 100644 --- a/plugins/wporg-5ftf/includes/email.php +++ b/plugins/wporg-5ftf/includes/email.php @@ -28,6 +28,7 @@ */ namespace WordPressDotOrg\FiveForTheFuture\Email; +use WordPressDotOrg\FiveForTheFuture; defined( 'WPINC' ) || die(); @@ -42,17 +43,32 @@ const TOKEN_LENGTH = 32; * @param string $to * @param string $subject * @param string $message + * @param int $pledge_id * * @return bool */ -function send_email( $to, $subject, $message ) { +function send_email( $to, $subject, $message, $pledge_id ) { $headers = array( 'From: WordPress - Five for the Future ', 'Reply-To: support@wordcamp.org', // todo update address when new one is created ); - return wp_mail( $to, $subject, $message, $headers ); + $result = wp_mail( $to, $subject, $message, $headers ); + + /** + * Broadcast the results of an attempt to send an email. + * + * @param string $to + * @param string $subject + * @param string $message + * @param array $headers + * @param bool $result + * @param int $pledge_id + */ + do_action( FiveForTheFuture\PREFIX . '_email_result', $to, $subject, $message, $headers, $result, $pledge_id ); + + return $result; } /** diff --git a/plugins/wporg-5ftf/includes/pledge-form.php b/plugins/wporg-5ftf/includes/pledge-form.php index 600ff8d..e9daa69 100755 --- a/plugins/wporg-5ftf/includes/pledge-form.php +++ b/plugins/wporg-5ftf/includes/pledge-form.php @@ -182,11 +182,11 @@ function send_contributor_confirmation_emails( $pledge_id, $contributor_id = nul "https://profiles.wordpress.org/me/profile/edit/group/5/\n\n" . - "If they aren't sponsoring your contributions, then you can ignore this email, and you won't be listed on their pledge." + "If {$pledge->post_title} isn't sponsoring your contributions, then you can ignore this email, and you won't be listed on their pledge." ; $user = get_user_by( 'login', $contributor->post_title ); - Email\send_email( $user->user_email, $subject, $message ); + Email\send_email( $user->user_email, $subject, $message, $pledge_id ); } } diff --git a/plugins/wporg-5ftf/includes/pledge-log.php b/plugins/wporg-5ftf/includes/pledge-log.php index 0090d79..5c5d3a5 100644 --- a/plugins/wporg-5ftf/includes/pledge-log.php +++ b/plugins/wporg-5ftf/includes/pledge-log.php @@ -19,6 +19,7 @@ add_action( 'added_post_meta', __NAMESPACE__ . '\capture_added_post_meta', 99, 4 add_action( 'transition_post_status', __NAMESPACE__ . '\capture_transition_post_status', 99, 3 ); add_action( FiveForTheFuture\PREFIX . '_add_pledge_contributors', __NAMESPACE__ . '\capture_add_pledge_contributors', 99, 3 ); add_action( FiveForTheFuture\PREFIX . '_remove_contributor', __NAMESPACE__ . '\capture_remove_contributor', 99, 3 ); +add_action( FiveForTheFuture\PREFIX . '_email_result', __NAMESPACE__ . '\capture_email_result', 99, 6 ); /** * Adds a meta box for the log on the custom post type. @@ -317,3 +318,26 @@ function capture_remove_contributor( $pledge_id, $contributor_post_id, $result ) ); } } + +/** + * Capture the results of an attempt to send an email. + * + * @param string $to + * @param string $subject + * @param string $message + * @param array $headers + * @param bool $result + * @param int $pledge_id + */ +function capture_email_result( $to, $subject, $message, $headers, $result, $pledge_id ) { + add_log_entry( + $pledge_id, + 'send_email_result', + sprintf( + 'Sending email to %s %s.', + $to, + $result ? 'succeeded' : 'failed' + ), + compact( 'to', 'subject', 'message', 'headers', 'result' ) + ); +} diff --git a/plugins/wporg-5ftf/includes/pledge.php b/plugins/wporg-5ftf/includes/pledge.php index 5ab4148..9fd853b 100755 --- a/plugins/wporg-5ftf/includes/pledge.php +++ b/plugins/wporg-5ftf/includes/pledge.php @@ -209,7 +209,8 @@ function send_pledge_confirmation_email( $pledge_id, $action_page_id ) { return Email\send_email( $pledge->{'5ftf_org-pledge-email'}, 'Please confirm your email address', - $message + $message, + $pledge_id ); }