fix: menu rollback survives a throwing delete of a new item (S50)

MenuWriter::fail guards wp_delete_post for created items: the touched items
are still restored and the client gets partial_write (with previous_items)
instead of internal_error.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 18:35:21 +02:00
co-authored by Claude Opus 5.5
parent eda592548e
commit 267e5d2076
2 changed files with 38 additions and 2 deletions
@@ -431,8 +431,13 @@ class MenuWriter
{
$problems = [];
foreach ($this->created as $itemId) {
if (! wp_delete_post($itemId, true) instanceof WP_Post) {
$problems[] = sprintf('created item %d not deleted', $itemId);
// Ruling S50: a throwing delete (e.g. a hook) must not stop the rest of the rollback.
try {
if (! wp_delete_post($itemId, true) instanceof WP_Post) {
$problems[] = sprintf('created item %d not deleted', $itemId);
}
} catch (Throwable $e) {
$problems[] = sprintf('created item %d not deleted: %s', $itemId, $e->getMessage());
}
}