Jake Vanderwerf
2026-08-27 d7c8752b4d8f688a13645130d4c3237efd5ad1bf
inc/registrar/config/seo/Schema.php
@@ -4,6 +4,7 @@
use JVBase\base\SchemaHelper;
use JVBase\managers\Cache;
use JVBase\managers\SEO\render;
use JVBase\managers\SEO\render\SchemaOutput;
use JVBase\meta\Meta;
use JVBase\registrar\Registrar;
use WP_Query;
@@ -54,9 +55,10 @@
      $this->referenceCache = Cache::for('schemaReference');
      $this->archiveCache = Cache::for('schemaArchive');
      if ($registrar) {
         $this->cache->connect($registrar->getType());
         $this->referenceCache->connect($registrar->getType());
         $this->archiveCache->connect($registrar->getType());
         $type = $registrar->getType();
         $this->cache = Cache::for('schema', $type);
         $this->referenceCache = Cache::for('schemaReference', $type);
         $this->archiveCache = Cache::for('schemaArchive', $type);
         switch ($registrar->getType()) {
            case 'term':
@@ -93,49 +95,8 @@
      add_action('wp_head', [$this, 'outputSchema'], 1);
      add_filter('the_seo_framework_schema_graph_data', [$this, 'filterTSFSchema'], 10, 2);
      add_filter('the_seo_framework_title_from_custom_field', [$this, 'filterTSFOGTitle'], 10, 2);
      $this->maybeExcludeSingles();
   }
      protected function maybeExcludeSingles(): void
      {
         $exclude = $this->cache->remember(
            'excludeSingles',
            function () {
               $exclude = [];
               $registrar = Registrar::getInstance($this->slug);
               if ($registrar && $registrar->hasFeature('hide_single')) {
                  $exclude = $this->excludeSingle();
               }
               if ($registrar && $registrar->hasFeature('is_timeline')) {
                  $exclude = array_merge($exclude, $this->excludeTimeline());
               }
               return $exclude;
            }
         );
         if (!empty($exclude)) {
            add_filter('the_seo_framework_sitemap_exclude_ids', $exclude);
         }
      }
      protected function excludeSingle():array
      {
         return get_posts([
            'post_type'    => jvbCheckBase($this->slug),
            'posts_per_page'=> -1,
            'fields'    => 'ids',
            'post_status'  => 'publish',
         ]);
      }
      protected function excludeTimeline():array
      {
         return get_posts([
            'post_type'    => jvbCheckBase($this->slug),
            'posts_per_page'=> -1,
            'fields'    => 'ids',
            'post_status'  => 'publish',
            'post_parent__not_in'   => [0], // Only get posts with a parent
         ]);
      }
   public function filterTSFSchema(array $graph, ?array $args):array
   {
      $based = jvbCheckBase($this->slug);
@@ -183,8 +144,11 @@
               $config = $this->getConfig();
               $class = JVB()->schemaHelper()::classFromConfig($config, $meta);
               $class->setAuthor(JVB()->seo()->getCreator(true));
               $class = SchemaHelper::getInstance()::classFromConfig($config, $meta);
               if (property_exists($class, 'author')) {
                  $class->setAuthor(SchemaOutput::getInstance()->getCreator(true));
               }
               $class = apply_filters('jvb_single_'.$this->slug.'_schema_output', $class, $ID);
               return $class->outputSchema();
@@ -196,14 +160,12 @@
      public function outputContentTaxArchiveSchema():array
      {
         $ID = get_the_ID();
         if (JVB_TESTING) {
            $this->cache->flush();
         }
         return $this->cache->remember(
            $ID,
            function() use ($ID) {
               $action = BASE.ucfirst($this->slug).'Schema';
               $config = JVB()->schemaHelper()::schema($action);
               $config = SchemaHelper::getInstance()::schema($action);
               if (!array_key_exists('type', $config)) {
                  $config['type'] = 'JVBase\inc\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage\CollectionPage';
@@ -212,7 +174,7 @@
                  error_log('No class found for archive schema output: '.$config['type']);
                  return [];
               }
               $class = JVB()->schemaHelper()::classFromConfig($config);
               $class = SchemaHelper::getInstance()::classFromConfig($config);
               $class->setIsPartOf(get_home_url().'/#website');
               $itemList = new render\Thing\Intangible\ItemList\ItemList();
@@ -246,12 +208,17 @@
         if (JVB_TESTING){
            $this->archiveCache->flush();
         }
         $this->archiveCache->flush();
         return $this->archiveCache->remember(
            $this->slug,
            function() {
               $action = BASE.ucfirst($this->slug).'Archive';
               $config = JVB()->schemaHelper()->archive($this->slug);
               $override = apply_filters($action.'Override', []);
               if (!empty($override)) {
                  return $override;
               }
               $config = SchemaHelper::getInstance()->archive($this->slug);
               if (!array_key_exists('type', $config)) {
                  $config['type'] = 'JVBase\inc\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage\CollectionPage';
               }
@@ -272,7 +239,7 @@
               $obj = get_queried_object();
               $meta = (property_exists($obj, 'taxonomy')) ? Meta::forTerm($obj->term_id) : null;
               $class = JVB()->schemaHelper()::classFromConfig($config, $meta);
               $class = SchemaHelper::getInstance()::classFromConfig($config, $meta);
               $class->setIsPartOf(get_home_url().'/#website');
               $itemList = new render\Thing\Intangible\ItemList\ItemList();
@@ -297,13 +264,7 @@
               $itemList->setItemListElement($itemListItems);
               $class->setMainEntity($itemList);
               $schema = $class->outputSchema();
               if (JVB_TESTING) {
//                error_log('Generated archive schema: '.print_r($schema, true));
               }
               return $schema;
               return $class->outputSchema();
            }
         );
      }
@@ -339,7 +300,7 @@
                  $meta = null;
            }
            $config = $this->getConfig();
            $class = JVB()->schemaHelper()::classFromConfig($config, $meta);
            $class = SchemaHelper::getInstance()::classFromConfig($config, $meta);
            if ($class) {
               $class->delete('about');
            }
@@ -368,7 +329,7 @@
         error_log('[SEO]Schema::getConfig Invalid type: '.$type);
         return [];
      }
      return JVB()->schemaHelper()::getConfig($this->slug, $type);
      return SchemaHelper::getInstance()::getConfig($this->slug, $type);
   }
   public function resolveMeta(array $config, Meta $meta):array
@@ -487,10 +448,12 @@
            'type'   => 'JVBase\inc\managers\SEO\render\Thing\CreativeWork\Comment\Answer',
            'text'   => wp_strip_all_tags(str_replace("\n", '', $meta->get('post_content'))),
         ],
         'answerCount'  => 1,
      ];
      $question = SchemaHelper::classFromConfig($question);
      $page->setMainEntity($question);
      $page->setAuthor(JVB()->seo()->getCreator(true));
      $page->setAuthor(SchemaOutput::getInstance()->getCreator(true));
      return $page->outputSchema();
   }
@@ -530,7 +493,7 @@
      }
      $page->setImage($images);
      $page->setAuthor(JVB()->seo()->getCreator(true));
      $page->setAuthor(SchemaOutput::getInstance()->getCreator(true));
      return $page->outputSchema();
   }