Configuration

Service Provider Registration

The NotificationServiceProvider auto-configures all built-in channels. No manual configuration files are needed.

$app->register(new NotificationServiceProvider());

Channel Configuration

Mail Channel

The MailChannel auto-detects the WPZylos MailManager from the container. If not available, it falls back to WordPress wp_mail().

With MailManager (preferred):

// If wpzylos-mail is installed, the MailChannel automatically uses it.
// Configure mail settings via the wpzylos-mail package.

Fallback to wp_mail():

// No configuration needed — wp_mail() is used automatically when
// MailManager is not available in the container.

Database Channel

The DatabaseChannel requires the wpzylos-database package and is only registered when a Connection is available.

Table creation:

$installer = $app->make(DatabaseNotificationInstaller::class);
$installer->install();

The table uses the plugin's prefix from ContextInterface::tableName().

Admin Notice Channel

The AdminNoticeChannel uses the ContextInterface for prefixed transient keys. Notices are stored for 1 hour (HOUR_IN_SECONDS) and rendered on the next admin_notices hook.

Custom Channel Registration

Register custom channels during or after service provider registration:

// In your service provider's boot() method:
$manager = $app->make(NotificationManager::class);
$manager->extend('slack', new SlackChannel($webhookUrl));
$manager->extend('sms', new SmsChannel($apiKey));

Notification Routing

Each notifiable entity controls how channels route notifications via routeNotificationFor():

public function routeNotificationFor(string $channel): mixed
{
    return match ($channel) {
        'mail'         => $this->email,
        'database'     => $this->id,
        'admin_notice' => $this->id,
        'slack'        => $this->slack_webhook,
        'sms'          => $this->phone_number,
        default        => null,
    };
}

Error Handling Configuration

Channel failures are reported via the wpzylos_notification_failed action. Hook into it for logging:

add_action('wpzylos_notification_failed', function (
    Notification $notification,
    object $notifiable,
    string $channelName,
    \Throwable $exception
) {
    // Log to your preferred logging system
    error_log("Notification failed: [{$channelName}] {$exception->getMessage()}");
}, 10, 4);

Notification ID

Set a custom notification ID for tracking:

$notification = new OrderShipped($order);
$notification->id = wp_generate_uuid4();
$user->notify($notification);

Database Table Schema

The notifications table schema is defined in DatabaseNotificationInstaller:

ColumnTypeNullableIndex
idbigint(20) unsignedNoPrimary
typevarchar(255)NoYes
notifiable_typevarchar(255)NoComposite
notifiable_idbigint(20) unsignedNoComposite
datalongtextNoNo
read_atdatetimeYesYes
created_atdatetimeNoNo