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