PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / trunk
Pods – Custom Content Types and Fields vtrunk
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 4 months ago Field.php 4 months ago Field_Slug.php 4 months ago Fields.php 4 months ago Group.php 4 months ago Group_Slug.php 4 months ago Groups.php 4 months ago Pod.php 4 months ago Pod_Slug.php 4 months ago Pods.php 4 months ago Swagger_Documentation.php 4 months ago
Pod.php
358 lines
1 <?php
2
3 namespace Pods\REST\V1\Endpoints;
4
5 // Don't load directly.
6 if ( ! defined( 'ABSPATH' ) ) {
7 die( '-1' );
8 }
9
10 use Pods\REST\Interfaces\Endpoints\DELETE_Interface;
11 use Pods\REST\Interfaces\Endpoints\READ_Interface;
12 use Pods\REST\Interfaces\Endpoints\UPDATE_Interface;
13 use Pods\REST\Interfaces\Swagger\Provider_Interface;
14 use WP_REST_Request;
15
16 class Pod extends Base implements READ_Interface, UPDATE_Interface, DELETE_Interface, Provider_Interface {
17
18 /**
19 * {@inheritdoc}
20 *
21 * @since 2.8.0
22 */
23 public $route = '/pods/%1$d';
24
25 /**
26 * {@inheritdoc}
27 *
28 * @since 2.8.11
29 */
30 public $rest_route = '/pods/(?P<id>\\d+)';
31
32 /**
33 * {@inheritdoc}
34 *
35 * @since 2.8.11
36 */
37 public $rest_doc_route = '/pods/{id}';
38
39 /**
40 * {@inheritdoc}
41 *
42 * @since 2.8.0
43 */
44 public $object = 'pod';
45
46 /**
47 * {@inheritdoc}
48 *
49 * @since 2.8.0
50 */
51 public function get_documentation() {
52 $GET_defaults = [
53 'in' => 'query',
54 'default' => '',
55 'type' => 'string',
56 ];
57
58 $POST_defaults = [
59 'in' => 'body',
60 'default' => '',
61 'type' => 'string',
62 ];
63
64 return [
65 'get' => [
66 'summary' => 'Retrieve a specific Pod',
67 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
68 'responses' => [
69 '200' => [
70 'description' => 'Returns the requested Pod with its details',
71 'content' => [
72 'application/json' => [
73 'schema' => [
74 '$ref' => '#/components/schemas/Pod',
75 ],
76 ],
77 ],
78 ],
79 '400' => [
80 'description' => 'The request was invalid or cannot be otherwise served',
81 'content' => [
82 'application/json' => [
83 'schema' => [
84 'type' => 'object',
85 ],
86 ],
87 ],
88 ],
89 '401' => [
90 'description' => 'Unauthorized access - user does not have permission to access this Pod',
91 'content' => [
92 'application/json' => [
93 'schema' => [
94 'type' => 'object',
95 ],
96 ],
97 ],
98 ],
99 '404' => [
100 'description' => 'The requested Pod was not found',
101 'content' => [
102 'application/json' => [
103 'schema' => [
104 'type' => 'object',
105 ],
106 ],
107 ],
108 ],
109 ],
110 ],
111 'put' => [
112 'summary' => 'Update a specific Pod',
113 'parameters' => $this->swaggerize_args( $this->EDIT_args(), $POST_defaults ),
114 'responses' => [
115 '200' => [
116 'description' => 'Returns the updated Pod',
117 'content' => [
118 'application/json' => [
119 'schema' => [
120 '$ref' => '#/components/schemas/Pod',
121 ],
122 ],
123 ],
124 ],
125 '400' => [
126 'description' => 'The request was invalid or cannot be otherwise served',
127 'content' => [
128 'application/json' => [
129 'schema' => [
130 'type' => 'object',
131 ],
132 ],
133 ],
134 ],
135 '401' => [
136 'description' => 'Unauthorized access - user does not have permission to update this Pod',
137 'content' => [
138 'application/json' => [
139 'schema' => [
140 'type' => 'object',
141 ],
142 ],
143 ],
144 ],
145 '404' => [
146 'description' => 'The Pod to update was not found',
147 'content' => [
148 'application/json' => [
149 'schema' => [
150 'type' => 'object',
151 ],
152 ],
153 ],
154 ],
155 ],
156 ],
157 'delete' => [
158 'summary' => 'Delete a specific Pod',
159 'parameters' => $this->swaggerize_args( $this->DELETE_args(), $POST_defaults ),
160 'responses' => [
161 '200' => [
162 'description' => 'Returns the deleted Pod details',
163 'content' => [
164 'application/json' => [
165 'schema' => [
166 '$ref' => '#/components/schemas/Pod',
167 ],
168 ],
169 ],
170 ],
171 '400' => [
172 'description' => 'The request was invalid or cannot be otherwise served',
173 'content' => [
174 'application/json' => [
175 'schema' => [
176 'type' => 'object',
177 ],
178 ],
179 ],
180 ],
181 '401' => [
182 'description' => 'Unauthorized access - user does not have permission to delete this Pod',
183 'content' => [
184 'application/json' => [
185 'schema' => [
186 'type' => 'object',
187 ],
188 ],
189 ],
190 ],
191 '404' => [
192 'description' => 'The Pod to delete was not found',
193 'content' => [
194 'application/json' => [
195 'schema' => [
196 'type' => 'object',
197 ],
198 ],
199 ],
200 ],
201 ],
202 ],
203 ];
204 }
205
206 /**
207 * {@inheritdoc}
208 *
209 * @since 2.8.0
210 */
211 public function READ_args() {
212 return [
213 'id' => [
214 'type' => 'integer',
215 'in' => 'path',
216 'description' => __( 'The Pod ID.', 'pods' ),
217 'required' => true,
218 'validate_callback' => [ $this->validator, 'is_pod_id' ],
219 ],
220 'include_fields' => [
221 'type' => 'boolean',
222 'description' => __( 'Whether to include fields (default: off).', 'pods' ),
223 'default' => false,
224 'cli_boolean' => true,
225 ],
226 'include_groups' => [
227 'type' => 'boolean',
228 'description' => __( 'Whether to include groups (default: off).', 'pods' ),
229 'default' => false,
230 'cli_boolean' => true,
231 ],
232 'include_group_fields' => [
233 'type' => 'boolean',
234 'description' => __( 'Whether to include group fields (default: off).', 'pods' ),
235 'default' => false,
236 'cli_boolean' => true,
237 ],
238 ];
239 }
240
241 /**
242 * {@inheritdoc}
243 *
244 * @since 2.8.0
245 */
246 public function get( WP_REST_Request $request ) {
247 return $this->get_by_args( 'id', 'id', $request );
248 }
249
250 /**
251 * Determine whether access to READ is available.
252 *
253 * @since 2.8.0
254 *
255 * @return bool Whether access to READ is available.
256 */
257 public function can_read() {
258 return pods_is_admin( 'pods' );
259 }
260
261 /**
262 * {@inheritdoc}
263 *
264 * @since 2.8.0
265 */
266 public function EDIT_args() {
267 return [
268 'id' => [
269 'type' => 'integer',
270 'in' => 'path',
271 'description' => __( 'The Pod ID.', 'pods' ),
272 'required' => true,
273 'validate_callback' => [ $this->validator, 'is_pod_id' ],
274 ],
275 'name' => [
276 'type' => 'string',
277 'description' => __( 'The new name of the Pod.', 'pods' ),
278 ],
279 'label' => [
280 'type' => 'string',
281 'description' => __( 'The singular label of the Pod.', 'pods' ),
282 ],
283 'args' => [
284 'required' => false,
285 'description' => __( 'A list of additional options to save to the Pod.', 'pods' ),
286 'swagger_type' => 'array',
287 ],
288 ];
289 }
290
291 /**
292 * {@inheritdoc}
293 *
294 * @since 2.8.0
295 */
296 public function update( WP_REST_Request $request ) {
297 if ( ! empty( $request['groups'] ) ) {
298 $request->set_param( 'groups', null );
299 }
300
301 if ( ! empty( $request['fields'] ) ) {
302 $request->set_param( 'fields', null );
303 }
304
305 return $this->update_by_args( 'id', 'id', $request );
306 }
307
308 /**
309 * {@inheritdoc}
310 *
311 * @since 2.8.0
312 */
313 public function can_edit() {
314 return pods_is_admin( 'pods' );
315 }
316
317 /**
318 * {@inheritdoc}
319 *
320 * @since 2.8.0
321 */
322 public function DELETE_args() {
323 return [
324 'id' => [
325 'type' => 'integer',
326 'in' => 'path',
327 'description' => __( 'The Pod ID.', 'pods' ),
328 'required' => true,
329 'validate_callback' => [ $this->validator, 'is_pod_id' ],
330 ],
331 'delete_all' => [
332 'type' => 'boolean',
333 'description' => __( 'Whether to delete all content for Pod (default: off).', 'pods' ),
334 'default' => false,
335 'cli_boolean' => true,
336 ],
337 ];
338 }
339
340 /**
341 * {@inheritdoc}
342 *
343 * @since 2.8.0
344 */
345 public function delete( WP_REST_Request $request ) {
346 return $this->delete_by_args( 'id', 'id', $request );
347 }
348
349 /**
350 * {@inheritdoc}
351 *
352 * @since 2.8.0
353 */
354 public function can_delete() {
355 return pods_is_admin( 'pods' );
356 }
357 }
358