Troubleshooting
Common Issues
Notification Not Being Sent
Symptoms: notify() is called but nothing happens — no email, no database entry, no admin notice.
Possible Causes:
- Service provider not registered:
// Ensure you've registered the provider: $app->register(new NotificationServiceProvider()); via()returns empty array:// Check your notification's via() method returns channels public function via(): array { return ['mail', 'database']; // Not empty }- Channel not registered in manager:
$manager = $app->make(NotificationManager::class); var_dump($manager->channelNames()); // Should show ['mail', 'database', 'admin_notice'] apply_filtersnot available: TheNotifiabletrait resolves the manager viaapply_filters('wpzylos_resolve_service', ...). If WordPress isn't loaded, this returns null and notifications are silently skipped.
Emails Not Delivered
Symptoms: toMail() returns a valid MailMessage, but no email arrives.
Possible Causes:
- Invalid email routing:
// Ensure routeNotificationFor('mail') returns a valid email public function routeNotificationFor(string $channel): mixed { if ($channel === 'mail') { return $this->email; // Must be a non-empty string } } wp_mail()failing silently:// Test wp_mail() independently $result = wp_mail('[email protected]', 'Test', 'Body'); var_dump($result); // Should be truetoMail()returning null: The baseNotification::toMail()returnsnullby default. Ensure your notification overrides it.
Database Notifications Not Saving
Symptoms: toDatabase() returns data, but nothing appears in the database.
Possible Causes:
- Table not created:
$installer = $app->make(DatabaseNotificationInstaller::class); $installer->install(); wpzylos-databasenot installed:composer require KYNetCode/wpzylos-databasetoDatabase()returning empty array: IftoDatabase()returns[], theDatabaseChannelskips the insert.- Invalid notifiable ID routing:
// Ensure routeNotificationFor('database') returns a numeric ID public function routeNotificationFor(string $channel): mixed { if ($channel === 'database') { return $this->id; // Must be numeric } }
Admin Notices Not Appearing
Symptoms: toAdminNotice() returns a message, but nothing shows in the dashboard.
Possible Causes:
- Not on an admin page:
Admin notices only render on
wp-adminpages via theadmin_noticeshook. - Targeting wrong user:
The notice is stored per-user via transients. Ensure
routeNotificationFor('admin_notice')returns the correct user ID. - Transient expired: Notices expire after 1 hour. If the user doesn't visit admin within that time, the notice is lost.
- Already displayed: Notices are deleted from the transient after being rendered. They only show once.
Channel Failure Errors
Symptoms: Some channels work but others silently fail.
Solution: Listen for the wpzylos_notification_failed action:
add_action('wpzylos_notification_failed', function (
$notification, $notifiable, $channelName, $exception
) {
error_log("Channel [{$channelName}] failed: {$exception->getMessage()}");
error_log($exception->getTraceAsString());
}, 10, 4);
Custom Channel Not Receiving Notifications
Symptoms: You registered a custom channel, but it never receives send() calls.
Checklist:
- Ensure the channel is registered before sending:
$manager->extend('slack', new SlackChannel($url)); - Ensure the notification's
via()includes the channel name:public function via(): array { return ['slack']; // Must match the name used in extend() } - Verify with
hasChannel():var_dump($manager->hasChannel('slack')); // Should be true
PHPStan Errors for WordPress Functions
Symptoms: PHPStan reports "Function esc_html not found" or similar.
Solution: These are ignored in phpstan.neon. Ensure the ignoreErrors section includes all WordPress functions used:
parameters:
ignoreErrors:
- '#Function esc_html not found#'
- '#Function wp_mail not found#'
# ... etc
Or install szepeviktor/phpstan-wordpress for full WordPress stubs.