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 a listener to track wp_mail events #66

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions includes/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class EventManager {
'\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\Commerce',
'\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\Yoast',
'\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\WonderCart',
'\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\WPMail',
);

/**
Expand Down Expand Up @@ -92,13 +93,14 @@ public function rest_api_init() {
/**
* Add the weekly option to cron schedules if it doesn't exist
*
* @param array $schedules List of cron schedule options
* @param array $schedules List of cron schedule options
*
* @return array
*/
public function add_minutely_schedule( $schedules ) {
if ( ! array_key_exists( 'minutely',
$schedules ) || MINUTE_IN_SECONDS !== $schedules['minutely']['interval'] ) {
if ( ! array_key_exists( 'minutely', $schedules ) ||
MINUTE_IN_SECONDS !== $schedules['minutely']['interval']
) {
$schedules['minutely'] = array(
'interval' => MINUTE_IN_SECONDS,
'display' => __( 'Once Every Minute' ),
Expand Down Expand Up @@ -138,7 +140,7 @@ public function shutdown() {
/**
* Register a new event subscriber
*
* @param SubscriberInterface $subscriber Class subscribing to event updates
* @param SubscriberInterface $subscriber Class subscribing to event updates
*
* @return void
*/
Expand Down Expand Up @@ -183,7 +185,7 @@ public function initialize_listeners() {
/**
* Push event data onto the queue
*
* @param Event $event Details about the action taken
* @param Event $event Details about the action taken
*
* @return void
*/
Expand All @@ -195,7 +197,7 @@ public function push( Event $event ) {
/**
* Send queued events to all subscribers
*
* @param array $events A list of events
* @param array $events A list of events
*
* @return void
*/
Expand Down
34 changes: 34 additions & 0 deletions includes/Listeners/WPMail.php
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'],
wpscholar marked this conversation as resolved.
Show resolved Hide resolved
)
);
}
}
Loading