PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.5
Pods – Custom Content Types and Fields v3.2.5
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / REST / V1 / Endpoints / Pod.php
pods / src / Pods / REST / V1 / Endpoints Last commit date
Base.php 3 years ago Field.php 3 years ago Field_Slug.php 4 years ago Fields.php 3 years ago Group.php 3 years ago Group_Slug.php 4 years ago Groups.php 3 years ago Pod.php 3 years ago Pod_Slug.php 4 years ago Pods.php 3 years ago Swagger_Documentation.php 3 years ago
Pod.php
257 lines
1 <?php
2
3 namespace Pods\REST\V1\Endpoints;
4
5 use Pods\REST\Interfaces\Endpoints\DELETE_Interface;
6 use Pods\REST\Interfaces\Endpoints\READ_Interface;
7 use Pods\REST\Interfaces\Endpoints\UPDATE_Interface;
8 use Pods\REST\Interfaces\Swagger\Provider_Interface;
9 use WP_REST_Request;
10
11 class Pod extends Base implements READ_Interface, UPDATE_Interface, DELETE_Interface, Provider_Interface {
12
13 /**
14 * {@inheritdoc}
15 *
16 * @since 2.8.0
17 */
18 public $route = '/pods/%1$d';
19
20 /**
21 * {@inheritdoc}
22 *
23 * @since 2.8.11
24 */
25 public $rest_route = '/pods/(?P<id>\\d+)';
26
27 /**
28 * {@inheritdoc}
29 *
30 * @since 2.8.11
31 */
32 public $rest_doc_route = '/pods/{id}';
33
34 /**
35 * {@inheritdoc}
36 *
37 * @since 2.8.0
38 */
39 public $object = 'pod';
40
41 /**
42 * {@inheritdoc}
43 *
44 * @since 2.8.0
45 */
46 public function get_documentation() {
47 $GET_defaults = [
48 'in' => 'query',
49 'default' => '',
50 'type' => 'string',
51 ];
52
53 // @todo Handle get/post/delete
54
55 return [
56 'get' => [
57 'summary' => '', // @todo Fill this out
58 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
59 'responses' => [
60 '200' => [
61 'description' => '', // @todo Fill this out
62 'content' => [
63 'application/json' => [
64 'schema' => [
65 '$ref' => '#/components/schemas/Pod',
66 ],
67 ],
68 ],
69 ],
70 '400' => [
71 'description' => '', // @todo Fill this out
72 'content' => [
73 'application/json' => [
74 'schema' => [
75 'type' => 'object',
76 ],
77 ],
78 ],
79 ],
80 '401' => [
81 'description' => '', // @todo Fill this out
82 'content' => [
83 'application/json' => [
84 'schema' => [
85 'type' => 'object',
86 ],
87 ],
88 ],
89 ],
90 '404' => [
91 'description' => '', // @todo Fill this out
92 'content' => [
93 'application/json' => [
94 'schema' => [
95 'type' => 'object',
96 ],
97 ],
98 ],
99 ],
100 ],
101 ],
102 ];
103 }
104
105 /**
106 * {@inheritdoc}
107 *
108 * @since 2.8.0
109 */
110 public function READ_args() {
111 return [
112 'id' => [
113 'type' => 'integer',
114 'in' => 'path',
115 'description' => __( 'The Pod ID.', 'pods' ),
116 'required' => true,
117 'validate_callback' => [ $this->validator, 'is_pod_id' ],
118 ],
119 'include_fields' => [
120 'type' => 'boolean',
121 'description' => __( 'Whether to include fields (default: off).', 'pods' ),
122 'default' => false,
123 'cli_boolean' => true,
124 ],
125 'include_groups' => [
126 'type' => 'boolean',
127 'description' => __( 'Whether to include groups (default: off).', 'pods' ),
128 'default' => false,
129 'cli_boolean' => true,
130 ],
131 'include_group_fields' => [
132 'type' => 'boolean',
133 'description' => __( 'Whether to include group fields (default: off).', 'pods' ),
134 'default' => false,
135 'cli_boolean' => true,
136 ],
137 ];
138 }
139
140 /**
141 * {@inheritdoc}
142 *
143 * @since 2.8.0
144 */
145 public function get( WP_REST_Request $request ) {
146 return $this->get_by_args( 'id', 'id', $request );
147 }
148
149 /**
150 * Determine whether access to READ is available.
151 *
152 * @since 2.8.0
153 *
154 * @return bool Whether access to READ is available.
155 */
156 public function can_read() {
157 return pods_is_admin( 'pods' );
158 }
159
160 /**
161 * {@inheritdoc}
162 *
163 * @since 2.8.0
164 */
165 public function EDIT_args() {
166 return [
167 'id' => [
168 'type' => 'integer',
169 'in' => 'path',
170 'description' => __( 'The Pod ID.', 'pods' ),
171 'required' => true,
172 'validate_callback' => [ $this->validator, 'is_pod_id' ],
173 ],
174 'name' => [
175 'type' => 'string',
176 'description' => __( 'The new name of the Pod.', 'pods' ),
177 ],
178 'label' => [
179 'type' => 'string',
180 'description' => __( 'The singular label of the Pod.', 'pods' ),
181 ],
182 'args' => [
183 'required' => false,
184 'description' => __( 'A list of additional options to save to the Pod.', 'pods' ),
185 'swagger_type' => 'array',
186 ],
187 ];
188 }
189
190 /**
191 * {@inheritdoc}
192 *
193 * @since 2.8.0
194 */
195 public function update( WP_REST_Request $request ) {
196 if ( ! empty( $request['groups'] ) ) {
197 $request->set_param( 'groups', null );
198 }
199
200 if ( ! empty( $request['fields'] ) ) {
201 $request->set_param( 'fields', null );
202 }
203
204 return $this->update_by_args( 'id', 'id', $request );
205 }
206
207 /**
208 * {@inheritdoc}
209 *
210 * @since 2.8.0
211 */
212 public function can_edit() {
213 return pods_is_admin( 'pods' );
214 }
215
216 /**
217 * {@inheritdoc}
218 *
219 * @since 2.8.0
220 */
221 public function DELETE_args() {
222 return [
223 'id' => [
224 'type' => 'integer',
225 'in' => 'path',
226 'description' => __( 'The Pod ID.', 'pods' ),
227 'required' => true,
228 'validate_callback' => [ $this->validator, 'is_pod_id' ],
229 ],
230 'delete_all' => [
231 'type' => 'boolean',
232 'description' => __( 'Whether to delete all content for Pod (default: off).', 'pods' ),
233 'default' => false,
234 'cli_boolean' => true,
235 ],
236 ];
237 }
238
239 /**
240 * {@inheritdoc}
241 *
242 * @since 2.8.0
243 */
244 public function delete( WP_REST_Request $request ) {
245 return $this->delete_by_args( 'id', 'id', $request );
246 }
247
248 /**
249 * {@inheritdoc}
250 *
251 * @since 2.8.0
252 */
253 public function can_delete() {
254 return pods_is_admin( 'pods' );
255 }
256 }
257