From 8d0e2130627497b55b1a61cbe374bfb309ef2f27 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 01 Jan 2026 23:04:26 +0000
Subject: [PATCH] Merge branch 'main' of https://github.com/jakevdwerf/jvb
---
inc/meta/MetaManager.php | 46 ++++++++++++++++++++++++++++++++++------------
1 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/inc/meta/MetaManager.php b/inc/meta/MetaManager.php
index 7ed3bc6..57b8076 100644
--- a/inc/meta/MetaManager.php
+++ b/inc/meta/MetaManager.php
@@ -19,11 +19,14 @@
public MetaForm $form;
protected int|null $object_id;
public object|null $data;
+ protected array $fields =[];
protected string $field;
protected mixed $value;
protected string|null $object_type;
protected int $max_file_size = 5242880;
protected ?string $content = null;
+
+ protected ?string $baseKey = null;
protected \wpdb $wpdb;
protected array $postFields = [
'post_title',
@@ -48,12 +51,11 @@
'description'
];
- public function __construct(?int $ID = null, ?string $type = null, ?string $content = null)
+ public function __construct(int|string|null $ID = null, ?string $type = null, ?string $content = null)
{
global $wpdb;
$this->wpdb = $wpdb;
- $this->object_id = $ID;
-
+ $this->object_id = is_int($ID) ? $ID : null;
$this->object_type = $type;
if ($ID) {
switch ($type) {
@@ -67,6 +69,10 @@
case 'integrations':
$this->data = get_user($ID);
break;
+ case 'options':
+ $this->baseKey = $ID;
+ $this->data = null;
+ break;
default:
$this->data = null;
break;
@@ -145,7 +151,10 @@
case 'integrations':
return get_user_meta($this->object_id, $meta_key, true);
case 'options':
- return get_option($meta_key);
+ $key = $this->baseKey
+ ? BASE . $this->baseKey . '_' . $name
+ : BASE . $name;
+ return get_option($key);
default:
return '';
}
@@ -332,11 +341,7 @@
}
}
if ($field_config['type'] == 'taxonomy' && (!array_key_exists('taxonomy_type', $field_config))) {
- error_log('Attempting to set taxonomies: ' . print_r($this->object_id, true));
- error_log('Sanitized data: ' . print_r($sanitized, true));
- error_log('Taxonomy: ' . print_r($field_config['taxonomy'], true));
$set = wp_set_post_terms($this->object_id, $sanitized, jvbCheckBase($field_config['taxonomy']), false);
- error_log('Set post terms: ' . print_r($set, true));
}
if ($field_config['type'] === 'location' && empty($sanitized)) {
$this->addMeta('has_map', false);
@@ -357,7 +362,10 @@
$result = update_user_meta($this->object_id, $meta_key, $sanitized);
break;
case 'options':
- $result = update_option($meta_key, $sanitized);
+ $key = $this->baseKey
+ ? BASE . $this->baseKey . '_' . $name
+ : BASE . $name;
+ return update_option($key, $sanitized);
}
if ($result === false) {
@@ -502,6 +510,10 @@
protected function getFields(): array
{
+ if (!empty($this->fields)) {
+ return $this->fields;
+ }
+ $type = false;
switch ($this->object_type) {
case 'post':
$type = get_post_type((int)$this->object_id);
@@ -515,6 +527,9 @@
case 'options':
return jvbGetFields('options');
}
+ if (!$type) {
+ return [];
+ }
return jvbGetFields($type, $this->object_type);
}
@@ -542,6 +557,7 @@
protected function getSections():array
{
+ $type = false;
switch ($this->object_type) {
case 'post':
$type = get_post_type((int)$this->object_id);
@@ -601,6 +617,11 @@
}
}
+ public function setFieldConfig(array $fields):void
+ {
+ $this->fields = $fields;
+ }
+
protected function getFieldConfig(string $name):array|false
{
$fields = $this->getFields();
@@ -749,7 +770,7 @@
}
- echo (jvbCheck('submit', $options)) ? '<button type="submit">'.jvbIcon('save').'Save</button>' : '';
+ echo (jvbCheck('submit', $options)) ? '<button type="submit">'.jvbIcon('floppy-disk').'Save</button>' : '';
echo '</form>';
$out = ob_get_clean();
@@ -793,7 +814,7 @@
$out = '<p class="'.$name.'">'.jvbIcon('calendar').'<span></span></p>';
break;
case 'time':
- $out = '<p class="'.$name.'">'.jvbIcon('time').'<time></time></p>';
+ $out = '<p class="'.$name.'">'.jvbIcon('clock').'<time></time></p>';
break;
case 'true_false':
$out = '<p class="'.$name.'"></p>';
@@ -1006,7 +1027,8 @@
}
if ($field_config['type'] === 'taxonomy' && !array_key_exists('taxonomy_type', $field_config)){
- $set = wp_set_post_terms($this->object_id, $sanitized, jvbCheckBase($field_config['taxonomy']), false);
+ $term_ids = array_map('intval', explode(',', trim($sanitized)));
+ $set = wp_set_post_terms($this->object_id, $term_ids, jvbCheckBase($field_config['taxonomy']), false);
}
if ($field_config['type'] === 'location' && empty($sanitized)) {
--
Gitblit v1.10.0