PluginProbe
Ovation Elements / 1.1.3
Ovation Elements v1.1.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.1.3, at includes/fetch-api.php

77 lines 2.2 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 // Get POST data
12 $postData = json_decode(file_get_contents('php://input'), true);
13
14 // Determine which API to call based on the provided action
15 $action = $postData['action'] ?? 'getProducts';
16 $url = '';
17
18 switch ($action) {
19 case 'getProducts':
20 $url = 'https://license.ovationthemes.com/api/public/getFilteredProducts';
21 $data = [
22 "collectionHandle" => $postData['collectionHandle'] ?? "",
23 "productHandle" => $postData['productHandle'] ?? "",
24 "paginationParams" => $postData['paginationParams'] ?? [
25 "first" => 12,
26 "afterCursor" => null,
27 "beforeCursor" => null,
28 "reverse" => true
29 ]
30 ];
31
32 break;
33 case 'getCollections':
34 $url = 'https://license.ovationthemes.com/api/public/getCollections';
35 $data = []; // Use an empty array to send a proper POST request
36 break;
37 default:
38 echo json_encode(['error' => 'Invalid action']);
39 exit;
40 }
41
42 // Prepare the request arguments
43 $args = [
44 'method' => 'POST',
45 'body' => json_encode($data),
46 'headers' => [
47 'Content-Type' => 'application/json',
48 ]
49 ];
50
51 // Make the request using wp_remote_post
52 $response = wp_remote_post($url, $args);
53
54 // Check for errors
55 if (is_wp_error($response)) {
56 echo json_encode(['error' => 'Request failed: ' . $response->get_error_message()]);
57 exit;
58 }
59
60 // Check the response code
61 $http_code = wp_remote_retrieve_response_code($response);
62 if ($http_code !== 200) {
63 echo json_encode(['error' => 'HTTP error: ' . $http_code]);
64 exit;
65 }
66
67 // Get the response body
68 $response_body = wp_remote_retrieve_body($response);
69 $data = json_decode($response_body, true);
70
71 if (json_last_error() !== JSON_ERROR_NONE) {
72 echo json_encode(['error' => 'Invalid JSON format received from the external API']);
73 exit;
74 }
75
76 // Output the fetched data as JSON
77 echo json_encode($data);