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 / Group.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
Group.php
340 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 Group 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 = '/groups/%1$d';
24
25 /**
26 * {@inheritdoc}
27 *
28 * @since 2.8.11
29 */
30 public $rest_route = '/groups/(?P<id>\\d+)';
31
32 /**
33 * {@inheritdoc}
34 *
35 * @since 2.8.11
36 */
37 public $rest_doc_route = '/groups/{id}';
38
39 /**
40 * {@inheritdoc}
41 *
42 * @since 2.8.0
43 */
44 public $object = 'group';
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 Group',
67 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
68 'responses' => [
69 '200' => [
70 'description' => 'Returns the requested Group with its details',
71 'content' => [
72 'application/json' => [
73 'schema' => [
74 '$ref' => '#/components/schemas/Group',
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 Group',
91 'content' => [
92 'application/json' => [
93 'schema' => [
94 'type' => 'object',
95 ],
96 ],
97 ],
98 ],
99 '404' => [
100 'description' => 'The requested Group 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 Group',
113 'parameters' => $this->swaggerize_args( $this->EDIT_args(), $POST_defaults ),
114 'responses' => [
115 '200' => [
116 'description' => 'Returns the updated Group',
117 'content' => [
118 'application/json' => [
119 'schema' => [
120 '$ref' => '#/components/schemas/Group',
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 Group',
137 'content' => [
138 'application/json' => [
139 'schema' => [
140 'type' => 'object',
141 ],
142 ],
143 ],
144 ],
145 '404' => [
146 'description' => 'The Group 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 Group',
159 'parameters' => $this->swaggerize_args( $this->DELETE_args(), $POST_defaults ),
160 'responses' => [
161 '200' => [
162 'description' => 'Returns the deleted Group details',
163 'content' => [
164 'application/json' => [
165 'schema' => [
166 '$ref' => '#/components/schemas/Group',
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 Group',
183 'content' => [
184 'application/json' => [
185 'schema' => [
186 'type' => 'object',
187 ],
188 ],
189 ],
190 ],
191 '404' => [
192 'description' => 'The Group 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 Group ID.', 'pods' ),
217 'required' => true,
218 'validate_callback' => [ $this->validator, 'is_group_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 ];
227 }
228
229 /**
230 * {@inheritdoc}
231 *
232 * @since 2.8.0
233 */
234 public function get( WP_REST_Request $request ) {
235 return $this->get_by_args( 'id', 'id', $request );
236 }
237
238 /**
239 * Determine whether access to READ is available.
240 *
241 * @since 2.8.0
242 *
243 * @return bool Whether access to READ is available.
244 */
245 public function can_read() {
246 return pods_is_admin( 'pods' );
247 }
248
249 /**
250 * {@inheritdoc}
251 *
252 * @since 2.8.0
253 */
254 public function EDIT_args() {
255 return [
256 'id' => [
257 'type' => 'integer',
258 'in' => 'path',
259 'description' => __( 'The Group ID.', 'pods' ),
260 'required' => true,
261 'validate_callback' => [ $this->validator, 'is_group_id' ],
262 ],
263 'name' => [
264 'type' => 'string',
265 'description' => __( 'The new name of the Group.', 'pods' ),
266 ],
267 'label' => [
268 'type' => 'string',
269 'description' => __( 'The singular label of the Group.', 'pods' ),
270 ],
271 'type' => [
272 'type' => 'string',
273 'description' => __( 'The type of the Group.', 'pods' ),
274 ],
275 'args' => [
276 'required' => false,
277 'description' => __( 'A list of additional options to save to the Group.', 'pods' ),
278 'swagger_type' => 'array',
279 ],
280 ];
281 }
282
283 /**
284 * {@inheritdoc}
285 *
286 * @since 2.8.0
287 */
288 public function update( WP_REST_Request $request ) {
289 if ( ! empty( $request['fields'] ) ) {
290 $request->set_param( 'fields', null );
291 }
292
293 return $this->update_by_args( 'id', 'id', $request );
294 }
295
296 /**
297 * {@inheritdoc}
298 *
299 * @since 2.8.0
300 */
301 public function can_edit() {
302 return pods_is_admin( 'pods' );
303 }
304
305 /**
306 * {@inheritdoc}
307 *
308 * @since 2.8.0
309 */
310 public function DELETE_args() {
311 return [
312 'id' => [
313 'type' => 'integer',
314 'in' => 'path',
315 'description' => __( 'The Group ID.', 'pods' ),
316 'required' => true,
317 'validate_callback' => [ $this->validator, 'is_group_id' ],
318 ],
319 ];
320 }
321
322 /**
323 * {@inheritdoc}
324 *
325 * @since 2.8.0
326 */
327 public function delete( WP_REST_Request $request ) {
328 return $this->delete_by_args( 'id', 'id', $request );
329 }
330
331 /**
332 * {@inheritdoc}
333 *
334 * @since 2.8.0
335 */
336 public function can_delete() {
337 return pods_is_admin( 'pods' );
338 }
339 }
340