From 01e9a8e40351a87f6548a4f55de842d6f6918ad0 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 15 Sep 2026 02:44:28 +0000
Subject: [PATCH] =Found little glitch with auto-adding rewrite rules to taxonomy Registrar instances where we have the post type as the base in the url rewrite
---
inc/meta/Storage.php | 61 ++++++++++++++++++------------
1 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/inc/meta/Storage.php b/inc/meta/Storage.php
index 74538ff..433b478 100644
--- a/inc/meta/Storage.php
+++ b/inc/meta/Storage.php
@@ -3,6 +3,8 @@
use Exception;
use JVBase\managers\Cache;
+use JVBase\managers\Errors;
+use wpdb;
if (!defined('ABSPATH')) {
exit;
@@ -10,11 +12,10 @@
/**
* Handles persistence of meta values to WordPress
- * Pure storage layer - no validation or sanitization
*/
class Storage
{
- protected \wpdb $wpdb;
+ protected wpdb $wpdb;
public function __construct()
{
@@ -77,7 +78,7 @@
&& (
($config['type'] ?? '') === 'taxonomy'
|| (($config['type']??'') === 'selector' && ($config['subtype']??'') === 'taxonomy')
- ) && !isset($config['taxonomy_type'])) {
+ ) && (!isset($config['taxonomy_type']) || !isset($config['isReference']))) {
$taxonomyFields[$name] = $config;
} else {
$metaFields[] = $name;
@@ -123,18 +124,21 @@
}
if ($field->isTaxonomy()) {
+ error_log('Saving Taxonomy field with set_object_terms');
return $this->saveTaxonomyField($item, $field);
}
$metaKey = BASE . $field->name;
-
- return match ($item->objectType) {
- 'post' => update_post_meta($item->id, $metaKey, $field->value) !== false,
- 'term' => update_term_meta($item->id, $metaKey, $field->value) !== false,
- 'user', 'integrations' => update_user_meta($item->id, $metaKey, $field->value) !== false,
+ $result = match ($item->objectType) {
+ 'post' => (bool)update_post_meta($item->id, $metaKey, $field->value),
+ 'term' => (bool)update_term_meta($item->id, $metaKey, $field->value),
+ 'user', 'integrations' => (bool)update_user_meta($item->id, $metaKey, $field->value),
'options' => $this->saveOption($item, $field),
default => false
};
+
+ error_log('Result: '.print_r($result, true));
+ return $result;
}
/**
@@ -149,10 +153,10 @@
}
$this->wpdb->query('START TRANSACTION');
-
try {
foreach ($dirty as $field) {
if (!$this->saveField($item, $field)) {
+ error_log("Could not save field: {$field->name}");
throw new Exception("Failed to save field: {$field->name}");
}
$field->markClean();
@@ -161,18 +165,17 @@
$this->wpdb->query('COMMIT');
// Update post modified timestamp
- Cache::invalidateItem($item->objectType, $item->id);
$this->clearCache($item);
return true;
} catch (Exception $e) {
$this->wpdb->query('ROLLBACK');
- JVB()->error()->log('meta_storage', $e->getMessage(), [
+ Errors::getInstance()->log('meta_storage', $e->getMessage(), [
'item_id' => $item->id,
'object_type' => $item->objectType,
'fields' => array_keys($dirty)
- ], 'error');
+ ]);
return false;
}
}
@@ -186,7 +189,7 @@
$config = $item->getFieldConfig($name);
if ($config && ($config['type'] ?? '') === 'taxonomy' && !isset($config['taxonomy_type'])) {
$taxonomy = jvbCheckBase($config['taxonomy']);
- wp_set_object_terms($item->id, [], $taxonomy, false);
+ wp_set_object_terms($item->id, [], $taxonomy);
return true;
}
@@ -324,7 +327,7 @@
$results[$meta->item()->id ?? 'options'] = false;
}
- JVB()->error()->log('meta_storage', 'Bulk save failed: ' . $e->getMessage(), [], 'error');
+ Errors::getInstance()->log('meta_storage', 'Bulk save failed: ' . $e->getMessage());
return $results;
}
@@ -440,7 +443,7 @@
protected function getTermField(Item $item, string $name): mixed
{
return match ($name) {
- 'term_name' => get_term_field('name', $item->id),
+ 'name' => get_term_field('name', $item->id),
'description' => get_term_field('description', $item->id),
default => ''
};
@@ -538,14 +541,13 @@
{
$taxonomy = jvbCheckBase($field->config['taxonomy']);
$value = $field->value;
-
if (empty(trim((string)$value))) {
- wp_set_object_terms($item->id, [], $taxonomy, false);
+ wp_set_object_terms($item->id, [], $taxonomy);
return true;
}
$termIds = array_map('intval', array_filter(explode(',', $value)));
- $result = wp_set_object_terms($item->id, $termIds, $taxonomy, false);
+ $result = wp_set_object_terms($item->id, $termIds, $taxonomy);
return !is_wp_error($result);
}
@@ -608,12 +610,21 @@
public function clearCache(Item $item): void
{
- match ($item->objectType) {
- 'post' => clean_post_cache($item->id),
- 'term' => clean_term_cache($item->id),
- 'user', 'integrations' => clean_user_cache($item->id),
- default => null
- };
+ switch ($item->objectType) {
+ case 'post':
+ Cache::clearPost($item->id);
+ clean_post_cache($item->id);
+ break;
+ case 'term':
+ Cache::clearTerm($item->id);
+ clean_term_cache($item->id);
+ break;
+ case 'user':
+ case 'integrations':
+ Cache::clearUser($item->id);
+ clean_user_cache($item->id);
+ break;
+ }
}
// ─────────────────────────────────────────────────────────────
@@ -723,7 +734,7 @@
? []
: array_map('intval', array_filter(explode(',', $update['value'])));
- wp_set_object_terms($update['object_id'], $termIds, $update['taxonomy'], false);
+ wp_set_object_terms($update['object_id'], $termIds, $update['taxonomy']);
}
}
--
Gitblit v1.10.0