From 275c0d74cd68677622a5431505c5c870c473063d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 29 Mar 2026 21:40:15 +0000
Subject: [PATCH] =Seems to be working, huzzah! Added some changes for on-this-page nav
---
inc/managers/SEO/render/SchemaOutput.php | 124 ++++++++++++++++++++++++++++++++---------
1 files changed, 97 insertions(+), 27 deletions(-)
diff --git a/inc/managers/SEO/render/SchemaOutput.php b/inc/managers/SEO/render/SchemaOutput.php
index 6109e90..909e6bb 100644
--- a/inc/managers/SEO/render/SchemaOutput.php
+++ b/inc/managers/SEO/render/SchemaOutput.php
@@ -7,6 +7,7 @@
use JVBase\managers\SEO\render\Thing\Intangible\OfferCatalog;
use JVBase\managers\SEO\render\Thing\Intangible\Service;
use JVBase\managers\SEO\render\Thing\Organization\LocalBusiness\LocalBusiness;
+use JVBase\meta\Meta;
use JVBase\registrar\config\seo\Resolver;
use JVBase\registrar\Registrar;
@@ -23,8 +24,13 @@
public function buildSchema():array
{
$schema = [];
- if (!is_front_page()) {
- $schema[] = $this->buildBasicWebsiteSchema();
+
+ $schema[] = $this->buildWebsiteSchema(false);
+ if (is_front_page()) {
+ $test = $this->buildOrganizationSchema();
+ if (!empty($test)) {
+ $schema[] = $test;
+ }
}
if (is_singular($this->types)) {
$type = get_post_type();
@@ -74,7 +80,7 @@
}
if (!empty($schema)) {
- $website = get_option(BASE.'WebsiteSchema');
+ $website = JVB()->schemaHelper()::schema('website');
if (!empty($website)) {
if (JVB_TESTING) {
Cache::for('websiteSchema')->flush();
@@ -97,18 +103,20 @@
protected function websiteSchema():array
{
- $stored = get_option(BASE.'WebsiteSchema', apply_filters(BASE.'WebsiteSchema', []));
+ $stored = JVB()->schemaHelper()::schema('website');
+ $website = JVB()->schemaHelper()::classFromConfig($stored);
- $seo = new WebSite();
- foreach ($stored as $property => $value) {
- $method = 'set'.ucfirst($property);
- $seo->$method($value);
+ if (!$website->getUrl() || empty($website->getUrl())){
+ $website->setUrl(get_home_url());
}
- $seo->setUrl(get_home_url());
- $seo->setName(get_bloginfo('name'));
- $seo->setCreator($this->getCreator());
- return $seo->outputSchema();
+ if (!$website->getName() || empty($website->getName())){
+ $website->setName(get_bloginfo('name'));
+ }
+ if(!$website->getCreator() || empty($website->getCreator())) {
+ $website->setCreator($this->getCreator());
+ }
+ return $website->outputSchema();
}
public function outputSchema():void
@@ -129,24 +137,76 @@
return BreadcrumbManager::getInstance()->toSchema();
}
- public function buildBasicWebsiteSchema():array
+ public function buildWebsiteSchema(bool $full = true):array
{
if (JVB_TESTING){
Cache::for('websiteSchema')->flush();
}
+ $storedWebsite = JVB()->schemaHelper()::schema('website');
+ if (!$full) {
+ return Cache::for('websiteSchema')->remember(
+ 'reference',
+ function () use ($storedWebsite) {
+ $allowed = ['type','name', 'url', 'description', 'inLanguage'];
+ $storedWebsite = array_filter($storedWebsite, function ($key) use ($allowed) {
+ return in_array($key, $allowed);
+ }, ARRAY_FILTER_USE_KEY);
+
+ $website = JVB()->schemaHelper()::classFromConfig($storedWebsite);
+ if (!$website->getName() || empty($website->getName())) {
+ $website->setName(get_bloginfo('name'));
+ }
+ if (!$website->getUrl() || empty($website->getUrl())) {
+ $website->setUrl(get_home_url());
+ }
+ if (!$website->getId() || empty($website->getId())) {
+ $website->setId(get_home_url().'/#website');
+ }
+ if (!$website->getDescription() || empty($website->getDescription())) {
+ $website->setDescription(get_bloginfo('description'));
+ }
+ if (!$website->getInLanguage() || empty($website->getInLanguage())) {
+ $website->setInLanguage('en-CA');
+ }
+ if (!$website->getPublisher() || empty($website->getPublisher())) {
+ $publisher = $this->getOptionSchemaReference('organization');
+ if ($publisher){
+ $website->setPublisher($publisher);
+ }
+ }
+
+ $website->setCreator($this->getCreator(true));
+
+ return $website->outputSchema();
+ }
+ );
+ }
return Cache::for('websiteSchema')->remember(
- 'reference',
- function () {
- $website = new WebSite();
- $website->setName(get_bloginfo('name'));
- $website->setUrl(get_home_url());
- $website->setId(get_home_url().'/#website');
- $website->setDescription(get_bloginfo('description'));
- $website->setInLanguage('en-CA');
- $publisher = $this->getOptionSchemaReference('organization');
- if ($publisher){
- $website->setPublisher($publisher);
+ 'full',
+ function () use ($storedWebsite) {
+ error_log('StoredWebsite: '.print_r($storedWebsite, true));
+ $website = JVB()->schemaHelper()::classFromConfig($storedWebsite);
+ if (!$website->getName() || empty($website->getName())) {
+ $website->setName(get_bloginfo('name'));
+ }
+ if (!$website->getUrl() || empty($website->getUrl())) {
+ $website->setUrl(get_home_url());
+ }
+ if (!$website->getId() || empty($website->getId())) {
+ $website->setId(get_home_url().'/#website');
+ }
+ if (!$website->getDescription() || empty($website->getDescription())) {
+ $website->setDescription(get_bloginfo('description'));
+ }
+ if (!$website->getInLanguage() || empty($website->getInLanguage())) {
+ $website->setInLanguage('en-CA');
+ }
+ if (!$website->getPublisher() || empty($website->getPublisher())) {
+ $publisher = $this->getOptionSchemaReference('organization');
+ if ($publisher){
+ $website->setPublisher($publisher);
+ }
}
$website->setCreator($this->getCreator(true));
@@ -235,8 +295,8 @@
return null;
}
$action = BASE.ucfirst($option).'Schema';
- $stored = get_option($action, apply_filters($action, []));
-// $stored = get_option($action, apply_filters($action, jvbDefaultSchema($option)));
+ $stored = JVB()->schemaHelper()::reference($action);
+
if (empty($stored)){
error_log('Attempted to get schema reference for: '.$option.', but defaults not set.');
return null;
@@ -255,9 +315,19 @@
$value = array_key_exists($property, $stored) ? $stored[$property] : null;
if (!$value) {continue;}
- $class->$method(Resolver::resolve($property, $value));
+ if (str_contains($value, '{{')) {
+ $value = Resolver::resolve($property, $value);
+ }
+ $class->$method($value);
}
return $class;
}
+
+ public function buildOrganizationSchema():array
+ {
+ $config = JVB()->schemaHelper()::schema('organization');
+ $class = JVB()->schemaHelper()::classFromConfig($config);
+ return ($class)? $class->outputSchema() : [];
+ }
}
--
Gitblit v1.10.0