From 67b8a154294c2eb48c8fe27225efa9672ae7ece1 Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 18 Nov 2025 18:14:32 +0700 Subject: [PATCH] fix: Add comprehensive MailQueue debugging and argument handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Issue: Action Scheduler completing but wp_mail() never called 🔍 Enhanced Debugging: - Log sendNow() entry with all arguments - Log argument type and value - Handle array vs string arguments (Action Scheduler compatibility) - Log payload retrieval status - Log wp_mail() call and result - Log WooEmailOverride disable/enable - Check database for option existence if not found - Log hook registration on init 📝 Debug Output: [WooNooW MailQueue] Hook registered [WooNooW MailQueue] sendNow() called with args [WooNooW MailQueue] email_id type: string/array [WooNooW MailQueue] email_id value: xxx [WooNooW MailQueue] Processing email_id: xxx [WooNooW MailQueue] Payload retrieved - To: xxx, Subject: xxx [WooNooW MailQueue] Disabling WooEmailOverride [WooNooW MailQueue] Calling wp_mail() now... [WooNooW MailQueue] wp_mail() returned: TRUE/FALSE [WooNooW MailQueue] Re-enabling WooEmailOverride [WooNooW MailQueue] Sent and deleted email ID 🎯 This will reveal: 1. If sendNow() is being called at all 2. What arguments Action Scheduler is passing 3. If payload is found in wp_options 4. If wp_mail() is actually called 5. If wp_mail() succeeds or fails --- includes/Core/Mail/MailQueue.php | 39 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/includes/Core/Mail/MailQueue.php b/includes/Core/Mail/MailQueue.php index 82c3aa1..8375553 100644 --- a/includes/Core/Mail/MailQueue.php +++ b/includes/Core/Mail/MailQueue.php @@ -8,6 +8,10 @@ namespace WooNooW\Core\Mail; class MailQueue { public static function init() { add_action('woonoow/mail/send', [__CLASS__, 'sendNow'], 10, 1); + + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('[WooNooW MailQueue] Hook registered: woonoow/mail/send -> MailQueue::sendNow'); + } } /** @@ -41,9 +45,19 @@ class MailQueue { * Retrieves payload from wp_options and deletes it after sending. */ public static function sendNow($email_id = null) { - // email_id should be passed directly as a string by Action Scheduler + error_log('[WooNooW MailQueue] sendNow() called with args: ' . print_r(func_get_args(), true)); + error_log('[WooNooW MailQueue] email_id type: ' . gettype($email_id)); + error_log('[WooNooW MailQueue] email_id value: ' . var_export($email_id, true)); + + // Action Scheduler might pass an array, extract the first element + if (is_array($email_id)) { + error_log('[WooNooW MailQueue] email_id is array, extracting first element'); + $email_id = $email_id[0] ?? null; + } + + // email_id should be a string if (empty($email_id)) { - error_log('[WooNooW MailQueue] ERROR: No email_id provided. Received: ' . print_r(func_get_args(), true)); + error_log('[WooNooW MailQueue] ERROR: No email_id provided after extraction. Received: ' . print_r(func_get_args(), true)); return; } @@ -54,32 +68,45 @@ class MailQueue { if (!$p) { error_log('[WooNooW MailQueue] ERROR: Email payload not found for ID: ' . $email_id); + error_log('[WooNooW MailQueue] Checking if option exists in database...'); + global $wpdb; + $exists = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name = %s", + $email_id + )); + error_log('[WooNooW MailQueue] Option exists in DB: ' . ($exists ? 'yes' : 'no')); return; } + error_log('[WooNooW MailQueue] Payload retrieved - To: ' . ($p['to'] ?? 'unknown') . ', Subject: ' . ($p['subject'] ?? 'unknown')); + // Temporarily disable WooEmailOverride to prevent infinite loop if (class_exists('WooNooW\Core\Mail\WooEmailOverride')) { + error_log('[WooNooW MailQueue] Disabling WooEmailOverride to prevent loop'); WooEmailOverride::disable(); } - wp_mail( + error_log('[WooNooW MailQueue] Calling wp_mail() now...'); + + $result = wp_mail( $p['to'] ?? '', $p['subject'] ?? '', $p['html'] ?? '', $p['headers'] ?? [], $p['attachments'] ?? [] ); + + error_log('[WooNooW MailQueue] wp_mail() returned: ' . ($result ? 'TRUE (success)' : 'FALSE (failed)')); // Re-enable if (class_exists('WooNooW\Core\Mail\WooEmailOverride')) { + error_log('[WooNooW MailQueue] Re-enabling WooEmailOverride'); WooEmailOverride::enable(); } // Delete the temporary option after sending delete_option($email_id); - if (defined('WP_DEBUG') && WP_DEBUG) { - error_log('[WooNooW MailQueue] Sent and deleted email ID: ' . $email_id . ' to: ' . ($p['to'] ?? 'unknown')); - } + error_log('[WooNooW MailQueue] Sent and deleted email ID: ' . $email_id . ' to: ' . ($p['to'] ?? 'unknown')); } } \ No newline at end of file