Pledge Log: Capture email events.

This commit is contained in:
Ian Dunn 2019-10-31 20:39:57 -05:00
parent 97daa42308
commit 87eb8ec43a
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB
4 changed files with 46 additions and 5 deletions

View file

@ -28,6 +28,7 @@
*/ */
namespace WordPressDotOrg\FiveForTheFuture\Email; namespace WordPressDotOrg\FiveForTheFuture\Email;
use WordPressDotOrg\FiveForTheFuture;
defined( 'WPINC' ) || die(); defined( 'WPINC' ) || die();
@ -42,17 +43,32 @@ const TOKEN_LENGTH = 32;
* @param string $to * @param string $to
* @param string $subject * @param string $subject
* @param string $message * @param string $message
* @param int $pledge_id
* *
* @return bool * @return bool
*/ */
function send_email( $to, $subject, $message ) { function send_email( $to, $subject, $message, $pledge_id ) {
$headers = array( $headers = array(
'From: WordPress - Five for the Future <donotreply@wordpress.org>', 'From: WordPress - Five for the Future <donotreply@wordpress.org>',
'Reply-To: support@wordcamp.org', 'Reply-To: support@wordcamp.org',
// todo update address when new one is created // 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;
} }
/** /**

View file

@ -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" . "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 ); $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 );
} }
} }

View file

@ -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( '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 . '_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 . '_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. * 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' )
);
}

View file

@ -209,7 +209,8 @@ function send_pledge_confirmation_email( $pledge_id, $action_page_id ) {
return Email\send_email( return Email\send_email(
$pledge->{'5ftf_org-pledge-email'}, $pledge->{'5ftf_org-pledge-email'},
'Please confirm your email address', 'Please confirm your email address',
$message $message,
$pledge_id
); );
} }