1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silk\PostType; |
4
|
|
|
|
5
|
|
|
use Silk\Type\Builder as BaseBuilder; |
6
|
|
|
use Silk\PostType\Exception\InvalidPostTypeNameException; |
7
|
|
|
|
8
|
|
|
class Builder extends BaseBuilder |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Default PostType labels |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected $labelDefaults = [ |
15
|
|
|
'add_new_item' => 'Add New {one}', |
16
|
|
|
'all_items' => 'All {many}', |
17
|
|
|
'archives' => '{one} Archives', |
18
|
|
|
'edit_item' => 'Edit {one}', |
19
|
|
|
'filter_items_list' => 'Filter {many} list', |
20
|
|
|
'insert_into_item' => 'Insert into {one}', |
21
|
|
|
'items_list_navigation' => '{many} list navigation', |
22
|
|
|
'items_list' => '{many} list', |
23
|
|
|
'menu_name' => '{many}', |
24
|
|
|
'name_admin_bar' => '{one}', |
25
|
|
|
'name' => '{many}', |
26
|
|
|
'new_item' => 'New {one}', |
27
|
|
|
'not_found_in_trash' => 'No {many} found in Trash.', |
28
|
|
|
'not_found' => 'No {many} found.', |
29
|
|
|
'search_items' => 'Search {many}', |
30
|
|
|
'singular_name' => '{one}', |
31
|
|
|
'uploaded_to_this_item' => 'Uploaded to this {one}', |
32
|
|
|
'view_item' => 'View {one}', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Specify which features the post type supports. |
37
|
|
|
* |
38
|
|
|
* @param mixed $features array of features |
39
|
|
|
* string ...$features features as parameters |
40
|
|
|
* |
41
|
|
|
* @return $this |
42
|
|
|
*/ |
43
|
|
|
public function supports($features) |
44
|
|
|
{ |
45
|
|
|
if (! is_array($features)) { |
46
|
|
|
$features = func_get_args(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $this->set('supports', $features); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set the post type as publicly available. |
54
|
|
|
* |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function open() |
58
|
|
|
{ |
59
|
|
|
return $this->set('public', true); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set the post type as non-publicly available. |
64
|
|
|
* |
65
|
|
|
* @return $this |
66
|
|
|
*/ |
67
|
|
|
public function closed() |
68
|
|
|
{ |
69
|
|
|
return $this->set('public', false); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Enable admin interface. |
74
|
|
|
* |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function withUI() |
78
|
|
|
{ |
79
|
|
|
return $this->set('show_ui', true); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Disable admin interface. |
84
|
|
|
* |
85
|
|
|
* @return $this |
86
|
|
|
*/ |
87
|
|
|
public function noUI() |
88
|
|
|
{ |
89
|
|
|
return $this->set('show_ui', false); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Register the post type. |
94
|
|
|
* |
95
|
|
|
* @return PostType |
96
|
|
|
*/ |
97
|
|
|
public function register() |
98
|
|
|
{ |
99
|
|
|
if (! $this->id || strlen($this->id) > 20) { |
100
|
|
|
throw new InvalidPostTypeNameException('Post type names must be between 1 and 20 characters in length.'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$object = register_post_type($this->id, $this->assembleArgs()); |
104
|
|
|
|
105
|
|
|
return new PostType($object); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|