Jake Vanderwerf
2026-03-29 275c0d74cd68677622a5431505c5c870c473063d
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
namespace JVBase\registrar;
 
if (!defined('ABSPATH')) {
    exit;
}
 
final class Terms {
    public string $taxonomy;
    public string $singular;
    public string $plural;
    public array $labels;
    /**
     * A string or array of strings of object types this taxonomy is for
     * @var string|array
     */
    public string|array $for;
    /**
     * A short descriptive summary of what the taxonomy is for.
     * @var string
     */
    public string $description;
    /**
     * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users.
     * The default settings of $publicly_queryable, $show_ui, and $show_in_nav_menus are inherited from $public.
     * @var bool
     */
    public bool $public = true;
    /**
     * Whether the taxonomy is publicly queryable.
     * If not set, the default is inherited from $public
     * @var bool
     */
    public bool $publicly_queryable;
    /**
     * Whether the taxonomy is hierarchical. Default false.
     * @var bool
     */
    public bool $hierarchical = false;
    /**
     * Whether to generate and allow a UI for managing terms in this taxonomy in the admin.
     * If not set, the default is inherited from $public (default true).
     * @var bool
     */
    public bool $show_ui;
    /**
     * Whether to show the taxonomy in the admin menu. If true, the taxonomy is shown as a submenu of the object type menu. If false, no menu is shown.
     * $show_ui must be true. If not set, default is inherited from $show_ui (default true).
     * @var bool
     */
    public bool $show_in_menu;
    /**
     * Makes this taxonomy available for selection in navigation menus.
     * If not set, the default is inherited from $public (default true).
     * @var bool
     */
    public bool $show_in_nav_menus;
    /**
     * Whether to include the taxonomy in the REST API. Set this to true for the taxonomy to be available in the block editor.
     * @var bool
     */
    public bool $show_in_rest = true;
    /**
     * To change the base url of REST API route. Default is $taxonomy.
     * @var string
     */
    public string $rest_base;
    /**
     * To change the namespace URL of REST API route. Default is wp/v2.
     * @var string
     */
    public string $rest_namespace;
    /**
     * REST API Controller class name. Default is ‘WP_REST_Terms_Controller‘.
     * @var string
     */
    public string $rest_controller_class;
    /**
     * Whether to list the taxonomy in the Tag Cloud Widget controls.
     * If not set, the default is inherited from $show_ui (default true).
     * @var bool
     */
    public bool $show_tag_cloud;
    /**
     * Whether to show the taxonomy in the quick/bulk edit panel.
     * If not set, the default is inherited from $show_ui (default true).
     * @var bool
     */
    public bool $show_quick_edit;
    /**
     * Whether to display a column for the taxonomy on its post type listing screens. Default false
     * @var bool
     */
    public bool $show_admin_column;
    /**
     * Provide a callback function for the meta box display.
     * If not set, post_categories_meta_box() is used for hierarchical taxonomies, and post_tags_meta_box() is used for non-hierarchical.
     * If false, no meta box is shown.
     * @var mixed
     */
    public mixed $meta_box_cb;
    /**
     * Callback function for sanitizing taxonomy data saved from a meta box. If no callback is defined, an appropriate one is determined based on the value of $meta_box_cb.
     * @var mixed
     */
    public mixed $meta_box_sanitize_cb;
    /**
     * Array of capabilities for this taxonomy.
     * manage_terms {string}    - Default 'manage_categories'.
     * edit_terms {string}      - Default 'manage_categories'.
     * delete_terms {string}    - Default 'manage_categories'.
     * assign_terms {string}    - Default 'edit_posts'.
     * @var array
     */
    public array $capabilities;
    /**
     * Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
        * slug {string}     - Customize the permastruct slug. Default $taxonomy key.
        * with_front {bool} -  Should the permastruct be prepended with WP_Rewrite::$front. Default true.
        * hierarchical {bool}- Either hierarchical rewrite tag or not. Default false.
        * ep_mask {int}     - Assign an endpoint mask. Default EP_NONE.
     * @var bool|array
     */
    public bool|array $rewrite;
    /**
     * Sets the query var key for this taxonomy. Default $taxonomy key.
     * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}.
     * If a string, the query ?{query_var}={term_slug} will be valid.
     * @var bool|string
     */
    public bool|string $query_var;
    /**
     * Works much like a hook, in that it will be called when the count is updated.
     * Default _update_post_term_count() for taxonomies attached to post types, which confirms that the objects are published before counting them.
     * Default _update_generic_term_count() for taxonomies attached to other object types, such as users.
     * @var mixed
     */
    public mixed $update_count_callback;
    /**
     * Default term to be used for the taxonomy.
        * name {string} - Name of the default term
        * slug {string} - Slug for the default term
        * description {string} - Description for default term
     * @var string|array
     */
    public string|array $default_term;
    /**
     * Whether terms in this taxonomy should be sorted in the order they are provided to wp_set_object_terms().
     * Default null which equates to false.
     * @var bool
     */
    public bool $sort;
    /**
     * Array of arguments to automatically use inside wp_get_object_terms() for this taxonomy.
     * @var array
     */
    public array $args;
 
 
    public function __construct(string $taxonomy, string $singular, string $plural)
    {
        $this->taxonomy = $taxonomy;
        $this->labels = $this->buildLabels($singular, $plural);
    }
    private function buildLabels(string $singular, string $plural): array
    {
        return [
            'name' => $plural,
            'singular_name' => $singular,
            'search_items' => "Search {$plural}",
            'all_items' => "All {$plural}",
            'edit_item' => "Edit {$singular}",
            'update_item' => "Update {$singular}",
            'add_new_item' => "Add New {$singular}",
            'new_item_name' => "New {$singular} Name",
            'menu_name' => $singular
        ];
    }
 
    public function register():void
    {
 
        $args = array_filter(get_object_vars($this));
//      $args = [
//          'labels'        => $this->labels,
//          'public'        => $this->public,
//          'hierarchical'  => $this->hierarchical,
//      ];
//          if (isset($this->description)) {
//              $args['description'] = $this->description;
//          }
//          if (isset($this->publicly_queryable)) {
//              $args['publicly_queryable'] = $this->publicly_queryable;
//          }
//          if (isset($this->show_ui)) {
//              $args['show_ui'] = $this->show_ui;
//          }
//          if (isset($this->show_in_menu)) {
//              $args['show_in_menu'] = $this->show_in_menu;
//          }
//          if (isset($this->show_in_nav_menus)) {
//              $args['show_in_nav_menus'] = $this->show_in_nav_menus;
//          }
//          if (isset($this->show_in_rest)) {
//              $args['show_in_rest'] = $this->show_in_rest;
//          }
//          if (isset($this->rest_base)) {
//              $args['rest_base'] = $this->rest_base;
//          }
//          if (isset($this->rest_namespace)) {
//              $args['rest_namespace'] = $this->rest_namespace;
//          }
//          if (isset($this->rest_controller_class)) {
//              $args['rest_controller_class'] = $this->rest_controller_class;
//          }
//          if (isset($this->show_tag_cloud)) {
//              $args['show_tag_cloud'] = $this->show_tag_cloud;
//          }
//          if (isset($this->show_quick_edit)) {
//              $args['show_quick_edit'] = $this->show_quick_edit;
//          }
//          if (isset($this->show_admin_column)) {
//              $args['show_admin_column'] = $this->show_admin_column;
//          }
//          if (isset($this->meta_box_cb) && is_callable($this->meta_box_cb)) {
//              $args['meta_box_cb'] = $this->meta_box_cb;
//          }
//          if (isset($this->meta_box_sanitize_cb) && is_callable($this->meta_box_sanitize_cb)) {
//              $args['meta_box_sanitize_cb'] = $this->meta_box_sanitize_cb;
//          }
//          if (isset($this->capabilities)) {
//              $allowed = ['manage_terms', 'edit_terms', 'delete_terms', 'assign_terms'];
//              $caps = array_filter($this->capabilities, function ($cap) use ($allowed) {
//                  return in_array($cap, $allowed);
//              }, ARRAY_FILTER_USE_KEY);
//              $args['capabilities'] = $caps;
//          }
//          if (isset($this->query_var)) {
//              $args['query_var'] = $this->query_var;
//          }
//          if (isset($this->update_count_callback) && is_callable($this->update_count_callback)) {
//              $args['update_count_callback'] = $this->update_count_callback;
//          }
//          if (isset($this->default_term)) {
//              $args['default_term'] = $this->default_term;
//          }
//          if (isset($this->sort)) {
//              $args['sort'] = $this->sort;
//          }
//          if (isset($this->args)) {
//              $args['args'] = $this->args;
//          }
        unset($args['for']);
 
        $for = array_map(function($item) { return jvbCheckBase($item);}, $this->for);
        register_taxonomy(jvbCheckBase($this->taxonomy), $for, $args);
    }
}