dwindown
a9ff8e2cea
fix: Channel toggle and event defaults issues
## 🐛 Critical Fixes
### Issue 1: Toggle Refuses to Disable
**Problem:** Channels always return `enabled: true` even after toggling off
**Root Cause:** Response didn't include actual saved state
**Fix:** Added verification and return actual state in response
**Changes:**
```php
// Update option
update_option($option_key, (bool) $enabled, false);
// Verify the update
$verified = get_option($option_key);
// Return verified state
return [
'channelId' => $channel_id,
'enabled' => (bool) $verified,
];
```
### Issue 2: Wrong Event Channel Defaults
**Problem:**
- Email showing as enabled by default in frontend
- Push showing as disabled in frontend
- Mismatch between frontend and backend
**Root Cause:**
1. Wrong path: `$settings['event_id']` instead of `$settings['event_id']['channels']`
2. Defaults set to `true` instead of `false`
**Fix:**
```php
// Before
'channels' => $settings['order_placed'] ?? ['email' => ['enabled' => true, ...]]
// After
'channels' => $settings['order_placed']['channels'] ?? [
'email' => ['enabled' => false, 'recipient' => 'admin'],
'push' => ['enabled' => false, 'recipient' => 'admin']
]
```
### What Was Fixed
1. ✅ Channel toggle now saves correctly
2. ✅ Response includes verified state
3. ✅ Event channels default to `false` (disabled)
4. ✅ Both email and push included in defaults
5. ✅ Correct path to saved settings
6. ✅ Consistent behavior across all events
### Testing
- [ ] Toggle email off → stays off
- [ ] Toggle push off → stays off
- [ ] Reload page → state persists
- [ ] Events page shows correct defaults (all disabled)
- [ ] Enable per-event channel → saves correctly
---
**Toggles should now work properly!** ✅
2025-11-11 15:57:01 +07:00
..
2025-11-11 10:43:03 +07:00
2025-11-05 10:02:40 +07:00
2025-11-10 12:23:44 +07:00
2025-11-10 22:41:18 +07:00
2025-11-09 23:44:24 +07:00
2025-11-11 15:57:01 +07:00
2025-11-10 18:56:41 +07:00
2025-11-06 14:05:18 +07:00
2025-11-04 18:08:00 +07:00
2025-11-09 23:44:24 +07:00
2025-11-11 12:11:08 +07:00
2025-11-10 10:16:51 +07:00
2025-11-11 10:12:30 +07:00
2025-11-10 22:41:18 +07:00
2025-11-10 14:09:52 +07:00