Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filters wp_mail and pre_wp_mail as in native wp_mail function. #72

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions Postman/PostmanWpMailBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,33 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
// create an instance of PostmanWpMail to send the message
$postmanWpMail = new PostmanWpMail ();
// send the mail

$mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );


$mail_data = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );

/**
* Filters whether to preempt sending an email.
*
* Returning a non-null value will short-circuit {@see wp_mail()}, returning
* that value instead. A boolean return value should be used to indicate whether
* the email was successfully sent.
*
* @param null|bool $return Short-circuit return value.
* @param array $mail_data {
* Array of the `wp_mail()` arguments.
*
* @type string|string[] $to Array or comma-separated list of email addresses to send message.
* @type string $subject Email subject.
* @type string $message Message contents.
* @type string|string[] $headers Additional headers.
* @type string|string[] $attachments Paths to files to attach.
* }
*/
$pre_wp_mail = apply_filters( 'pre_wp_mail', null, $mail_data );

if ( null !== $pre_wp_mail ) {
return $pre_wp_mail;
}

$result = $postmanWpMail->send ( $to, $subject, $message, $headers, $attachments );

if( $result ) {
Expand Down