-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwpjson.php
More file actions
35 lines (28 loc) · 879 Bytes
/
Copy pathwpjson.php
File metadata and controls
35 lines (28 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
header('Content-Type: application/json');
// Parse request
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$method = $_SERVER['REQUEST_METHOD'];
// Remove project path prefix if needed
$scriptName = dirname($_SERVER['SCRIPT_NAME']);
$path = str_replace($scriptName, '', $path);
// Match your route
if ($method === 'GET' && $path === '/wp-json/mspform/v1/allforms') {
require 'api/allforms.php';
exit;
}
if ($method === 'GET' && preg_match('#^/wp-json/mspform/v1/(\d+)/entries$#', $path, $matches)) {
$formid = intval($matches[1]);
require __DIR__ . '/api/form_entries.php';
exit;
}
if ($method === 'POST' && preg_match('#^/wp-json/mspform/v1/submit$#', $path)) {
require __DIR__ . '/api/form_submit.php';
exit;
}
// Fallback
http_response_code(404);
echo json_encode([
'error' => 'Route not found',
'path' => $path,
]);