From d7e7d248cbe41cd7a9ef9c2fb022b6c4831f99a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 31 May 2026 15:22:56 +0000
Subject: [PATCH] =jakevan complete

---
 inc/meta/Meta.php |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/inc/meta/Meta.php b/inc/meta/Meta.php
index a32c545..35a8c3d 100644
--- a/inc/meta/Meta.php
+++ b/inc/meta/Meta.php
@@ -17,9 +17,9 @@
 	 */
 	protected string $type;
 	/**
-	 * @var string the full slug, with BASE
+	 * @var ?string the full slug, with BASE
 	 */
-	protected string $slug;
+	protected ?string $slug;
 
 	protected string $contentType;
 	protected Item $item;
@@ -27,7 +27,7 @@
 	protected Validator $validator;
 	protected Sanitizer $sanitizer;
 	protected array $fields;
-	protected WP_Post|WP_Term|WP_User|null $wpObject;
+	protected WP_Post|WP_Term|WP_User|false|null $wpObject;
 	protected int|string $ID;
 	protected MetaTypeManager $typeManager;
 	protected static array $instances = ['post' => [],'term' => [], 'user'=>[],'options'=>[]];
@@ -104,11 +104,8 @@
 			'post' 	=> get_post($id),
 			'term'	=> get_term($id),
 			'user', 'integrations' => get_userdata($id),
-			default => null
+			default => false
 		};
-		if (!$this->wpObject){
-			return;
-		}
 
 		$this->slug = match($type) {
 			'post'	=> $this->wpObject->post_type,
@@ -119,7 +116,7 @@
 
 
 
-		$registrar = Registrar::getInstance($this->slug);
+		$registrar = !is_null($this->slug) ? Registrar::getInstance($this->slug) : false;
 		$fields = $registrar ? $registrar->getFields() : [];
 		$meta = match($type) {
 			'post'	=> get_post_meta($id),
@@ -127,6 +124,9 @@
 			'user'	=> get_user_meta($id),
 			default => []
 		};
+		if (!$meta) {
+			$meta = [];
+		}
 		$meta = array_map(fn($value) => maybe_unserialize($value[0]), $meta);
 
 		foreach ($fields as $fieldName => $config) {
@@ -195,8 +195,15 @@
 		if (str_contains($name, ':')) {
 			return $this->getByPath($name);
 		}
-
-		return $this->fields[$name]->get();
+		if (!array_key_exists($name, $this->fields)) {
+			error_log('[Meta]::get Attempted to get unregistered field: '.$name);
+			return '';
+		}
+		if (is_null($this->fields[$name])) {
+			error_log('[Meta]::get Field does not seem to be setup yet: '.$name);
+			return '';
+		}
+		return $this->fields[$name]->get()??'';
 	}
 
 	/**
@@ -254,7 +261,6 @@
 	public function setAll(array $data):bool
 	{
 		foreach ($data as $name => $value) {
-			error_log('Setting '.$name.' with value: '.print_r($value, true));
 			$this->set($name, $value, false);
 		}
 		return $this->save();
@@ -316,12 +322,12 @@
 					}
 					break;
 				case 'term':
-					$result = wp_update_term($this->ID, $this->slug, $defaults);
+					$termDefaults = array_map(fn($field) => $field->value, $defaults);
+					$result = wp_update_term($this->ID, $this->slug, $termDefaults);
 					break;
 				case 'user':
-					$data = array_merge([
-						'ID'	=> $this->ID
-					], $defaults);
+					$userDefaults = array_map(fn($field) => $field->value, $defaults);
+					$data = array_merge(['ID' => $this->ID], $userDefaults);
 					$result = wp_update_user($data);
 					break;
 			}
@@ -347,9 +353,10 @@
 					error_log('Problem saving field: '.$field->name.' with value: '.print_r($field->value, true));
 				}
 			}
-			if ($this->type === 'term' && Registrar::getInstance($this->slug)->hasFeature('is_content')) {
-				update_term_meta($this->ID, BASE.'date_modified', date('Y-m-d H:i:s'));
-			}
+			//Now handled directly from Registrar
+//			if ($this->type === 'term' && Registrar::getInstance($this->slug)->hasFeature('is_content')) {
+//				update_term_meta($this->ID, BASE.'date_modified', date('Y-m-d H:i:s'));
+//			}
 		}
 
 

--
Gitblit v1.10.0