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 / Groups.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
Groups.php
273 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\CREATE_Interface;
11 use Pods\REST\Interfaces\Endpoints\READ_Interface;
12 use Pods\REST\Interfaces\Swagger\Provider_Interface;
13 use WP_REST_Request;
14
15 class Groups extends Base implements READ_Interface, CREATE_Interface, Provider_Interface {
16
17 /**
18 * {@inheritdoc}
19 *
20 * @since 2.8.0
21 */
22 public $route = '/groups';
23
24 /**
25 * {@inheritdoc}
26 *
27 * @since 2.8.0
28 */
29 public $object = 'group';
30
31 /**
32 * {@inheritdoc}
33 *
34 * @since 2.8.0
35 */
36 public function get_documentation() {
37 $GET_defaults = [
38 'in' => 'query',
39 'default' => '',
40 'type' => 'string',
41 ];
42
43 $POST_defaults = [
44 'in' => 'body',
45 'default' => '',
46 'type' => 'string',
47 ];
48
49 return [
50 'get' => [
51 'summary' => 'Retrieve a collection of Groups',
52 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
53 'responses' => [
54 '200' => [
55 'description' => 'Returns a collection of Groups matching the request',
56 'content' => [
57 'application/json' => [
58 'schema' => [
59 'type' => 'object',
60 'properties' => [
61 'rest_url' => [
62 'type' => 'string',
63 'format' => 'uri',
64 'description' => __( 'This results page REST URL.', 'pods' ),
65 ],
66 'total' => [
67 'type' => 'integer',
68 'description' => __( 'The total number of results across all pages.', 'pods' ),
69 ],
70 'total_pages' => [
71 'type' => 'integer',
72 'description' => __( 'The total number of result pages matching the search criteria.', 'pods' ),
73 ],
74 'groups' => [
75 'type' => 'array',
76 'items' => [ '$ref' => '#/components/schemas/Group' ],
77 ],
78 ],
79 ],
80 ],
81 ],
82 ],
83 '400' => [
84 'description' => 'The request was invalid or cannot be otherwise served',
85 'content' => [
86 'application/json' => [
87 'schema' => [
88 'type' => 'object',
89 ],
90 ],
91 ],
92 ],
93 '401' => [
94 'description' => 'Unauthorized access - user does not have permission to access Groups',
95 'content' => [
96 'application/json' => [
97 'schema' => [
98 'type' => 'object',
99 ],
100 ],
101 ],
102 ],
103 ],
104 ],
105 'post' => [
106 'summary' => 'Create a new Group',
107 'parameters' => $this->swaggerize_args( $this->CREATE_args(), $POST_defaults ),
108 'responses' => [
109 '201' => [
110 'description' => 'Returns the newly created Group',
111 'content' => [
112 'application/json' => [
113 'schema' => [
114 '$ref' => '#/components/schemas/Group',
115 ],
116 ],
117 ],
118 ],
119 '400' => [
120 'description' => 'The request was invalid or cannot be otherwise served',
121 'content' => [
122 'application/json' => [
123 'schema' => [
124 'type' => 'object',
125 ],
126 ],
127 ],
128 ],
129 '401' => [
130 'description' => 'Unauthorized access - user does not have permission to create Groups',
131 'content' => [
132 'application/json' => [
133 'schema' => [
134 'type' => 'object',
135 ],
136 ],
137 ],
138 ],
139 '403' => [
140 'description' => 'Forbidden - creation of this Group is not allowed',
141 'content' => [
142 'application/json' => [
143 'schema' => [
144 'type' => 'object',
145 ],
146 ],
147 ],
148 ],
149 ],
150 ],
151 ];
152 }
153
154 /**
155 * {@inheritdoc}
156 *
157 * @since 2.8.0
158 */
159 public function READ_args() {
160 return [
161 'return_type' => [
162 'description' => __( 'The type of data to return.', 'pods' ),
163 'type' => 'string',
164 'default' => 'full',
165 'required' => false,
166 'enum' => [
167 'full',
168 'names',
169 'names_ids',
170 'ids',
171 'key_names',
172 'count',
173 ],
174 ],
175 'types' => [
176 'required' => false,
177 'description' => __( 'A list of types to filter by.', 'pods' ),
178 'swagger_type' => 'array',
179 'items' => [
180 'type' => 'string',
181 ],
182 'collectionFormat' => 'csv',
183 ],
184 'ids' => [
185 'required' => false,
186 'description' => __( 'A list of IDs to filter by.', 'pods' ),
187 'swagger_type' => 'array',
188 'items' => [
189 'type' => 'integer',
190 ],
191 'collectionFormat' => 'csv',
192 ],
193 'args' => [
194 'required' => false,
195 'description' => __( 'A list of arguments to filter by.', 'pods' ),
196 'swagger_type' => 'array',
197 ],
198 ];
199 }
200
201 /**
202 * {@inheritdoc}
203 *
204 * @since 2.8.0
205 */
206 public function get( WP_REST_Request $request ) {
207 return $this->archive_by_args( $request );
208 }
209
210 /**
211 * Determine whether access to READ is available.
212 *
213 * @since 2.8.0
214 *
215 * @return bool Whether access to READ is available.
216 */
217 public function can_read() {
218 return pods_is_admin( 'pods' );
219 }
220
221 /**
222 * {@inheritdoc}
223 *
224 * @since 2.8.0
225 */
226 public function CREATE_args() {
227 return [
228 'pod_id' => [
229 'type' => 'string',
230 'description' => __( 'The Pod ID.', 'pods' ),
231 'validate_callback' => [ $this->validator, 'is_pod_id' ],
232 ],
233 'pod' => [
234 'type' => 'string',
235 'description' => __( 'The Pod name.', 'pods' ),
236 'validate_callback' => [ $this->validator, 'is_pod_slug' ],
237 ],
238 'name' => [
239 'type' => 'string',
240 'description' => __( 'The name of the Group.', 'pods' ),
241 ],
242 'label' => [
243 'type' => 'string',
244 'description' => __( 'The singular label of the Group.', 'pods' ),
245 'required' => true,
246 ],
247 'args' => [
248 'required' => false,
249 'description' => __( 'A list of additional options to save to the Group.', 'pods' ),
250 'swagger_type' => 'array',
251 ],
252 ];
253 }
254
255 /**
256 * {@inheritdoc}
257 *
258 * @since 2.8.0
259 */
260 public function create( WP_REST_REQUEST $request, $return_id = false ) {
261 return $this->create_by_args( $request, $return_id );
262 }
263
264 /**
265 * {@inheritdoc}
266 *
267 * @since 2.8.0
268 */
269 public function can_create() {
270 return pods_is_admin( 'pods' );
271 }
272 }
273