Jake Vanderwerf
5 hours ago 56a9a1ccf764ff7a6af8f8a2292cb07443cb4aa7
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace JVBase\registrar\fields;
 
use JVBase\registrar\Registrar;
 
if (!defined('ABSPATH')) {
    exit;
}
 
class SelectorField extends Field {
    protected string $taxonomy;
    protected string $post_type;
    protected string $user_role;
    protected int $max = 0;
    protected bool $search = true;
    protected bool $createNew = false;
    protected bool $autocomplete = true;
    /**
     * @var bool isReference If true, does not set default taxonomy functionality, but is a reference to the selected items. (example: if it's a taxonomy subtype, does not set_object_terms with the selection)
     */
    protected bool $isReference = false;
    protected bool $update = true;
    protected string $subtype;
    protected array $allowedSubtype = ['taxonomy', 'user', 'post'];
 
    public function setTaxonomy(string $taxonomy):void
    {
        $allowed = array_merge(['tag', 'category'], Registrar::getRegistered('term'));
        if (!in_array(jvbNoBase($taxonomy), $allowed)) {
            error_log('[SelectorField]Attempted taxonomy not allowed: '.$taxonomy);
            return;
        }
        $this->taxonomy = $taxonomy;
    }
    public function getTaxonomy():string {
        return $this->taxonomy;
    }
 
    public function setPost_type(string $post_type):void
    {
        $allowed = array_merge(['post', 'page'], Registrar::getRegistered('post'));
        if (!in_array(jvbNoBase($post_type), $allowed)) {
            error_log('[SelectorField]Attempted post type not allowed: '.$post_type);
            return;
        }
        $this->post_type = $post_type;
    }
    public function getPost_type():string {
        return $this->post_type;
    }
 
    public function setUser_role(string $user_role):void
    {
        $allowed = array_merge(['administrator'], Registrar::getRegistered('user'));
        if (!in_array(jvbNoBase($user_role), $allowed)) {
            error_log('[SelectorField]Attempted user not allowed: '.$user_role);
            return;
        }
        $this->user_role = $user_role;
    }
    public function getUser_role():string {
        return $this->user_role;
    }
 
    public function setMax(int $max):void
    {
        $this->max = $max;
    }
    public function getMax():int
    {
        return $this->max;
    }
    public function setSearch(bool $search):void {
        $this->search = $search;
    }
    public function getSearch():bool
    {
        return $this->search;
    }
    public function setCreateNew(bool $createNew):void
    {
        $this->createNew = $createNew;
    }
    public function getCreateNew():bool
    {
        return $this->createNew;
    }
    public function setAutocomplete(bool $autocomplete):void
    {
        $this->autocomplete = $autocomplete;
    }
    public function getAutocomplete():bool
    {
        return $this->autocomplete;
    }
    public function setUpdate(bool $update):void
    {
        $this->update = $update;
    }
    public function getUpdate():bool
    {
        return $this->update;
    }
    public function setSubtype(string $subtype):void
    {
        if (!in_array($subtype, $this->allowedSubtype)) {
            error_log('[SelectorField]Attempted subtype not allowed: '.$subtype);
            return;
        }
        $this->subtype = $subtype;
    }
    public function getSubtype():string
    {
        return $this->subtype;
    }
 
    public function setIsReference(bool $isReference):void
    {
        $this->isReference = $isReference;
    }
    public function getIsReference():bool
    {
        return $this->isReference;
    }
}