From 8c6502de2f8ec2bd8382cd6945c327d7be400e14 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 28 Jan 2026 05:34:41 +0000
Subject: [PATCH] =Queue cleanup - seems to be working enough to get legacy before and after going!

---
 inc/helpers/crud.php |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/inc/helpers/crud.php b/inc/helpers/crud.php
index fa0bdbb..cd36f41 100644
--- a/inc/helpers/crud.php
+++ b/inc/helpers/crud.php
@@ -4,6 +4,57 @@
 	exit;
 }
 
+use JVBase\managers\Cache;
+
+/**
+ * For whatever reason, after much testing, it seems that
+ *  good ol' WP resets post_parent if you call wp_update_post
+ *  without explicitly setting the post_parent
+ * This is a wrapper that grabs old data and merges it with
+ *   what we're trying to update - reducing repetition
+ * @param array $postArr as in wp_update_post
+ * @param array $allowOverride an array of keys that are allowed to be overridden
+ * @return int|WP_Error
+ */
+function jvb_update_post(array $postArr, array $allowOverride = []) {
+	if (empty($postArr['ID'])) {
+		return new WP_Error('missing_id', 'Post ID is required');
+	}
+
+	$old = get_post($postArr['ID'], ARRAY_A);
+	if (!$old) {
+		return new WP_Error('invalid_id', 'Post not found');
+	}
+	/**
+	 * WARNING: You won't want to override fields like:
+	 * guid
+	 * filter
+	 * ancestors
+	 * post_category
+	 * tags_input
+	 * to_ping
+	 * pinged
+	**/
+	$preserveFields = [
+		'post_parent', 'menu_order',
+		'post_status', 'post_password', 'comment_status', 'ping_status',
+		'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt',
+		'post_name', 'post_title', 'post_excerpt', 'post_content',
+		'post_author'
+	];
+	// Remove fields we explicitly want to override
+	$preserveFields = array_diff($preserveFields, $allowOverride);
+
+	// Keep only preserved fields from old post
+	$old = array_intersect_key($old, array_flip($preserveFields));
+
+	// Merge old → new (new wins)
+	$merged = array_merge($old, $postArr);
+	$merged['ID'] = (int)$postArr['ID'];
+
+	return wp_update_post($merged, true);
+}
+
 /**
  * Outputs the blocks of a CRUD management in backend
  * Mainly used in news.php so far
@@ -166,7 +217,7 @@
  */
 function jvbRenderDateFilter(string $content):string
 {
-    $cache = new JVBase\Managers\CacheManager('date_filter');
+    $cache = Cache::for('date_filter')->connect('post', true);
     $check = $cache->get($content);
     if ($check) {
         return $check;

--
Gitblit v1.10.0