Jake Vanderwerf
5 days ago 266aa37c48222993bf7bdad6834e31bd08736f5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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
    {
        error_log('Filtering title...');
        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);
    }
}