Jake Vanderwerf
2026-03-29 9f672be1f7bb5f8462374ca4732d095d4f24685b
inc/registrar/config/seo/Schema.php
@@ -169,7 +169,7 @@
               $meta = Meta::forPost($ID);
               $config = $this->getConfig();
               $class = $this->classFromConfig($config, $meta);
               $class = JVB()->schemaHelper()::classFromConfig($config, $meta);
               $class->setAuthor(JVB()->seo()->getCreator(true));
               return $class->outputSchema();
@@ -188,7 +188,8 @@
            $ID,
            function() use ($ID) {
               $action = BASE.ucfirst($this->slug).'Schema';
               $config = get_option($action, apply_filters($action, $this->defaultSchema));
               $config = JVB()->schemaHelper()::schema($action);
               if (!array_key_exists('type', $config)) {
                  $config['type'] = 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage';
               }
@@ -196,7 +197,7 @@
                  error_log('No class found for archive schema output: '.$config['type']);
                  return [];
               }
               $class = $this->classFromConfig($config);
               $class = JVB()->schemaHelper()::classFromConfig($config);
               $class->setIsPartOf(get_home_url().'/#website');
               $itemList = new render\Thing\Intangible\ItemList\ItemList();
@@ -235,7 +236,7 @@
            $this->slug,
            function() {
               $action = BASE.ucfirst($this->slug).'Archive';
               $config = get_option($action, apply_filters($action, $this->defaultArchive));
               $config = JVB()->schemaHelper()->archive($this->slug);
               if (!array_key_exists('type', $config)) {
                  $config['type'] = 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage';
               }
@@ -246,7 +247,7 @@
               $obj = get_queried_object();
               $meta = (property_exists($obj, 'taxonomy')) ? Meta::forTerm($obj->term_id) : null;
               $class = $this->classFromConfig($config, $meta);
               $class = JVB()->schemaHelper()::classFromConfig($config, $meta);
               $class->setIsPartOf(get_home_url().'/#website');
               $itemList = new render\Thing\Intangible\ItemList\ItemList();
@@ -301,7 +302,7 @@
                  $meta = null;
            }
            $config = $this->getConfig('archive');
            $class = $this->classFromConfig($config, $meta);
            $class = JVB()->schemaHelper()::classFromConfig($config, $meta);
            $class->delete('about');
            switch ($type) {
@@ -327,9 +328,7 @@
         error_log('[SEO]Schema::getConfig Invalid type: '.$type);
         return [];
      }
      $action = BASE.ucfirst($this->slug).ucfirst($type);
      $default = 'default'.ucfirst($type);
      return get_option($action, apply_filters($action, $this->$default));
      return JVB()->schemaHelper()::getConfig($this->slug, $type);
   }
   public function define(string $property, string $value):void
@@ -394,39 +393,16 @@
         $config = $this->getConfig('meta');
         $meta = Meta::forPost(get_the_ID());
         $title = Resolver::resolve($config['name'], $meta);
      } elseif (is_post_type_archive($based) || is_tax($based)) {
      } elseif (is_post_type_archive($based) ) {
         $config = $this->getConfig('archive');
         $title = $config['name'];
      } elseif (is_tax($based)) {
         $config = $this->getConfig('archive');
         $meta = Meta::forTerm(get_queried_object_id());
         $title = Resolver::resolve($config['name'], $meta);
      } else {
         error_log('[Schema]::filterTSFOGTitle Unmatched condition: '.$this->slug);
      }
      return $title;
   }
   protected function classFromConfig(array $config, ?Meta $meta = null):mixed
   {
      if (!array_key_exists('type', $config)) {
         error_log('[Schema]::classFromConfig No class defined in config: '.print_r($config, true));
         return false;
      }
      $className = $config['type'];
      unset($config['type']);
      $class = new $className();
      foreach ($config as $property=>$value) {
         if (is_array ($value)) {
            $value = $this->classFromConfig($value, $meta);
         }
         $method = 'set'.ucfirst($property);
         if (!method_exists($class, $method)) {
            error_log('[Schema]::classFromConfig - method: '.$method.' does not exist in class: '.$className);
            continue;
         }
         if (is_string($value) && str_contains($value, '{{')) {
            $value = Resolver::resolveForSchema($property, $value, $config, $meta);
         }
         if (!empty($value)) {
            $class->$method($value);
         }
      }
      return $class;
   }
}