PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.3
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / API / Route / Routes.php

Routes.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.3, at includes/API/Route/Routes.php

178 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\API\Route;
4
5 use WP_REST_Controller;
6 use WP_REST_Server;
7 use BitCode\BitForm\API\Controller\EntryController;
8 use BitCode\BitForm\API\Controller\NoteController;
9
10
11 class Routes extends WP_REST_Controller
12 {
13 function __construct()
14 {
15 $this->namespace = 'bitform';
16 $this->rest_base = 'v1';
17 $this->entryController = new EntryController();
18 $this->noteController = new NoteController();
19 }
20
21 public function register_routes()
22 {
23 /* form routes */
24 register_rest_route(
25 $this->namespace,
26 $this->rest_base . '/forms/',
27 [
28 [
29 'methods' => WP_REST_Server::READABLE,
30 'callback' => [$this->entryController, 'get_forms'],
31 'permission_callback' => array($this, 'get_items_permissions_check'),
32 ],
33 'schema' => [$this, 'get_item_schema']
34 ]
35 );
36 register_rest_route(
37 $this->namespace,
38 $this->rest_base . '/fields/(?P<form_id>[\d]+)',
39 [
40 [
41 'methods' => WP_REST_Server::READABLE,
42 'callback' => [$this->entryController, 'get_fields'],
43 'permission_callback' => [$this, 'get_items_permissions_check']
44 ]
45 ]
46 );
47 /* form routes*/
48
49 /* entry routes*/
50 register_rest_route(
51 $this->namespace,
52 $this->rest_base . '/entry/(?P<form_id>[\d]+)',
53 [
54 [
55 'methods' => WP_REST_Server::CREATABLE,
56 'callback' => [$this->entryController, 'entry_store'],
57 'permission_callback' => [$this, 'get_items_permissions_check']
58 ]
59 ]
60 );
61 register_rest_route(
62 $this->namespace,
63 $this->rest_base . '/form/response/(?P<id>[\d]+)',
64 [
65 [
66 'methods' => WP_REST_Server::READABLE,
67 'callback' => [$this->entryController, 'getEntryResponse'],
68 'permission_callback' => [$this, 'get_items_permissions_check']
69 ]
70 ]
71 );
72 register_rest_route(
73 $this->namespace,
74 $this->rest_base . '/entry/(?P<entry_id>[\d]+)',
75 [
76 [
77 'methods' => WP_REST_Server::READABLE,
78 'callback' => [$this->entryController, 'entry_view'],
79 'permission_callback' => [$this, 'get_items_permissions_check']
80
81 ],
82 [
83 'methods' => WP_REST_Server::DELETABLE,
84 'callback' => [$this->entryController, 'entry_delete'],
85 'permission_callback' => [$this, 'get_items_permissions_check']
86 ]
87 ]
88 );
89
90 register_rest_route(
91 $this->namespace,
92 $this->rest_base . '/entry_update/(?P<entry_id>[\d]+)/',
93 [
94 [
95 'methods' => WP_REST_Server::EDITABLE,
96 'callback' => [$this->entryController, 'entry_update'],
97 'permission_callback' => [$this, 'get_items_permissions_check']
98 ]
99 ]
100 );
101 /* entry routes*/
102
103 /* note routes*/
104 register_rest_route(
105 $this->namespace,
106 $this->rest_base . '/notes/',
107 [
108 [
109 'methods' => WP_REST_Server::READABLE,
110 'callback' => [$this->noteController, 'get_notes'],
111 'permission_callback' => [$this, 'get_items_permissions_check']
112 ]
113 ]
114 );
115 register_rest_route(
116 $this->namespace,
117 $this->rest_base . '/create-note/',
118 [
119 [
120 'methods' => WP_REST_Server::CREATABLE,
121 'callback' => [$this->noteController, 'create_note'],
122 'permission_callback' => [$this, 'get_items_permissions_check']
123 ]
124 ]
125 );
126 register_rest_route(
127 $this->namespace,
128 $this->rest_base . '/note/(?P<id>[\d]+)',
129 [
130 [
131 'methods' => WP_REST_Server::READABLE,
132 'callback' => [$this->noteController, 'note_edit'],
133 'permission_callback' => [$this, 'get_items_permissions_check'],
134 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
135 ],
136 [
137 'methods' => WP_REST_Server::EDITABLE,
138 'callback' => [$this->noteController, 'note_update'],
139 'permission_callback' => [$this, 'get_items_permissions_check']
140 ],
141 [
142 'methods' => WP_REST_Server::DELETABLE,
143 'callback' => [$this->noteController, 'note_delete'],
144 'permission_callback' => [$this, 'get_items_permissions_check']
145 ]
146 ]
147 );
148 /* note routes*/
149
150 /* google sheet route */
151 register_rest_route(
152 $this->namespace,
153 $this->rest_base . '/google/',
154 [
155 [
156 'methods' => WP_REST_Server::READABLE,
157 'callback' => [$this->entryController, 'googleAuth'],
158 'permission_callback' => '__return_true'
159 ]
160
161 ]
162 );
163 }
164 public function get_items_permissions_check($request)
165 {
166 $api_key = get_option('bitform_secret_api_key');
167 $header = $request->get_header('Bitform-Api-Key');
168 if (empty($header)) {
169 $error = ['message' => 'Api Key is required to access this resource'];
170 return wp_send_json_error($error, 401);
171 } else if ($request->get_header('Bitform-Api-Key') != $api_key || $api_key == null) {
172 $error = ['message' => 'Invalid API key'];
173 return wp_send_json_error($error, 401);
174 }
175 return true;
176 }
177 }
178