fix: resolve container width issues, spa redirects, and appearance settings overwrite. feat: enhance order/sub details and newsletter layout
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Notification Manager
|
||||
*
|
||||
@@ -9,32 +10,43 @@
|
||||
|
||||
namespace WooNooW\Core\Notifications;
|
||||
|
||||
class NotificationManager {
|
||||
|
||||
use WooNooW\Core\Notifications\ChannelRegistry;
|
||||
|
||||
class NotificationManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if a channel is enabled globally
|
||||
*
|
||||
* @param string $channel_id Channel ID (email, push, etc.)
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_channel_enabled($channel_id) {
|
||||
public static function is_channel_enabled($channel_id)
|
||||
{
|
||||
// Check built-in channels
|
||||
if ($channel_id === 'email') {
|
||||
return (bool) get_option('woonoow_email_notifications_enabled', true);
|
||||
} elseif ($channel_id === 'push') {
|
||||
return (bool) get_option('woonoow_push_notifications_enabled', true);
|
||||
}
|
||||
|
||||
// For addon channels, check if they're registered and enabled
|
||||
|
||||
// Check if channel is registered in ChannelRegistry
|
||||
if (ChannelRegistry::has($channel_id)) {
|
||||
$channel = ChannelRegistry::get($channel_id);
|
||||
return $channel->is_configured();
|
||||
}
|
||||
|
||||
// Legacy: check via filter (backward compatibility)
|
||||
$channels = apply_filters('woonoow_notification_channels', []);
|
||||
foreach ($channels as $channel) {
|
||||
if ($channel['id'] === $channel_id) {
|
||||
return isset($channel['enabled']) ? (bool) $channel['enabled'] : true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a channel is enabled for a specific event
|
||||
*
|
||||
@@ -42,24 +54,25 @@ class NotificationManager {
|
||||
* @param string $channel_id Channel ID
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_event_channel_enabled($event_id, $channel_id) {
|
||||
public static function is_event_channel_enabled($event_id, $channel_id)
|
||||
{
|
||||
$settings = get_option('woonoow_notification_settings', []);
|
||||
|
||||
|
||||
if (!isset($settings[$event_id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$event = $settings[$event_id];
|
||||
|
||||
|
||||
if (!isset($event['channels'][$channel_id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isset($event['channels'][$channel_id]['enabled'])
|
||||
? (bool) $event['channels'][$channel_id]['enabled']
|
||||
|
||||
return isset($event['channels'][$channel_id]['enabled'])
|
||||
? (bool) $event['channels'][$channel_id]['enabled']
|
||||
: false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if notification should be sent
|
||||
*
|
||||
@@ -69,26 +82,27 @@ class NotificationManager {
|
||||
* @param string $channel_id Channel ID
|
||||
* @return bool
|
||||
*/
|
||||
public static function should_send_notification($event_id, $channel_id) {
|
||||
public static function should_send_notification($event_id, $channel_id)
|
||||
{
|
||||
// Check if WooNooW notification system is enabled
|
||||
$system_mode = get_option('woonoow_notification_system_mode', 'woonoow');
|
||||
if ($system_mode !== 'woonoow') {
|
||||
return false; // Use WooCommerce default emails instead
|
||||
}
|
||||
|
||||
|
||||
// Check if channel is globally enabled
|
||||
if (!self::is_channel_enabled($channel_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Check if channel is enabled for this specific event
|
||||
if (!self::is_event_channel_enabled($event_id, $channel_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get recipient for event channel
|
||||
*
|
||||
@@ -96,16 +110,17 @@ class NotificationManager {
|
||||
* @param string $channel_id Channel ID
|
||||
* @return string Recipient type (admin, customer, both)
|
||||
*/
|
||||
public static function get_recipient($event_id, $channel_id) {
|
||||
public static function get_recipient($event_id, $channel_id)
|
||||
{
|
||||
$settings = get_option('woonoow_notification_settings', []);
|
||||
|
||||
|
||||
if (!isset($settings[$event_id]['channels'][$channel_id]['recipient'])) {
|
||||
return 'admin';
|
||||
}
|
||||
|
||||
|
||||
return $settings[$event_id]['channels'][$channel_id]['recipient'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send notification through specified channel
|
||||
*
|
||||
@@ -114,16 +129,25 @@ class NotificationManager {
|
||||
* @param array $data Notification data
|
||||
* @return bool Success status
|
||||
*/
|
||||
public static function send($event_id, $channel_id, $data = []) {
|
||||
public static function send($event_id, $channel_id, $data = [])
|
||||
{
|
||||
// Validate if notification should be sent
|
||||
if (!self::should_send_notification($event_id, $channel_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Get recipient
|
||||
$recipient = self::get_recipient($event_id, $channel_id);
|
||||
|
||||
// Allow addons to handle their own channels
|
||||
|
||||
// Try to use registered channel from ChannelRegistry
|
||||
if (ChannelRegistry::has($channel_id)) {
|
||||
$channel = ChannelRegistry::get($channel_id);
|
||||
if ($channel->is_configured()) {
|
||||
return $channel->send($event_id, $recipient, $data);
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy: Allow addons to handle their own channels via filter
|
||||
$sent = apply_filters(
|
||||
'woonoow_send_notification',
|
||||
false,
|
||||
@@ -132,22 +156,22 @@ class NotificationManager {
|
||||
$recipient,
|
||||
$data
|
||||
);
|
||||
|
||||
|
||||
// If addon handled it, return
|
||||
if ($sent !== false) {
|
||||
return $sent;
|
||||
}
|
||||
|
||||
// Handle built-in channels
|
||||
|
||||
// Handle built-in channels (email, push)
|
||||
if ($channel_id === 'email') {
|
||||
return self::send_email($event_id, $recipient, $data);
|
||||
} elseif ($channel_id === 'push') {
|
||||
return self::send_push($event_id, $recipient, $data);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send email notification
|
||||
*
|
||||
@@ -156,25 +180,26 @@ class NotificationManager {
|
||||
* @param array $data Notification data
|
||||
* @return bool
|
||||
*/
|
||||
private static function send_email($event_id, $recipient, $data) {
|
||||
private static function send_email($event_id, $recipient, $data)
|
||||
{
|
||||
// Use EmailRenderer to render the email
|
||||
$renderer = EmailRenderer::instance();
|
||||
$email_data = $renderer->render($event_id, $recipient, $data['order'] ?? $data['product'] ?? $data['customer'] ?? null, $data);
|
||||
|
||||
|
||||
if (!$email_data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Send email using wp_mail
|
||||
$headers = ['Content-Type: text/html; charset=UTF-8'];
|
||||
$sent = wp_mail($email_data['to'], $email_data['subject'], $email_data['body'], $headers);
|
||||
|
||||
|
||||
// Trigger action for logging/tracking
|
||||
do_action('woonoow_email_sent', $event_id, $recipient, $email_data, $sent);
|
||||
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send push notification
|
||||
*
|
||||
@@ -183,7 +208,8 @@ class NotificationManager {
|
||||
* @param array $data Notification data
|
||||
* @return bool
|
||||
*/
|
||||
private static function send_push($event_id, $recipient, $data) {
|
||||
private static function send_push($event_id, $recipient, $data)
|
||||
{
|
||||
// Push notification sending will be implemented later
|
||||
// This is a placeholder for future implementation
|
||||
do_action('woonoow_send_push_notification', $event_id, $recipient, $data);
|
||||
|
||||
Reference in New Issue
Block a user