From bf69b2c2daeb2d5c1f9b1b3dfe99bfb62a739a9a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 10 Feb 2026 02:42:15 +0000
Subject: [PATCH] =more CRUDSkeleton

---
 inc/meta/Storage.php |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/inc/meta/Storage.php b/inc/meta/Storage.php
index 30160a9..e8216d7 100644
--- a/inc/meta/Storage.php
+++ b/inc/meta/Storage.php
@@ -429,6 +429,11 @@
 			return set_post_thumbnail($item->id, $value) !== false;
 		}
 
+		// Special handling for post_status (trash/delete require specific functions)
+		if ($item->objectType === 'post' && $name === 'post_status') {
+			return $this->updatePostStatus($item->id, $value);
+		}
+
 		return match ($item->objectType) {
 			'post' => wp_update_post(['ID' => $item->id, $name => $value]) !== 0,
 			'term' => !is_wp_error(wp_update_term($item->id, $item->wpObject->taxonomy, [
@@ -440,6 +445,55 @@
 		};
 	}
 
+	/**
+	 * Update post status with proper WordPress functions
+	 *
+	 * WordPress doesn't handle trash/delete via wp_update_post():
+	 * - wp_trash_post() required for trashing
+	 * - wp_delete_post() required for deletion
+	 * - 'delete' is not even a valid post_status value
+	 *
+	 * @param int $postId Post ID
+	 * @param string $status New status (trash, delete, publish, draft, etc.)
+	 * @return bool Success
+	 */
+	protected function updatePostStatus(int $postId, string $status): bool
+	{
+		// Handle trash status
+		if ($status === 'trash') {
+			$result = wp_trash_post($postId);
+			if ($result === false || $result === null) {
+				error_log("[Storage] Failed to trash post {$postId}");
+				return false;
+			}
+			return true;
+		}
+
+		// Handle permanent deletion
+		if ($status === 'delete') {
+			$result = wp_delete_post($postId, true); // true = force delete, bypass trash
+			if ($result === false || $result === null) {
+				error_log("[Storage] Failed to delete post {$postId}");
+				return false;
+			}
+			return true;
+		}
+
+		// Handle all other statuses (publish, draft, pending, private, future)
+		$result = wp_update_post([
+			'ID' => $postId,
+			'post_status' => $status
+		]);
+
+		if ($result === 0 || is_wp_error($result)) {
+			$error = is_wp_error($result) ? $result->get_error_message() : 'Unknown error';
+			error_log("[Storage] Failed to update post {$postId} status to {$status}: {$error}");
+			return false;
+		}
+
+		return true;
+	}
+
 	protected function saveTaxonomyField(Item $item, Field $field): bool
 	{
 		$taxonomy = jvbCheckBase($field->config['taxonomy']);

--
Gitblit v1.10.0