<?php
|
namespace JVBase\registrar\config\seo;
|
|
use JVBase\registrar\Registrar;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
class Meta {
|
protected string $slug;
|
|
protected string $title;
|
protected string $description;
|
protected int $image;
|
protected int $twitterImage;
|
|
|
public function __construct(string $slug) {
|
$this->slug = $slug;
|
add_action('init', [$this, 'init']);
|
}
|
|
public function init():void {
|
if (!function_exists('tsf')){
|
return;
|
}
|
if ($this->hasTitle()){
|
add_filter('the_seo_framework_title_from_generation', [$this, 'filterTitle'], 10, 2);
|
}
|
if ($this->hasDescription()){
|
add_filter('the_seo_framework_generated_description', [$this, 'filterDescription'], 10, 3);
|
}
|
if ($this->hasImage()){
|
add_filter('the_seo_framework_image_generation_params', [$this, 'filterImage'], 10, 3);
|
}
|
}
|
|
public function hasTitle():bool
|
{
|
return !empty($this->title);
|
}
|
public function hasDescription():bool
|
{
|
return !empty($this->description);
|
}
|
public function hasImage():bool
|
{
|
return !empty($this->image);
|
}
|
public function hasTwitterImage():bool
|
{
|
return !empty($this->twitterImage);
|
}
|
|
public function filterTitle(string $title, ?array $args): string
|
{
|
if (jvbTSFDoIt($this->slug, $args)){
|
return $title;
|
}
|
$ID = jvbTSFGetID($args);
|
|
$meta = new \JVBase\meta\Meta($ID, Registrar::getInstance($this->slug)->getType());
|
return Resolver::resolve($this->title, $meta);
|
}
|
|
public function filterDescription(string $description, ?array $args): string
|
{
|
if (jvbTSFDoIt($this->slug, $args)){
|
return $description;
|
}
|
$ID = jvbTSFGetID($args);
|
|
$meta = new \JVBase\meta\Meta($ID, Registrar::getInstance($this->slug)->getType());
|
return Resolver::resolve($this->title, $meta);
|
}
|
public function filterImage(string $image, ?array $args): string
|
{
|
if (jvbTSFDoIt($this->slug, $args)){
|
return $image;
|
}
|
$ID = jvbTSFGetID($args);
|
|
$meta = new \JVBase\meta\Meta($ID, Registrar::getInstance($this->slug)->getType());
|
return Resolver::resolve($this->title, $meta);
|
}
|
}
|