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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace JVBase\registrar\config;
 
use JVBase\registrar\Registrar;
 
if (!defined('ABSPATH')) {
    exit;
}
 
final class Feed extends Config {
    protected array $single = [];
    protected array $archive = [];
    protected array $config = [];
    protected string $slug;
 
    public function __construct(string $slug) {
        $this->slug = $slug;
        $this->config = $this->defaultConfig();
    }
 
    public function defaultConfig():array
    {
        return [
            'is_gallery'    => false,
            'icon'          => Registrar::getInstance($this->slug)->getIcon(),
            'content'       => $this->slug,
//          'taxonomies'    => Registrar::getInstance($this->slug)->registrar->taxonomies,
        ];
    }
 
    protected function allowedConfig():array
    {
        return ['is_gallery', 'content', 'context', 'taxonomies','icon','source','custom_order','images','fields'];
    }
 
    public function setGallery(bool $set = true):self
    {
        $this->config['is_gallery'] = $set;
        return $this;
    }
    public function setIcon(string $icon):self
    {
        $this->config['icon'] = $icon;
        return $this;
    }
    public function setCustomOrder(array $order):self
    {
        $this->config['custom_order'] = $order;
        return $this;
    }
    public function getCustomOrder():array {
        return $this->config['custom_order']??[];
    }
    public function setImages(string|array $images):self
    {
        $images = is_string($images) ? [$images] : $images;
        $images = array_filter($images, function($imgField) {
            return array_key_exists($imgField, Registrar::getInstance($this->slug)->getFields());
        });
        if (empty($images)) {
            $images = ['post_thumbnail'];
        }
        $this->config['images'] = $images;
        return $this;
    }
    public function setFields(array $fields):self
    {
        $fields = array_filter($fields, function($field){
            return array_key_exists($field, Registrar::getInstance($this->slug)->getFields());
        });
        if (empty($fields)) {
            $fields = ['post_title', 'post_date','post_excerpt'];
        }
        $this->config['fields'] = $fields;
        return $this;
    }
    public function getConfig():array
    {
        return $this->config;
    }
 
 
}