fix: Restore actually works now — handler was checking wrong $_POST key (v3.4.2)
v3.4.1 added a redirect to the Restore handler thinking that was the missing piece. It wasn't — the entire if-block was dead code. The per-row Restore form in inc/wp-notes-display.php sends a hidden $_POST['note_id'] (singular) when clicked. The handler in wp_notes_page_callback() was checking for $_POST['done_ids'] (plural), an array of IDs from bulk-action checkboxes that were removed back in v3.1.0. The mismatch meant the handler's isset($_POST['done_ids']) guard was always false → handler body never ran → clicking Restore was a no-op all the way back to v3.1.0. Pre-v3.4.0 this was masked because the page re-rendered with both Active and Completed sections visible, so users might assume they'd misclicked. v3.4.0's single-pane tab render made the no-op symptom unmissable; v3.4.1's redirect was a phantom fix because it lived inside the unreachable block. Fix: rewrite the handler to match the working single-note mark-done handler pattern that lives directly above it — isset(note_id), absint, isset($done_notes[$note_id]) lookup, move with restored_by annotation, redirect to Active tab. Adds a load-bearing comment recording the bug history so future- Claude doesn't reintroduce the dead-code structure. Lesson recorded in the changelog: when a handler appears to "do nothing", verify the $_POST keys match BEFORE assuming the issue is downstream (missing redirect, failed update, etc.).
This commit is contained in:
@@ -9,6 +9,42 @@ Format: [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/) — versi
|
||||
|
||||
---
|
||||
|
||||
## [3.4.2] — 2026-05-27
|
||||
|
||||
### Fixed — Restore actually works now (v3.4.1 was incomplete)
|
||||
|
||||
David retested after v3.4.1 and reported the same symptom: *"the restore still not working."*
|
||||
|
||||
Root cause (the real one): the per-row Restore form in `inc/wp-notes-display.php` sends a hidden `$_POST['note_id']` (singular) when the button is clicked — but the handler in `wp_notes_page_callback()` was checking for `$_POST['done_ids']` (plural), an array of IDs that used to come from bulk-action checkboxes **removed in v3.1.0**. So the handler's `isset($_POST['done_ids'])` guard was always false, the handler body never ran, and clicking Restore was a no-op all the way back to v3.1.0. The bug was masked before v3.4.0 because the page re-rendered with both Active and Completed sections visible, so the user could see the (unchanged) completed note still sitting there and assume they'd misclicked. v3.4.0's single-pane render made the no-op symptom unmissable.
|
||||
|
||||
The v3.4.1 redirect added inside the handler was syntactically correct but never reached — the entire `if` block was dead code.
|
||||
|
||||
Fix: rewrite the handler to match the working **single-note** mark-done handler pattern that lives just above it:
|
||||
|
||||
- Check `isset($_POST['note_id'])` (singular) instead of `done_ids` (plural array)
|
||||
- `absint()` the ID for sanitization
|
||||
- `isset($done_notes[$note_id])` lookup instead of iterating with `in_array()`
|
||||
- Move the note across with the existing `restored_by` annotation
|
||||
- Keep the redirect-to-Active-tab from v3.4.1
|
||||
|
||||
The handler now mirrors the pattern of the mark-done handler that's been working all along.
|
||||
|
||||
### Why this took two attempts to fix
|
||||
|
||||
v3.4.1's diagnosis stopped at the missing redirect — which was real but not load-bearing because the handler body was unreachable. Lesson recorded: when a handler appears to "do nothing", verify it's being entered at all (matching `$_POST` keys) before assuming the issue is downstream (missing redirect, failed update, etc.).
|
||||
|
||||
### Files changed
|
||||
|
||||
- `wp-notes.php` — Restore handler rewritten (lines around 1340). The change replaces the old bulk-checkbox-era handler with a single-note handler matching the live form. Adds a load-bearing comment block recording the v3.4.1/v3.4.2 bug history so future-Claude understands why the structure mirrors mark-done.
|
||||
- Plugin header `Version: 3.4.1 → 3.4.2`; `WP_NOTES_VERSION` constant updated to match. PATCH bump (bug fix).
|
||||
|
||||
### Not changed
|
||||
|
||||
- The display code in `inc/wp-notes-display.php` — the form was already correct; the handler was the one out of sync.
|
||||
- The Active and Completed tabs, storage model, CSS, other handlers — all unchanged.
|
||||
|
||||
---
|
||||
|
||||
## [3.4.1] — 2026-05-27
|
||||
|
||||
### Fixed — Restore button now sends you to the Active tab where the restored note lives
|
||||
|
||||
Reference in New Issue
Block a user