| | |
| | | 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, [ |
| | |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * 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']); |