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 | 155 +++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 125 insertions(+), 30 deletions(-)
diff --git a/inc/managers/SEO/render/SchemaOutput.php b/inc/managers/SEO/render/SchemaOutput.php
index d187f7d..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();
@@ -49,9 +55,24 @@
$registrar = Registrar::getInstance($type);
if ($registrar && !empty($registrar->getConfig('seo')['schema']??[])) {
$seo = $registrar->getSEO();
+ error_log('SEO: '.print_r($seo->schema(), true));
$schema[] = $seo->schema()->outputArchiveSchema();
}
}
+ $isContent = array_values(array_filter(array_map(function($item) {
+ return intval(get_option(BASE.$item.'_archive', false));
+ },Registrar::getFeatured('is_content', 'term'))));
+
+ if (is_page($isContent)){
+ $type = get_post_meta(get_the_id(), BASE.'for_type', true);
+ error_log('Type: '.print_r($type, true));
+ $registrar = Registrar::getInstance($type);
+ if ($registrar) {
+ $schema[] = $registrar->getSEO()->schema()->outputContentTaxArchiveSchema();
+ }
+ }
+
+
$breadcrumbs = $this->buildBreadcrumbs();
if ($breadcrumbs) {
@@ -59,9 +80,11 @@
}
if (!empty($schema)) {
- $website = get_option(BASE.'WebsiteSchema');
+ $website = JVB()->schemaHelper()::schema('website');
if (!empty($website)) {
- Cache::for('websiteSchema')->flush();
+ if (JVB_TESTING) {
+ Cache::for('websiteSchema')->flush();
+ }
$website = Cache::for('websiteSchema')->remember(
'schema',
function () {
@@ -80,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
@@ -104,6 +129,7 @@
echo '<script type="application/ld+json">' . "\n";
echo wp_json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
echo "\n" . '</script>' . "\n";
+ echo "\n" . '<!-- / SEO Schema by JakeVan -->'."\n";
}
public function buildBreadcrumbs():array
@@ -111,20 +137,76 @@
return BreadcrumbManager::getInstance()->toSchema();
}
- public function buildBasicWebsiteSchema():array
- { Cache::for('websiteSchema')->flush();
+ 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));
@@ -137,7 +219,10 @@
public function getCreator(bool $reference = false):LocalBusiness
{
- Cache::for('JakeVanCreator')->flush();
+ if (JVB_TESTING){
+ Cache::for('JakeVanCreator')->flush();
+ }
+
if ($reference) {
return Cache::for('JakeVanCreator')->remember(
'reference',
@@ -210,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;
@@ -230,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