|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\System\PostType; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Contracts\System\PostType\PostTypeInterface; |
|
6
|
|
|
use Leonidas\Library\System\AbstractSystemModelType; |
|
7
|
|
|
|
|
8
|
|
|
class PostType extends AbstractSystemModelType implements PostTypeInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected bool $isExcludedFromSearch; |
|
11
|
|
|
|
|
12
|
|
|
protected bool $isShownInAdminBar; |
|
13
|
|
|
|
|
14
|
|
|
protected ?int $menuPosition; |
|
15
|
|
|
|
|
16
|
|
|
protected ?string $menuIcon; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string|array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $capabilityType; |
|
22
|
|
|
|
|
23
|
|
|
protected bool $usesMapMetaCap; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var bool|array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $supports; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var null|callable |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $registerMetaBoxCb; |
|
34
|
|
|
|
|
35
|
|
|
protected array $taxonomies; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var bool|string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $archive; |
|
41
|
|
|
|
|
42
|
|
|
protected bool $canBeExported; |
|
43
|
|
|
|
|
44
|
|
|
protected ?bool $isDeletedWithUser; |
|
45
|
|
|
|
|
46
|
|
|
protected array $template; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var false|string |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $templateLock; |
|
52
|
|
|
|
|
53
|
|
|
public function __construct( |
|
54
|
|
|
string $name, |
|
55
|
|
|
string $pluralLabel, |
|
56
|
|
|
?string $singularLabel = null, |
|
57
|
|
|
string $description = '', |
|
58
|
|
|
array $labels = [], |
|
59
|
|
|
bool $isPublic = false, |
|
60
|
|
|
bool $isHierarchical = false, |
|
61
|
|
|
?bool $isPubliclyQueryable = null, |
|
62
|
|
|
?bool $isShownInUi = null, |
|
63
|
|
|
$shownInMenu = null, |
|
64
|
|
|
?bool $isShownInNavMenus = null, |
|
65
|
|
|
array $capabilities = [], |
|
66
|
|
|
$rewrite = true, |
|
67
|
|
|
$queryVar = true, |
|
68
|
|
|
bool $isShownInRest = false, |
|
69
|
|
|
$restBase = false, |
|
70
|
|
|
$restNamespace = false, |
|
71
|
|
|
$restControllerClass = false, |
|
72
|
|
|
?bool $isExcludedFromSearch = null, |
|
73
|
|
|
?bool $isShownInAdminBar = null, |
|
74
|
|
|
?int $menuPosition = null, |
|
75
|
|
|
?string $menuIcon = null, |
|
76
|
|
|
$capabilityType = 'post', |
|
77
|
|
|
bool $usesMapMetaCap = false, |
|
78
|
|
|
$supports = [], |
|
79
|
|
|
?callable $registerMetaBoxCb = null, |
|
80
|
|
|
array $taxonomies = [], |
|
81
|
|
|
$archive = false, |
|
82
|
|
|
bool $canBeExported = true, |
|
83
|
|
|
?bool $isDeletedWithUser = null, |
|
84
|
|
|
array $template = [], |
|
85
|
|
|
$templateLock = false, |
|
86
|
|
|
array $options = [] |
|
87
|
|
|
) { |
|
88
|
|
|
parent::__construct( |
|
89
|
|
|
$name, |
|
90
|
|
|
$pluralLabel, |
|
91
|
|
|
$singularLabel, |
|
|
|
|
|
|
92
|
|
|
$description, |
|
93
|
|
|
$labels, |
|
94
|
|
|
$isPublic, |
|
95
|
|
|
$isHierarchical, |
|
96
|
|
|
$isPubliclyQueryable, |
|
97
|
|
|
$isShownInUi, |
|
98
|
|
|
$shownInMenu, |
|
99
|
|
|
$isShownInNavMenus, |
|
100
|
|
|
$capabilities, |
|
101
|
|
|
$rewrite, |
|
102
|
|
|
$queryVar, |
|
103
|
|
|
$isShownInRest, |
|
104
|
|
|
$restBase, |
|
105
|
|
|
$restNamespace, |
|
106
|
|
|
$restControllerClass, |
|
107
|
|
|
$options |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
$this->menuPosition = $menuPosition; |
|
111
|
|
|
$this->menuIcon = $menuIcon; |
|
112
|
|
|
$this->usesMapMetaCap = $usesMapMetaCap; |
|
113
|
|
|
$this->capabilityType = $capabilityType; |
|
114
|
|
|
$this->supports = $supports; |
|
115
|
|
|
$this->registerMetaBoxCb = $registerMetaBoxCb; |
|
116
|
|
|
$this->taxonomies = $taxonomies; |
|
117
|
|
|
$this->archive = $archive; |
|
118
|
|
|
$this->canBeExported = $canBeExported; |
|
119
|
|
|
$this->isDeletedWithUser = $isDeletedWithUser; |
|
120
|
|
|
$this->template = $template; |
|
121
|
|
|
$this->templateLock = $templateLock; |
|
122
|
|
|
|
|
123
|
|
|
$this->isExcludedFromSearch = $isExcludedFromSearch ?? $this->isPublic; |
|
124
|
|
|
$this->isShownInAdminBar = $isShownInAdminBar ?? $this->shownInMenu; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function isExcludedFromSearch(): bool |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->isExcludedFromSearch; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function isShownInAdminBar(): bool |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->isShownInAdminBar; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function getMenuPosition(): int |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->menuPosition; |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function getMenuIcon(): ?string |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->menuIcon; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function getCapabilityType() |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->capabilityType; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function usesMapMetaCap(): bool |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->usesMapMetaCap; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function getSupports() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->supports; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function getRegisterMetaBoxCb(): ?callable |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->registerMetaBoxCb; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function getTaxonomies(): array |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->taxonomies; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function getArchive() |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->archive; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function canBeExported(): bool |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->canBeExported; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function isDeletedWithUser(): ?bool |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->isDeletedWithUser; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function getTemplate(): array |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->template; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function getTemplateLock() |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->templateLock; |
|
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
protected function defaultLabels(): array |
|
198
|
|
|
{ |
|
199
|
|
|
$singleUpper = $this->getSingularLabel(); |
|
200
|
|
|
$pluralUpper = $this->getPluralLabel(); |
|
201
|
|
|
$singleLower = strtolower($singleUpper); |
|
202
|
|
|
$pluralLower = strtolower($pluralUpper); |
|
203
|
|
|
|
|
204
|
|
|
return [ |
|
205
|
|
|
'name' => $pluralUpper, |
|
206
|
|
|
'singular_name' => $singleUpper, |
|
207
|
|
|
'add_new_item' => "Add New {$singleUpper}", |
|
208
|
|
|
'edit_item' => "Edit {$singleUpper}", |
|
209
|
|
|
'new_item' => "New {$singleUpper}", |
|
210
|
|
|
'view_item' => "View {$singleUpper}", |
|
211
|
|
|
'view_items' => "View {$pluralUpper}", |
|
212
|
|
|
'search_items' => "Search {$pluralUpper}", |
|
213
|
|
|
'not_found' => "No {$pluralLower} found", |
|
214
|
|
|
'not_found_in_trash' => "No {$pluralLower} found in Trash", |
|
215
|
|
|
'parent_item_colon' => "Parent {$singleUpper}:", |
|
216
|
|
|
'all_items' => "All {$pluralUpper}", |
|
217
|
|
|
'archives' => "{$singleUpper} Archives", |
|
218
|
|
|
'attributes' => "{$singleUpper} Attributes", |
|
219
|
|
|
'insert_into_item' => "Insert into {$singleLower}", |
|
220
|
|
|
'uploaded_to_this_item' => "Uploaded to this {$singleLower}", |
|
221
|
|
|
'filter_items_list' => "Filter {$pluralLower} list", |
|
222
|
|
|
'items_list_navigation' => "{$pluralUpper} list navigation", |
|
223
|
|
|
'items_list' => "{$pluralUpper} list", |
|
224
|
|
|
'item_published' => "{$singleUpper} published", |
|
225
|
|
|
'item_published_privately' => "{$singleUpper} published privately", |
|
226
|
|
|
'item_reverted_to_draft' => "{$singleUpper} reverted to draft", |
|
227
|
|
|
'item_scheduled' => "{$singleUpper} scheduled", |
|
228
|
|
|
'item_updated' => "{$singleUpper} updated", |
|
229
|
|
|
]; |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|