Jake Vanderwerf
2026-03-03 772462eeca3002a1d52508aeba485aab2b4742ad
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
<?php
 
namespace JVBase\registrar\config;
 
use JVBase\registrar\config\seo\Archive;
use JVBase\registrar\config\seo\Meta;
use JVBase\registrar\config\seo\Schema;
use JVBase\registrar\Registrar;
 
if (!defined('ABSPATH')) {
    exit;
}
 
final class SEO extends Config
{
    protected string $slug;
    protected array $config;
    public Schema $schema;
    public Meta $meta;
    public Archive $archive;
 
 
    public function __construct(string $slug)
    {
        $this->slug = $slug;
        $action = ucFirst($slug);
        $this->config = [
            'schema'    => get_option(BASE.$action.'Schema', apply_filters(BASE.$action.'Schema', [])),
            'meta'      => get_option(BASE.$action.'Meta', apply_filters(BASE.$action.'Meta', [])),
            'archive'   => get_option(BASE.$action.'Archive', apply_filters(BASE.$action.'Archive', [])),
        ];
    }
 
    protected function initSchema():void
    {
        if (!array_key_exists('type', $this->config['schema'])){
            error_log('Missing schema type');
            return;
        }
        if (!class_exists($this->config['schema']['type'])) {
            error_log('Could not find class: '.$this->config['schema']['type']);
            return;
        }
        $this->schema = new Schema($this->slug, $this->config['schema']['type']);
 
    }
    public function schema():Schema|false
    {
        if (!isset($this->schema)) {
            $this->initSchema();
        }
        return $this->schema??false;
    }
    public function meta():Meta
    {
        return $this->meta;
    }
    public function archive():Archive
    {
        return $this->archive;
    }
 
    public function getConfig():array
    {
        return  $this->config;
    }
}