PluginProbe
Ovation Elements / 1.2.3
Ovation Elements v1.2.3
1.2.7 1.2.6 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 27 releases
ovation-elements / includes / fetch-api.php

fetch-api.php in Ovation Elements 1.2.3, at includes/fetch-api.php

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once '../../../../wp-load.php';
3
4 header('Content-Type: application/json');
5
6 if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'POST') {
7 echo json_encode(['error' => 'Invalid request method']);
8 exit;
9 }
10
11 $postData = json_decode(file_get_contents('php://input'), true);
12
13 $action = $postData['action'] ?? 'getProducts';
14 $url = '';
15
16 switch ($action) {
17 case 'getProducts':
18 $url = OVA_ELEMS_LICENSE_ENDPOINT. 'getFilteredProducts';
19 $data = [
20 "collectionHandle" => $postData['collectionHandle'] ?? "",
21 "productHandle" => $postData['productHandle'] ?? "",
22 "paginationParams" => $postData['paginationParams'] ?? [
23 "first" => 12,
24 "afterCursor" => null,
25 "beforeCursor" => null,
26 "reverse" => true
27 ]
28 ];
29
30 break;
31 case 'getCollections':
32 $url = OVA_ELEMS_LICENSE_ENDPOINT. 'getCollections';
33 $data = [];
34 break;
35 default:
36 echo json_encode(['error' => 'Invalid action']);
37 exit;
38 }
39
40 // Prepare the request arguments
41 $args = [
42 'method' => 'POST',
43 'body' => json_encode($data),
44 'headers' => [
45 'Content-Type' => 'application/json',
46 ]
47 ];
48
49 $response = wp_remote_post($url, $args);
50
51 if (is_wp_error($response)) {
52 echo json_encode(['error' => 'Request failed: ' . $response->get_error_message()]);
53 exit;
54 }
55
56 $http_code = wp_remote_retrieve_response_code($response);
57 if ($http_code !== 200) {
58 echo json_encode(['error' => 'HTTP error: ' . $http_code]);
59 exit;
60 }
61
62 $response_body = wp_remote_retrieve_body($response);
63 $data = json_decode($response_body, true);
64
65 if (json_last_error() !== JSON_ERROR_NONE) {
66 echo json_encode(['error' => 'Invalid JSON format received from the external API']);
67 exit;
68 }
69 echo json_encode($data);