Jake Vanderwerf
6 days ago 266aa37c48222993bf7bdad6834e31bd08736f5e
inc/registrar/config/seo/Resolver.php
@@ -16,6 +16,13 @@
   public static function resolve(string $template, ?Meta $meta): string
   {
      if (!$meta) {
         if (is_singular()){
            $meta = Meta::forPost(get_the_ID());
         }else if (is_tax()) {
            $meta = Meta::forTerm(get_queried_object()->term_id);
         }
      }
      self::$meta = $meta;
      return preg_replace_callback(
         '/\{\{([^}]+)}}/',
@@ -29,6 +36,13 @@
      switch ($variable) {
         case 'CREATOR':
            return JVB()->seo()->getCreator();
         case 'name':
            if (is_post_type_archive()) {
               $obj = get_queried_object();
               $registrar = Registrar::getInstance($obj->name);
               return $registrar ? $registrar->getPlural() : $obj->label;
            }
            break;
      }
      if (str_contains($variable, '.')) {
@@ -45,6 +59,9 @@
         error_log('[SEO]Meta Resolver. Could not find meta configuration for variable: '.$variable);
         return '';
      }
      if ($variable === 'post_content') {
         return self::resolvePostContent($variable, $meta);
      }
      return match($config['type']) {
         'upload', 'image', 'gallery' => self::resolveImage($variable, $meta),
         'selector', 'taxonomy', 'user', 'post' => self::resolveObject($variable, $meta),
@@ -69,6 +86,10 @@
         }
      }
      if (!$meta) {
         return'';
      }
      $ID = $meta->get($relation);
      if (!$ID || $ID === '') {
         return '';
@@ -78,14 +99,16 @@
      if (!$config) {
         return '';
      }
      $type = false;
      if ($config['type'] === 'taxonomy' || array_key_exists('taxonomy', $config)) {
         $type = 'taxonomy';
      } elseif ($config['type'] === 'user'){
         $type = 'term';
      } elseif ($config['type'] === 'user' || array_key_exists('user', $config)){
         $type = 'user';
      } elseif ($config['type'] === 'post'){
      } elseif ($config['type'] === 'post' || array_key_exists('post', $config)){
         $type = 'post';
      }
      if (!$type) {
         error_log('[SEO]Meta Resolver. Could not find type for relation: '.$relation.': '.$field);
         return '';
@@ -95,6 +118,9 @@
      return self::resolve($field, $newMeta);
   }
   protected static function resolvePostContent(string $variable, ?Meta $meta):string{
      return wp_strip_all_tags(str_replace("\n", '', $meta->get('post_content')));
   }
   protected static function resolveImage(string $variable, ?Meta $meta, bool $returnID = false): string
   {
      $imgID = $meta->get($variable);
@@ -133,7 +159,11 @@
         return $checkType;
      }
      error_log('[SEO]Resolver - No method found for '.$property.' with value: '.print_r($value, true).'. Defaulting to base Resolver');
      $ignore = ['description', 'name'];
      if (!in_array($property, $ignore)) {
         error_log('[SEO]Resolver - No method found for '.$property.' with value: '.print_r($value, true).'. Defaulting to base Resolver');
      }
      return self::resolve($value, $meta);
   }