| | |
| | | |
| | | 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( |
| | | '/\{\{([^}]+)}}/', |
| | |
| | | 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), |
| | |
| | | } |
| | | |
| | | } |
| | | error_log('resolveRelation: '.print_r($path, true)); |
| | | |
| | | $ID = $meta->get($relation); |
| | | if (!$ID || $ID === '') { |
| | | return ''; |
| | |
| | | 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 ''; |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |