feat: Complete email debugging toolkit and comprehensive guide

�� New Diagnostic Tools:

1. check-settings.php
   - Notification system mode
   - Email channel status
   - Event configuration
   - Template configuration
   - Hook registration
   - Action Scheduler stats
   - Queued emails
   - Recommendations

2. test-email-direct.php
   - Queue test email
   - Manually trigger sendNow()
   - Test wp_mail() directly
   - Check wp_options
   - Check Action Scheduler
   - Verify email sent

3. EMAIL_DEBUGGING_GUIDE.md
   - Complete troubleshooting guide
   - Common issues & solutions
   - Expected log flow
   - Testing procedures
   - Manual fixes
   - Monitoring queries
   - Quick checklist

🔍 Enhanced Logging:
- MailQueue::init() logs hook registration
- sendNow() logs all arguments and types
- Handles both string and array arguments
- Checks database for missing options
- Logs wp_mail() result
- Logs WooEmailOverride disable/enable

🎯 Usage:
1. Visit check-settings.php - verify configuration
2. Visit test-email-direct.php - test email flow
3. Check debug.log for detailed flow
4. Follow EMAIL_DEBUGGING_GUIDE.md for troubleshooting

📋 Checklist for User:
- [ ] Run check-settings.php
- [ ] Run test-email-direct.php
- [ ] Check debug.log
- [ ] Verify Action Scheduler args
- [ ] Check Email Log plugin
- [ ] Follow debugging guide
This commit is contained in:
dwindown
2025-11-18 18:19:56 +07:00
parent 67b8a15429
commit 8e314b7c54
3 changed files with 655 additions and 0 deletions

178
check-settings.php Normal file
View File

@@ -0,0 +1,178 @@
<?php
/**
* Check Notification Settings
*
* Usage: Visit /wp-content/plugins/woonoow/check-settings.php
*/
// Load WordPress
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/wp-load.php';
if (!current_user_can('manage_options')) {
die('Access denied');
}
header('Content-Type: text/plain; charset=utf-8');
echo "=== WooNooW Notification Settings Check ===\n\n";
// 1. System Mode
echo "1. Notification System Mode:\n";
$system_mode = get_option('woonoow_notification_system_mode', 'not set');
echo " Value: $system_mode\n";
if ($system_mode === 'woonoow') {
echo " ✓ WooNooW notifications enabled\n";
} elseif ($system_mode === 'woocommerce') {
echo " ✗ Using WooCommerce default emails (WooNooW disabled)\n";
} else {
echo " ⚠ Not set (defaulting to WooNooW)\n";
}
// 2. Email Channel
echo "\n2. Email Channel:\n";
$email_enabled = get_option('woonoow_email_notifications_enabled', 'not set');
echo " Value: " . var_export($email_enabled, true) . "\n";
if ($email_enabled) {
echo " ✓ Email notifications enabled\n";
} else {
echo " ✗ Email notifications disabled\n";
}
// 3. Notification Settings
echo "\n3. Event Configuration:\n";
$settings = get_option('woonoow_notification_settings', []);
if (empty($settings)) {
echo " ✗ No notification settings found!\n";
echo " This means no events are configured.\n";
} else {
echo " ✓ Settings found\n";
if (isset($settings['events'])) {
echo "\n Events:\n";
foreach ($settings['events'] as $event_id => $event_data) {
echo " - $event_id:\n";
if (isset($event_data['channels']['email'])) {
$email_config = $event_data['channels']['email'];
$enabled = $email_config['enabled'] ?? false;
$status = $enabled ? '✓ ENABLED' : '✗ DISABLED';
echo " Email: $status\n";
if (isset($email_config['recipients'])) {
echo " Recipients: " . implode(', ', array_keys($email_config['recipients'])) . "\n";
}
} else {
echo " Email: ✗ NOT CONFIGURED\n";
}
}
} else {
echo " ⚠ No events configured\n";
}
}
// 4. Email Templates
echo "\n4. Email Templates:\n";
$templates = get_option('woonoow_email_templates', []);
if (empty($templates)) {
echo " ✗ No email templates found!\n";
} else {
echo "" . count($templates) . " template(s) found\n";
foreach ($templates as $template_id => $template_data) {
echo " - $template_id: " . ($template_data['subject'] ?? 'no subject') . "\n";
}
}
// 5. WooCommerce Hooks
echo "\n5. WooCommerce Hook Status:\n";
global $wp_filter;
$hooks_to_check = [
'woocommerce_order_status_pending_to_processing',
'woocommerce_order_status_pending_to_completed',
'woocommerce_order_status_processing_to_completed',
'woocommerce_order_status_completed',
];
foreach ($hooks_to_check as $hook) {
if (isset($wp_filter[$hook])) {
$callbacks = $wp_filter[$hook]->callbacks;
$count = 0;
foreach ($callbacks as $priority => $funcs) {
$count += count($funcs);
}
echo "$hook: $count callback(s)\n";
} else {
echo "$hook: NOT REGISTERED\n";
}
}
// 6. Mail Queue Hook
echo "\n6. Mail Queue Hook:\n";
if (isset($wp_filter['woonoow/mail/send'])) {
echo " ✓ woonoow/mail/send: REGISTERED\n";
} else {
echo " ✗ woonoow/mail/send: NOT REGISTERED\n";
echo " This means MailQueue::init() was not called!\n";
}
// 7. Action Scheduler
echo "\n7. Action Scheduler:\n";
if (function_exists('as_enqueue_async_action')) {
echo " ✓ Available\n";
global $wpdb;
$stats = [
'pending' => $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}actionscheduler_actions WHERE hook = 'woonoow/mail/send' AND status = 'pending'"),
'complete' => $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}actionscheduler_actions WHERE hook = 'woonoow/mail/send' AND status = 'complete'"),
'failed' => $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}actionscheduler_actions WHERE hook = 'woonoow/mail/send' AND status = 'failed'"),
];
echo " Pending: {$stats['pending']}\n";
echo " Complete: {$stats['complete']}\n";
echo " Failed: {$stats['failed']}\n";
} else {
echo " ✗ Not available (using wp-cron)\n";
}
// 8. Queued Emails
echo "\n8. Queued Emails (wp_options):\n";
global $wpdb;
$queued = $wpdb->get_results(
"SELECT option_name, LENGTH(option_value) as size FROM {$wpdb->options}
WHERE option_name LIKE 'woonoow_mail_%'
ORDER BY option_id DESC LIMIT 10"
);
if (empty($queued)) {
echo " ⚠ No emails in queue\n";
} else {
echo " " . count($queued) . " email(s) in queue:\n";
foreach ($queued as $row) {
echo " - {$row->option_name} ({$row->size} bytes)\n";
}
}
echo "\n=== Summary ===\n";
echo "System Mode: $system_mode\n";
echo "Email Channel: " . ($email_enabled ? 'enabled' : 'disabled') . "\n";
echo "Events Configured: " . (isset($settings['events']) ? count($settings['events']) : 0) . "\n";
echo "Templates: " . count($templates) . "\n";
echo "Queued Emails: " . count($queued) . "\n";
echo "\n=== Recommendations ===\n";
if ($system_mode !== 'woonoow') {
echo "⚠ Set notification system mode to 'woonoow'\n";
}
if (!$email_enabled) {
echo "⚠ Enable email channel\n";
}
if (empty($settings['events'])) {
echo "⚠ Configure events in notification settings\n";
}
if (!isset($wp_filter['woonoow/mail/send'])) {
echo "⚠ MailQueue hook not registered - check Bootstrap::init()\n";
}
echo "\nDone!\n";