From 4089ba01e0881c89a72332e13bc3a80b6bddec2a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 29 Jun 2026 22:15:55 +0000
Subject: [PATCH] =DashboardManager overhaul. A bit easier to modify the output of pages. Still have to get the account pages to work as expected, as well as verify the integrations and others are working - but registrar/content pages work as expected. Also fixed up the table generation in CRUD.js and CRUDSkeleton.php

---
 inc/meta/Meta.php |   32 +++++++++++---------------------
 1 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/inc/meta/Meta.php b/inc/meta/Meta.php
index 796ebe9..8f83f18 100644
--- a/inc/meta/Meta.php
+++ b/inc/meta/Meta.php
@@ -89,17 +89,17 @@
 	 * Constructor
 	***************************************************************/
 
-	public function __construct(int|string|null $id, string $type)
+	public function __construct(int|string|null $id, string $type, array $fields = [])
 	{
 		$this->validator = new Validator();
 		$this->sanitizer = new Sanitizer();
 		$this->typeManager = new MetaTypeManager();
 		$this->type = $type;
 		$this->ID = $id;
-		$this->buildData($id, $type);
+		$this->buildData($id, $type, $fields);
 	}
 
-	protected function buildData(int|string|null $id, string $type):void
+	protected function buildData(int|string|null $id, string $type, array $fields):void
 	{
 		$this->wpObject = match($type) {
 			'post' 	=> get_post($id),
@@ -115,10 +115,9 @@
 			default => null
 		};
 
-
-
 		$registrar = !is_null($this->slug) ? Registrar::getInstance($this->slug) : false;
-		$fields = $registrar ? $registrar->getFields() : [];
+		$fields = $registrar ? $registrar->getFields() : $fields;
+
 		if ($this->type == 'option') {
 			$options = Options::getInstance();
 			$fields = $options->getFields();
@@ -133,15 +132,18 @@
 			$meta = [];
 		}
 		$meta = array_map(fn($value) => maybe_unserialize($value[0]), $meta);
-
+		$this->fields = [];
 		foreach ($fields as $fieldName => $config) {
 			$fieldName = jvbNoBase($fieldName);
 			if ($this->type === 'option') {
 				$value = get_option(BASE . $fieldName, $config['default'] ?? '');
-			} else if ($this->wpObject && property_exists($this->wpObject, $fieldName)) {
+			} else if (
+				$this->wpObject && property_exists($this->wpObject, $fieldName)
+				|| $type === 'user' && $this->wpObject && property_exists($this->wpObject->data, $fieldName)) {
 				$config['wp'] = true;
 				$value = $this->wpObject->$fieldName;
-			} else if (in_array($fieldName, $this->defaults)) {
+
+			}  else if (in_array($fieldName, $this->defaults)) {
 				$config['wp'] = true;
 				switch ($fieldName) {
 					case 'post_thumbnail':
@@ -252,11 +254,6 @@
 			$this->save();
 		}
 
-
-		if ($this->type === 'option') {
-			error_log('Value saved for: '.$name.': '.print_r($value, true));
-		}
-
 		return $this;
 	}
 
@@ -372,12 +369,6 @@
 			foreach ($custom as $field) {
 				if ($this->type === 'option') {
 					$result = update_option(BASE.$field->name, $field->value);
-					if ($result) {
-						error_log('Option '.$field->name.' updated');
-					} else {
-						error_log('Option '.$field->name.' not updated');
-					}
-					error_log('Update option '.$field->name.' result: '.print_r($result, true));
 				} else {
 					$result = $function($this->ID, BASE.$field->name, $field->value);
 				}
@@ -450,7 +441,6 @@
 
 	protected function setByPath(string $path, mixed $value): self
 	{
-		error_log('Setting by path: '.$path.', with value: '.print_r($value, true));
 		$parts = explode(':', $path, 3);
 		if (count($parts) !== 3) {
 			return $this;

--
Gitblit v1.10.0