fix: Add comprehensive MailQueue debugging and argument handling
🐛 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
This commit is contained in:
@@ -8,6 +8,10 @@ namespace WooNooW\Core\Mail;
|
|||||||
class MailQueue {
|
class MailQueue {
|
||||||
public static function init() {
|
public static function init() {
|
||||||
add_action('woonoow/mail/send', [__CLASS__, 'sendNow'], 10, 1);
|
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.
|
* Retrieves payload from wp_options and deletes it after sending.
|
||||||
*/
|
*/
|
||||||
public static function sendNow($email_id = null) {
|
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)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,15 +68,27 @@ class MailQueue {
|
|||||||
|
|
||||||
if (!$p) {
|
if (!$p) {
|
||||||
error_log('[WooNooW MailQueue] ERROR: Email payload not found for ID: ' . $email_id);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log('[WooNooW MailQueue] Payload retrieved - To: ' . ($p['to'] ?? 'unknown') . ', Subject: ' . ($p['subject'] ?? 'unknown'));
|
||||||
|
|
||||||
// Temporarily disable WooEmailOverride to prevent infinite loop
|
// Temporarily disable WooEmailOverride to prevent infinite loop
|
||||||
if (class_exists('WooNooW\Core\Mail\WooEmailOverride')) {
|
if (class_exists('WooNooW\Core\Mail\WooEmailOverride')) {
|
||||||
|
error_log('[WooNooW MailQueue] Disabling WooEmailOverride to prevent loop');
|
||||||
WooEmailOverride::disable();
|
WooEmailOverride::disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_mail(
|
error_log('[WooNooW MailQueue] Calling wp_mail() now...');
|
||||||
|
|
||||||
|
$result = wp_mail(
|
||||||
$p['to'] ?? '',
|
$p['to'] ?? '',
|
||||||
$p['subject'] ?? '',
|
$p['subject'] ?? '',
|
||||||
$p['html'] ?? '',
|
$p['html'] ?? '',
|
||||||
@@ -70,16 +96,17 @@ class MailQueue {
|
|||||||
$p['attachments'] ?? []
|
$p['attachments'] ?? []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
error_log('[WooNooW MailQueue] wp_mail() returned: ' . ($result ? 'TRUE (success)' : 'FALSE (failed)'));
|
||||||
|
|
||||||
// Re-enable
|
// Re-enable
|
||||||
if (class_exists('WooNooW\Core\Mail\WooEmailOverride')) {
|
if (class_exists('WooNooW\Core\Mail\WooEmailOverride')) {
|
||||||
|
error_log('[WooNooW MailQueue] Re-enabling WooEmailOverride');
|
||||||
WooEmailOverride::enable();
|
WooEmailOverride::enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the temporary option after sending
|
// Delete the temporary option after sending
|
||||||
delete_option($email_id);
|
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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user