From 32ce5c542c90be348895328078e392dde2052957 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 04 Sep 2026 19:15:16 +0000
Subject: [PATCH] =Working at adding defined fields to a dedicated panel in the gutenberg editor. Registrar now has AddCustomFields.php, which currently only supports post fields. Added a @wordpress/plugins base _meta/fields in /build and /src that successfully creates a panel. Next steps: determine sections and fields, group fields by section (each section to a panel), and save output
---
inc/meta/Meta.php | 45 ++++++++++++++++++++++++++++++++++++---------
1 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/inc/meta/Meta.php b/inc/meta/Meta.php
index c0454a6..a9412c5 100644
--- a/inc/meta/Meta.php
+++ b/inc/meta/Meta.php
@@ -1,6 +1,7 @@
<?php
namespace JVBase\meta;
+use JVBase\base\options;
use JVBase\managers\Cache;
use JVBase\registrar\Registrar;
@@ -25,6 +26,7 @@
* @var array of Registrar's defined fields, if any
*/
protected static array $registrars = [];
+ protected static ?options $options = null;
/**
* @var array Field values, stored in memory
*/
@@ -60,6 +62,9 @@
self::$registrars[$this->content] = $registrar->getFields();
}
}
+ if ($this->objectType === 'options' && !isset(self::$options)) {
+ self::$options = options::getInstance();
+ }
if ($this->objectType === 'post' && function_exists('wc_get_product') && in_array($this->content, ['product', 'product_variation'], true)) {
$this->product = wc_get_product($this->ID) ?: null;
@@ -210,10 +215,13 @@
public function set(string $name, mixed $value): bool {
$field = $this->getFieldConfig($name);
if ($field) {
- if ($field['type']??'' === 'repeater' && str_contains($name, ':')) {
- return $this->setByPath($name, $value);
- } elseif ($field['type']??'' === 'group' && str_contains($name, '|')) {
- return $this->setGroup($name, $value);
+ if (array_key_exists('type', $field)) {
+ if ($field['type'] === 'repeater' && str_contains($name, ':')) {
+ $this->log('Setting by path in set');
+ return $this->setByPath($name, $value);
+ } elseif ($field['type'] === 'group' && str_contains($name, '|')) {
+ return $this->setGroup($name, $value);
+ }
}
if (!self::$validator->validate($value, $field)) {
@@ -407,7 +415,7 @@
* WOOCOMMERCE PRODUCT SPECIFIC
**************************************************************/
protected function isProductField(string $name): bool {
- return method_exists($this->product, 'get_'.$name) || method_exists($this->product, 'set_'.$name);
+ return $name === 'variations' || method_exists($this->product, 'get_'.$name) || method_exists($this->product, 'set_'.$name);
}
protected function getProductField(string $name): mixed {
@@ -422,7 +430,7 @@
$variations = $this->product->get_children();
$out = [];
foreach ($variations as $v) {
- $out[] = self::forPost($v)->getAll();
+ $out[] = array_merge(['id' => $v], self::forPost($v)->getAll());
}
return $out;
}
@@ -442,8 +450,14 @@
return [
'price',
'sku',
- 'sale',
+ 'sale_price',
+ 'regular_price',
+ 'date_on_sale_from',
+ 'date_on_sale_to',
+ 'max_purchase_quantity',
+ 'min_purchase_quantity',
'short_description',
+ 'description',
'image_id',
'gallery_image_ids',
'stock',
@@ -505,9 +519,13 @@
}
protected function setByPath(string $path, mixed $value):bool
{
+ if (!str_contains($path, ':')) {
+ $this->log('setByPath called without appropriate string (:)');
+ return $this->set($path, $value);
+ }
$parts = explode(':', $path, 3);
if (count($parts) !== 3) {
- $this->log('Could not set value by path');
+ $this->log('Could not set value by path: '.$path.', with value: '.print_r($value, true));
return false;
}
[$repeaterName, $rowIndex, $subField] = $parts;
@@ -536,6 +554,10 @@
protected function setGroup(string $name, mixed $value):bool
{
+ if (!str_contains($name, '|')) {
+ $this->log('setGroup called without appropriate key (|)');
+ return $this->set($name, $value);
+ }
[$parent, $child] = explode('|', $name, 2);
$this->clearCache();
return $this->group($parent)->set($child, $value);
@@ -571,13 +593,18 @@
protected function hasRegistrar():bool
{
- return array_key_exists($this->content, self::$registrars);
+ return !is_null($this->content) && array_key_exists($this->content, self::$registrars);
}
public function getFieldConfig(string $name): ?array {
+ if ($this->objectType === 'options') return $this->getOptionsConfig($name);
if (!$this->hasRegistrar()) return null;
return self::$registrars[$this->content][$name] ?? null;
}
+ protected function getOptionsConfig(string $name):?array
+ {
+ return self::$options->getConfig($name);
+ }
protected function getCoreDefault(string $name):string
{
--
Gitblit v1.10.0