Files
WooNooW/includes/Core/Notifications/EventRegistry.php
dwindown 4471cd600f feat: Complete markdown syntax refinement and variable protection
 New cleaner syntax implemented:
- [card:type] instead of [card type='type']
- [button:style](url)Text[/button] instead of [button url='...' style='...']
- Standard markdown images: ![alt](url)

 Variable protection from markdown parsing:
- Variables with underscores (e.g., {order_items_table}) now protected
- HTML comment placeholders prevent italic/bold parsing
- All variables render correctly in preview

 Button rendering fixes:
- Buttons work in Visual mode inside cards
- Buttons work in Preview mode
- Button clicks prevented in visual editor
- Proper styling for solid and outline buttons

 Backward compatibility:
- Old syntax still supported
- No breaking changes

 Bug fixes:
- Fixed order_item_table → order_items_table naming
- Fixed button regex to match across newlines
- Added button/image parsing to parseMarkdownBasics
- Prevented button clicks on .button and .button-outline classes

📚 Documentation:
- NEW_MARKDOWN_SYNTAX.md - Complete user guide
- MARKDOWN_SYNTAX_AND_VARIABLES.md - Technical analysis
2025-11-15 20:05:50 +07:00

244 lines
7.3 KiB
PHP

<?php
/**
* Event Registry - Single Source of Truth for Notification Events
*
* Defines all notification events in the system with their metadata.
* Other components query this registry instead of hardcoding event lists.
*
* @package WooNooW\Core\Notifications
*/
namespace WooNooW\Core\Notifications;
class EventRegistry {
/**
* Get all registered notification events
*
* This is the SINGLE SOURCE OF TRUTH for all events in the system.
* All other components (API, TemplateProvider, etc.) must use this.
*
* @return array Event definitions with structure:
* [
* 'event_id' => [
* 'id' => 'event_id',
* 'label' => 'Human readable label',
* 'description' => 'What triggers this event',
* 'category' => 'orders|products|customers',
* 'recipient_type' => 'staff|customer',
* 'wc_email' => 'woocommerce_email_id',
* 'enabled' => true|false,
* ]
* ]
*/
public static function get_all_events() {
$events = [
// STAFF EVENTS
'order_placed' => [
'id' => 'order_placed',
'label' => __('Order Placed', 'woonoow'),
'description' => __('When a new order is placed', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'staff',
'wc_email' => 'new_order',
'enabled' => true,
],
'order_processing' => [
'id' => 'order_processing',
'label' => __('Order Processing', 'woonoow'),
'description' => __('When order is confirmed and being processed', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'staff',
'wc_email' => 'customer_processing_order',
'enabled' => true,
],
'order_shipped' => [
'id' => 'order_shipped',
'label' => __('Order Shipped', 'woonoow'),
'description' => __('When order is shipped', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'staff',
'wc_email' => '',
'enabled' => true,
],
'order_completed' => [
'id' => 'order_completed',
'label' => __('Order Completed', 'woonoow'),
'description' => __('When order is marked as completed', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'staff',
'wc_email' => 'customer_completed_order',
'enabled' => true,
],
'order_cancelled' => [
'id' => 'order_cancelled',
'label' => __('Order Cancelled', 'woonoow'),
'description' => __('When order is cancelled', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'staff',
'wc_email' => 'cancelled_order',
'enabled' => true,
],
'payment_received' => [
'id' => 'payment_received',
'label' => __('Payment Received', 'woonoow'),
'description' => __('When payment is successfully received', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'staff',
'wc_email' => '',
'enabled' => true,
],
'payment_failed' => [
'id' => 'payment_failed',
'label' => __('Payment Failed', 'woonoow'),
'description' => __('When payment processing fails', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'staff',
'wc_email' => '',
'enabled' => true,
],
// CUSTOMER EVENTS
'order_placed_customer' => [
'id' => 'order_placed',
'label' => __('Order Placed', 'woonoow'),
'description' => __('When customer places an order', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'customer',
'wc_email' => 'customer_on_hold_order',
'enabled' => true,
],
'order_processing_customer' => [
'id' => 'order_processing',
'label' => __('Order Processing', 'woonoow'),
'description' => __('When order status changes to processing', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'customer',
'wc_email' => 'customer_processing_order',
'enabled' => true,
],
'order_shipped_customer' => [
'id' => 'order_shipped',
'label' => __('Order Shipped', 'woonoow'),
'description' => __('When order is shipped with tracking', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'customer',
'wc_email' => '',
'enabled' => true,
],
'order_completed_customer' => [
'id' => 'order_completed',
'label' => __('Order Completed', 'woonoow'),
'description' => __('When order is delivered/completed', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'customer',
'wc_email' => 'customer_completed_order',
'enabled' => true,
],
'order_cancelled_customer' => [
'id' => 'order_cancelled',
'label' => __('Order Cancelled', 'woonoow'),
'description' => __('When order is cancelled', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'customer',
'wc_email' => 'customer_refunded_order',
'enabled' => true,
],
'payment_received_customer' => [
'id' => 'payment_received',
'label' => __('Payment Received', 'woonoow'),
'description' => __('When payment is confirmed', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'customer',
'wc_email' => '',
'enabled' => true,
],
'payment_failed_customer' => [
'id' => 'payment_failed',
'label' => __('Payment Failed', 'woonoow'),
'description' => __('When payment fails - prompt retry', 'woonoow'),
'category' => 'orders',
'recipient_type' => 'customer',
'wc_email' => 'customer_failed_order',
'enabled' => true,
],
'new_customer' => [
'id' => 'new_customer',
'label' => __('New Customer', 'woonoow'),
'description' => __('When a new customer registers', 'woonoow'),
'category' => 'customers',
'recipient_type' => 'customer',
'wc_email' => 'customer_new_account',
'enabled' => true,
],
];
/**
* Filter: woonoow_notification_events_registry
*
* Allows plugins/themes to add custom notification events
*
* @param array $events Event definitions
*/
return apply_filters('woonoow_notification_events_registry', $events);
}
/**
* Get events by recipient type
*
* @param string $recipient_type 'staff' or 'customer'
* @return array Filtered events
*/
public static function get_events_by_recipient($recipient_type) {
$all_events = self::get_all_events();
return array_filter($all_events, function($event) use ($recipient_type) {
return $event['recipient_type'] === $recipient_type;
});
}
/**
* Get events by category
*
* @param string $category 'orders', 'products', 'customers'
* @return array Filtered events
*/
public static function get_events_by_category($category) {
$all_events = self::get_all_events();
return array_filter($all_events, function($event) use ($category) {
return $event['category'] === $category;
});
}
/**
* Get single event definition
*
* @param string $event_id Event ID
* @param string $recipient_type Recipient type
* @return array|null Event definition or null if not found
*/
public static function get_event($event_id, $recipient_type) {
$all_events = self::get_all_events();
foreach ($all_events as $event) {
if ($event['id'] === $event_id && $event['recipient_type'] === $recipient_type) {
return $event;
}
}
return null;
}
/**
* Check if event exists
*
* @param string $event_id Event ID
* @param string $recipient_type Recipient type
* @return bool
*/
public static function event_exists($event_id, $recipient_type) {
return self::get_event($event_id, $recipient_type) !== null;
}
}