-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from newfold-labs/add/wp-mail-event
Add a listener to track `wp_mail` events
- Loading branch information
Showing
2 changed files
with
42 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace NewfoldLabs\WP\Module\Data\Listeners; | ||
|
||
/** | ||
* Monitors wp_mail events. | ||
*/ | ||
class WPMail extends Listener { | ||
|
||
/** | ||
* Register wp_mail_* hooks for the subscriber. | ||
* | ||
* @return void | ||
*/ | ||
public function register_hooks() { | ||
add_action( 'wp_mail_succeeded', array( $this, 'mail_succeeded' ), 10, 1 ); | ||
} | ||
|
||
/** | ||
* Mail sent successfully. | ||
* | ||
* @param array $mail_data An array containing the email recipient(s), subject, message, headers, and attachments. | ||
* @return void | ||
*/ | ||
public function mail_succeeded( $mail_data ) { | ||
$this->push( | ||
'wp_mail', | ||
array( | ||
'label_key' => 'subject', | ||
'subject' => $mail_data['subject'], | ||
) | ||
); | ||
} | ||
} |