Jake Vanderwerf
2026-09-04 c16a4d78d07e81ecdd2ff9b1b9090560ab2fe488
inc/meta/Storage.php
@@ -3,6 +3,8 @@
use Exception;
use JVBase\managers\Cache;
use JVBase\managers\Errors;
use wpdb;
if (!defined('ABSPATH')) {
   exit;
@@ -13,7 +15,7 @@
 */
class Storage
{
   protected \wpdb $wpdb;
   protected wpdb $wpdb;
   public function __construct()
   {
@@ -163,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;
      }
   }
@@ -188,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;
      }
@@ -326,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;
      }
@@ -541,12 +542,12 @@
      $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);
   }
@@ -609,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;
      }
   }
   // ─────────────────────────────────────────────────────────────
@@ -724,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']);
      }
   }