|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\Core\Models\Taxonomy; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Library\Core\Models\AbstractWpConfigModelBuilder; |
|
6
|
|
|
|
|
7
|
|
|
class Taxonomy extends AbstractWpConfigModelBuilder |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var string|array |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $objectTypes; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct(string $name, $objectTypes) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->name = $name; |
|
20
|
|
|
$this->objectTypes = $objectTypes; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get the value of objectTypes |
|
25
|
|
|
* |
|
26
|
|
|
* @return string|array |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getObjectTypes() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->objectTypes; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
*/ |
|
36
|
|
|
public function register() |
|
37
|
|
|
{ |
|
38
|
|
|
register_taxonomy($this->name, $this->objectTypes, $this->buildArgs($this->args)); |
|
39
|
|
|
|
|
40
|
|
|
$this->registerForObjectTypes(); |
|
41
|
|
|
|
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* pair taxonomy to provided object types |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function registerForObjectTypes() |
|
49
|
|
|
{ |
|
50
|
|
|
foreach ((array) $this->objectTypes as $objectType) { |
|
51
|
|
|
register_taxonomy_for_object_type($this->name, $objectType); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getRegisteredTaxonomy() |
|
61
|
|
|
{ |
|
62
|
|
|
return get_taxonomy($this->name); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getDefaultLabels(string $single, string $plural): array |
|
69
|
|
|
{ |
|
70
|
|
|
$pluralLower = strtolower($plural); |
|
71
|
|
|
|
|
72
|
|
|
return [ |
|
73
|
|
|
'name' => $plural, |
|
74
|
|
|
'singular_name' => $single, |
|
75
|
|
|
'search_items' => "Search {$plural}", |
|
76
|
|
|
'popular_items' => "Popular {$plural}", |
|
77
|
|
|
'all_items' => "All {$plural}", |
|
78
|
|
|
'parent_item' => "Parent {$single}", |
|
79
|
|
|
'parent_item_colon' => "Parent {$single}:", |
|
80
|
|
|
'edit_item' => "Edit {$single}", |
|
81
|
|
|
'view_item' => "View {$single}", |
|
82
|
|
|
'update_item' => "Update {$plural}", |
|
83
|
|
|
'add_new_item' => "Add New {$single}", |
|
84
|
|
|
'new_item_name' => "New {$single} Name", |
|
85
|
|
|
'separate_items_with_commas' => "Separate {$pluralLower} with commas", |
|
86
|
|
|
'add_or_remove_items' => "Add or remove {$pluralLower}", |
|
87
|
|
|
'choose_from_most_used' => "Choose from the most used {$pluralLower}", |
|
88
|
|
|
'not_found' => "No {$pluralLower} found", |
|
89
|
|
|
'no_terms' => "No {$pluralLower}", |
|
90
|
|
|
'items_list_navigation' => "{$plural} list navigation", |
|
91
|
|
|
'items_list' => "{$plural} list", |
|
92
|
|
|
'back_to_items' => "← Back to {$plural}" |
|
93
|
|
|
]; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|