From f94860aacd6200fb24c9e7431eb379a368cb392d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 10 Jul 2026 00:35:44 +0000
Subject: [PATCH] =Refactored CredentialsManager.php to utilize a CustomTable instance instead
---
inc/registrar/Fields.php | 390 +++++++++++++++++++++++++++++++------------------------
1 files changed, 221 insertions(+), 169 deletions(-)
diff --git a/inc/registrar/Fields.php b/inc/registrar/Fields.php
index ada4615..f9668f2 100644
--- a/inc/registrar/Fields.php
+++ b/inc/registrar/Fields.php
@@ -1,6 +1,10 @@
<?php
namespace JVBase\registrar;
+use JVBase\managers\SEO\render\Thing\Organization\LocalBusiness\LocalBusiness;
+use JVBase\managers\SEO\render\Thing\Thing;
+use JVBase\meta\Form;
+use JVBase\meta\Meta;
use JVBase\registrar\fields\Field;
use JVBase\registrar\fields\GroupedField;
use JVBase\registrar\fields\OptionsField;
@@ -15,19 +19,26 @@
class Fields {
protected array $fields;
- protected Registrar $registrar;
+ private ?Registrar $registrar = null;
+ protected ?string $type;
public function __construct(?string $type = null, ?Registrar $registrar = null) {
$this->registrar = $registrar;
+ $this->type = $type;
switch ($type) {
case 'post':
$this->addPostFields();
+ //TODO: Add fields to post edit screen
+// add_action('add_meta_boxes', [$this, 'registerPostFields']);
break;
case 'term':
$this->addTermFields();
break;
case 'user':
$this->addUserFields();
+ if ($registrar->hasAnyIntegrations()) {
+ $this->addIntegrationSetupField();
+ }
break;
}
}
@@ -46,11 +57,64 @@
return $this;
}
- public function addPostFields():void
+ protected function defaultPostFields():array
{
- $fields = [
+ $statuses = [
+// 'all' => [
+// 'icon' => 'infinity',
+// 'label' => 'Everything',
+// ],
+ 'publish' => [
+ 'icon' => 'eye',
+ 'label' => 'Live',
+ ],
+ 'draft' => [
+ 'icon' => 'eye-closed',
+ 'label' => 'Hidden',
+ ],
+ 'trash' => [
+ 'label' => 'Scrapped',
+ 'icon' => 'trash',
+ ],
+// 'delete' => [
+// 'label' => 'Permanently Delete',
+// 'icon' => 'trash'
+// ]
+ ];
+ if ($this->registrar->hasFeature('is_calendar')) {
+ $statuses = [
+ 'future' => [
+ 'icon' => '',
+ 'label' => 'Upcoming',
+ ],
+ 'past' => [
+ 'icon' => '',
+ 'label' => 'Past',
+ ],
+ 'repeat' => [
+ 'icon' => '',
+ 'label' => 'Repeating',
+ ],
+ 'draft' => [
+ 'icon' => 'eye-closed',
+ 'label' => 'Hidden',
+ ],
+ 'trash' => [
+ 'label' => 'Scrapped',
+ 'icon' => 'trash',
+ ],
+ ];
+ }
+ return [
+ 'post_status' => [
+ 'type' => 'radio',
+ 'label' => 'Status',
+ 'default' => 'draft',
+ 'options' => $statuses
+ ],
'post_thumbnail' => [
'type' => 'upload',
+ 'subtype' => 'image',
'multiple'=> false,
'label' => 'Main Image',
],
@@ -58,6 +122,11 @@
'type' => 'datetime',
'label' => 'Date',
],
+ 'post_modified' => [
+ 'type' => 'datetime',
+ 'label' => 'Date Modified',
+ 'hidden' => true,
+ ],
'post_content' => [
'type' => 'textarea',
'quill' => true,
@@ -73,41 +142,19 @@
'label' => 'TLDR',
'maxLength' => 158,
],
- 'post_status' => [
- 'type' => 'radio',
- 'label' => 'Status',
- 'default' => 'draft',
- 'options' => [
- 'all' => [
- 'icon' => 'infinity',
- 'label' => 'Everything',
- ],
- 'publish' => [
- 'icon' => 'eye',
- 'label' => 'Live',
- ],
- 'draft' => [
- 'icon' => 'eye-closed',
- 'label' => 'Hidden',
- ],
- 'trash' => [
- 'label' => 'Scrapped',
- 'icon' => 'trash',
- ],
- 'delete' => [
- 'label' => 'Permanently Delete',
- 'icon' => 'trash'
- ]
- ]
- ]
];
+ }
+
+ public function addPostFields():void
+ {
+ $fields = $this->defaultPostFields();
foreach ($fields as $name => $config) {
$this->addField($name, $config);
}
}
- public function addTermFields():void
+ protected function defaultTermFields():array
{
$fields = [
'name' => [
@@ -129,37 +176,54 @@
'label' => 'Term Parent'
];
}
- foreach ($fields as $name => $config) {
+
+ return $fields;
+ }
+
+ public function addTermFields():void
+ {
+ foreach ($this->defaultTermFields() as $name => $config) {
$this->addField($name, $config);
}
}
- public function addUserFields():void
+ protected function defaultUserFields():array
{
- $fields = [
+ return [
'first_name' => [
'type' => 'text',
'label' => 'First Name',
+ 'section'=> 'your-account'
],
'last_name' => [
'type' => 'text',
'label' => 'Last Name',
+ 'section'=> 'your-account'
+ ],
+ 'user_email' => [
+ 'type' => 'email',
+ 'label' => 'Your Email',
+ 'section'=> 'your-account'
],
'display_name' => [
'type' => 'text',
'label' => 'Display Name',
+ 'section'=> 'your-account'
],
- 'website' => [
- 'type' => 'url',
- 'label' => 'Website',
- ],
- 'description' => [
- 'type' => 'textarea',
- 'quill' => true,
- 'label' => 'Description',
- ]
+// 'website' => [
+// 'type' => 'url',
+// 'label' => 'Website',
+// ],
+// 'description' => [
+// 'type' => 'textarea',
+// 'quill' => true,
+// 'label' => 'Description',
+// ],
];
- foreach ($fields as $name => $config) {
+ }
+ public function addUserFields():void
+ {
+ foreach ($this->defaultUserFields() as $name => $config) {
$this->addField($name, $config);
}
}
@@ -267,159 +331,147 @@
protected function addReviewField(?string $label = null):void
{
- $this->addField(
- 'reviews',
- [
- 'type' => 'repeater',
- 'add_label' => 'name',
- 'label' => $label ?: 'Reviews',
- 'fields' => [
- 'name' => [
- 'type' => 'text',
- 'label' => 'Reviewer Name',
- ],
- 'review' => [
- 'type' => 'textarea',
- 'quill' => false,
- 'label' => 'Review',
- ],
- 'rating' => [
- 'type' => 'select',
- 'label' => 'Rating',
- 'options' => [
- 'none' => 'Not Given',
- '0.5' => '0.5',
- '1' => '1',
- '1.5' => '1.5',
- '2' => '2',
- '2.5' => '2.5',
- '3' => '3',
- '3.5' => '3.5',
- '4' => '4',
- '4.5' => '4.5',
- '5' => '5',
- ],
- 'default' => 'none'
- ],
- 'date' => [
- 'type' => 'date',
- 'label' => 'Date of Review',
- ],
- 'url' => [
- 'type' => 'url',
- 'label' => 'Link to Review (optional)',
- ],
- ],
- 'section' => 'seo'
- ]
- );
+ $biz = new LocalBusiness();
+ $biz->setReviewField($this);
}
protected function addAlternateNameField():void
{
- $this->addField(
- 'alternate_name',
- [
- 'type' => 'repeater',
- 'label' => 'Alternate Name',
- 'fields' => [
- 'name' => [
- 'type' => 'text',
- 'label' => 'Name',
- ]
- ],
- 'section' => 'seo'
- ]
- );
+ $thing = new Thing();
+ $thing->setAlternateNameField($this);
}
protected function addKeywordsField():void
{
- $this->addField(
- 'keywords',
- [
- 'type' => 'repeater',
- 'label' => 'Keywords',
- 'fields' => [
- 'keyword' => [
- 'type' => 'text',
- 'label' => 'Keyword',
- ],
- ],
- 'default' => $labels ?? [ 'Edmonton tattoos', 'Edmonton tattoo artist', 'Edmonton tattooist' ],
- 'section' => 'seo',
- 'quickEdit' => true,
- ]
- );
+ $thing = new LocalBusiness();
+ $thing->setKeywordsField($this);
}
protected function addOutsidePhotoField():void
{
- $this->addField(
- 'outside_photo',
- [
- 'type' => 'image',
- 'limit' => 1,
- 'label' => __('Outside Photo', 'jvb')
- ]
- );
+ $business = new LocalBusiness();
+ $business->setPhotoField($this);
}
protected function addSloganField():void
{
- $this->addField(
- 'slogan',
- [
- 'type' => 'text',
- 'label' => __('Tagline or Slogan', 'jvb')
- ]
- );
+ $business = new LocalBusiness();
+ $business->setSloganField($this);
}
protected function addPaymentField():void
{
- $this->addField(
- 'payment_accepted',
- [
- 'type' => 'set',
- 'label' => __('Payment Accepted', 'jvb'),
- 'options' => [
- 'Cash' => 'Cash',
- 'Credit Card' => 'Credit Card',
- 'Debit' => 'Debit',
- 'Google Pay' => 'Google Pay',
- 'Apple Pay' => 'Apple Pay',
- 'PayPal' => 'PayPal',
- 'Interac' => 'Interac',
- 'AMEX' => 'AMEX',
- ],
- ]
- );
+ $business = new LocalBusiness();
+ $business->setPaymentAcceptedField($this);
}
protected function addAmenitiesField():void
{
+ $business = new LocalBusiness();
+ $business->setAmenityFeatureField($this);
+ }
+ protected function addCredentialsField():void
+ {
$this->addField(
- 'amenities',
+ 'credentials',
[
'type' => 'set',
- 'label' => __('Amenities', 'jvb'),
- 'options' => [
- 'Wheelchair Accessible' => 'Wheelchair Accessible',
- 'Free Parking' => 'Free Parking',
- 'Private Rooms' => 'Private Rooms',
- 'Air Conditioning' => 'Air Conditioning',
- 'WiFi' => 'WiFi',
- 'Gender Neutral Restroom' => 'Gender Neutral Restroom',
- 'LGBTQ+ Friendly' => 'LGBTQ+ Friendly',
- 'Sterilization Room' => 'Sterilization Room',
- 'Refreshments Available' => 'Refreshments Available',
- 'Street Level Access' => 'Street Level Access',
- 'Single Use Needles' => 'Single Use Needles',
- 'Consultation Room' => 'Consultation Room',
- 'Aftercare Products Available' => 'Aftercare Products Available',
- 'Walk-Ins Welcome' => 'Walk-Ins Welcome',
+ 'label' => __('Credentials', 'jvb'),
+ 'options'=> [
+ 'WHMIS 2015' => 'WHMIS 2015',
+ 'Tattoo and Piercing Safety Standards' => 'Tattoo and Piercing Safety Standards',
+ 'Bloodborne Pathogens and Infection Control' => 'Bloodborne Pathogens and Infection Control',
+ 'First Aid Training' => 'First Aid Training',
]
]
);
}
+ protected function addPermanentlyCloseField():void
+ {
+ $business = new LocalBusiness();
+ $business->setDissolutionDateField($this);
+ }
+
+ protected function addHoursField():void
+ {
+ $business = new LocalBusiness();
+ $business->setOpeningHoursSpecificationField($this);
+ }
+
+ protected function addRateField():void
+ {
+ $this->addField('rate',
+ [
+ 'type' => 'text',
+ 'subtype' => 'number',
+ 'label' => __('Hourly Rate', 'jvb')
+ ]);
+ }
+
+ protected function addAwardsField():void
+ {
+ $business = new LocalBusiness();
+ $business->setAwardField($this);
+ }
+
+ protected function addRatingsField():void
+ {
+ $business = new LocalBusiness();
+ $business->setAggregateRatingField($this);
+ }
+
+ protected function addServicesField():void
+ {
+ $business = new LocalBusiness();
+ $business->setHasOfferCatalogField($this);
+ }
+
+ public function registerPostFields():void
+ {
+ $postType = $this->registrar->getBased();
+ add_meta_box(
+ $postType.'_fields',
+ 'Extra Fields',
+ [$this, 'renderMyMetaBox'],
+ $postType,
+ 'side',
+ 'high'
+ );
+ }
+ public function renderMyMetaBox():void
+ {
+ $ID = get_the_ID();
+ $meta = match ($this->type) {
+ 'post' => Meta::forPost($ID),
+ 'term' => Meta::forTerm($ID),
+ 'user' => Meta::forUser($ID),
+ };
+ $defaults = array_keys(match($this->type) {
+ 'post' => $this->defaultPostFields(),
+ 'term' => $this->defaultTermFields(),
+ 'user' => $this->defaultUserFields()
+ });
+ foreach ($this->fields as $fName => $field){
+ if (!in_array($fName, $defaults)){
+ echo Form::render($fName, $meta->get($fName),$field->getConfig());
+ }
+ }
+ }
+
+ public static function getUserFields():array
+ {
+ return (new self())->defaultUserFields();
+ }
+
+ protected function addIntegrationSetupField():void
+ {
+ $integrations = $this->registrar->getIntegrations();
+ foreach (array_keys($integrations) as $integration) {
+ $this->addField('integration_'.$integration.'_connected', [
+ 'type' => 'true_false',
+ 'hidden' => true,
+ 'label' => 'Connected to '.$integration,
+ 'default' => false,
+ ]);
+ }
+ }
}
--
Gitblit v1.10.0