-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPost_Preview_Service.php
More file actions
134 lines (115 loc) · 2.64 KB
/
Copy pathPost_Preview_Service.php
File metadata and controls
134 lines (115 loc) · 2.64 KB
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
<?php
declare(strict_types=1);
namespace HWP\Previews\Preview\Post;
/**
* Post Preview Service class
*
* This class provides methods to get the allowed post-types and statuses for previews.
*
* @package HWP\Previews
*
* @since 0.0.1
*/
class Post_Preview_Service {
/**
* The allowed post-types for previews.
*
* @var array<string>
*/
protected $post_types = [];
/**
* The allowed post-statuses for previews.
*
* @var array<string>
*/
protected $post_statuses = [];
/**
* The allowed post-statuses for parent post-types (hierarchical).
*
* @var array<string>
*/
protected $parent_post_statuses = [];
/**
* @return array<string>
*/
public function get_allowed_post_types(): array {
return $this->get_post_types();
}
/**
* Get the post-statuses.
*
* @return array<string>
*/
public function get_post_statuses(): array {
$post_statuses = $this->post_statuses;
if ([] !== $post_statuses) {
return $post_statuses;
}
$this->set_post_statuses();
return $this->post_statuses;
}
/**
* Get the post-types.
*
* @return array<string>
*/
public function get_post_types(): array {
$post_types = $this->post_types;
if ([] !== $post_types) {
return $post_types;
}
$this->set_post_types();
return $this->post_types;
}
/**
* Get the parent post-statuses
*
* @return array<string>
*/
public function get_parent_post_statuses(): array {
$parent_post_statuses = $this->parent_post_statuses;
if ([] !== $parent_post_statuses) {
return $parent_post_statuses;
}
$this->set_post_parent_statuses();
return $this->parent_post_statuses;
}
/**
* Sets the allowed post-types for previews.
*/
protected function set_post_types(): void {
$post_types = get_post_types( [ 'public' => true ], 'objects' );
$result = [];
foreach ( $post_types as $post_type ) {
$result[ $post_type->name ] = $post_type->label;
}
$this->post_types = apply_filters( 'hwp_previews_filter_available_post_types', $result );
}
/**
* Sets the allowed post-statuses for previews.
*/
protected function set_post_statuses(): void {
$post_statuses = [
'publish',
'future',
'draft',
'pending',
'private',
'auto-draft',
];
$this->post_statuses = apply_filters( 'hwp_previews_filter_available_post_statuses', $post_statuses );
}
/**
* Sets the allowed post-statuses for parent post-types (hierarchical).
*/
protected function set_post_parent_statuses(): void {
$post_statuses = [
'publish',
'future',
'draft',
'pending',
'private',
];
$this->parent_post_statuses = apply_filters( 'hwp_previews_filter_available_parent_post_statuses', $post_statuses );
}
}