PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Onboarding / Routes / FormRoute.php

FormRoute.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Onboarding/Routes/FormRoute.php

88 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Onboarding\Routes;
4
5 use Give\API\RestRoute;
6 use Give\Onboarding\FormRepository;
7 use WP_REST_Request;
8
9 /**
10 * @since 2.8.0
11 */
12 class FormRoute implements RestRoute
13 {
14
15 /** @var string */
16 protected $endpoint = 'onboarding/form';
17
18 /** @var FormRepository */
19 protected $formRepository;
20
21 /**
22 * @since 2.8.0
23 *
24 * @param FormRepository $formRepository
25 *
26 */
27 public function __construct(FormRepository $formRepository)
28 {
29 $this->formRepository = $formRepository;
30 }
31
32 /**
33 * @since 2.8.0
34 *
35 * @param WP_REST_Request $request
36 *
37 * @return array
38 *
39 */
40 public function handleRequest(WP_REST_Request $request)
41 {
42 return [
43 'formID' => $this->formRepository->getOrMake(),
44 ];
45 }
46
47 /**
48 * @inheritDoc
49 */
50 public function registerRoute()
51 {
52 register_rest_route(
53 'give-api/v2',
54 $this->endpoint,
55 [
56 [
57 'methods' => 'POST',
58 'callback' => [$this, 'handleRequest'],
59 'permission_callback' => function () {
60 return current_user_can('manage_options');
61 },
62 ],
63 'schema' => [$this, 'getSchema'],
64 ]
65 );
66 }
67
68 /**
69 * @since 2.8.0
70 * @return array
71 *
72 */
73 public function getSchema()
74 {
75 return [
76 // This tells the spec of JSON Schema we are using which is draft 4.
77 '$schema' => 'http://json-schema.org/draft-04/schema#',
78 // The title property marks the identity of the resource.
79 'title' => 'onboarding',
80 'type' => 'object',
81 // In JSON Schema you can specify object properties in the properties attribute.
82 'properties' => [
83 // ...
84 ],
85 ];
86 }
87 }
88