From ab6855529782238251c6024dfae105786224759f Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 5 Apr 2024 18:13:22 +0530 Subject: [PATCH 1/2] Add a listener to track wp_mail events --- includes/EventManager.php | 15 +++++++++------ includes/Listeners/WPMail.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 includes/Listeners/WPMail.php diff --git a/includes/EventManager.php b/includes/EventManager.php index 1d0d771..d7620be 100644 --- a/includes/EventManager.php +++ b/includes/EventManager.php @@ -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', ); /** @@ -92,13 +93,15 @@ 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' ), @@ -138,7 +141,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 */ @@ -183,7 +186,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 */ @@ -195,7 +198,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 */ diff --git a/includes/Listeners/WPMail.php b/includes/Listeners/WPMail.php new file mode 100644 index 0000000..c1ef6b0 --- /dev/null +++ b/includes/Listeners/WPMail.php @@ -0,0 +1,34 @@ +push( + 'wp_mail', + array( + 'label_key' => 'subject', + 'subject' => $mail_data['subject'], + ) + ); + } +} From 37df1ef32e769d3b8747905b0fcf18b85fed3ee8 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Tue, 9 Apr 2024 00:40:33 +0530 Subject: [PATCH 2/2] Reformat a bit differently --- includes/EventManager.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/EventManager.php b/includes/EventManager.php index d7620be..7289285 100644 --- a/includes/EventManager.php +++ b/includes/EventManager.php @@ -98,10 +98,9 @@ public function rest_api_init() { * @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' ),