PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.5
Flex Import v2.5
2.9 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
flex-import / includes / flex-get-templates-api.php
flex-import / includes Last commit date
loader 10 months ago class-template-importer.php 10 months ago flex-dashboard-post-api.php 10 months ago flex-get-api.php 10 months ago flex-get-templates-api.php 10 months ago fleximp-license-functions.php 10 months ago
flex-get-templates-api.php
84 lines
1 <?php
2 require_once '../../../../wp-load.php';
3
4 header('Content-Type: application/json');
5
6 if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
7 echo json_encode(['error' => 'Invalid request method']);
8 exit;
9 }
10
11 // Decode the input JSON
12 $postData = json_decode(file_get_contents('php://input'), true);
13 $action = $postData['action'] ?? 'getTemplates';
14 $url = '';
15 $request_method = 'GET';
16 $data = [];
17
18 switch ($action) {
19 case 'getTemplates':
20 $url = FLEXIMP_JSON_DATA_URL . 'flex_theme_get_theme_templates';
21 $request_method = 'POST';
22
23 $data = [
24 'per_page' => !empty($postData['per_page']) ? (int) $postData['per_page'] : 1,
25 'page' => !empty($postData['page']) ? (int) $postData['page'] : 1
26 ];
27
28 if (!empty($postData['product_cat'])) {
29 $data['product_cat'] = $postData['product_cat'];
30 }
31
32 if (!empty($postData['search'])) {
33 $data['search'] = $postData['search'];
34 }
35
36 break;
37
38 case 'getCategories':
39 $url = FLEXIMP_JSON_DATA_URL . 'flex_theme_get_product_categories';
40 $request_method = 'GET';
41 break;
42
43 default:
44 echo json_encode(['error' => 'Invalid action']);
45 exit;
46 }
47
48 $args = [
49 'method' => $request_method,
50 'headers' => [
51 'Content-Type' => 'application/json',
52 ],
53 ];
54
55 if ($request_method === 'POST') {
56 $args['body'] = json_encode($data);
57 }
58
59 $response = ($request_method === 'POST') ? wp_remote_post($url, $args) : wp_remote_get($url, $args);
60
61 if (is_wp_error($response)) {
62 echo json_encode(['error' => 'Request failed: ' . $response->get_error_message()]);
63 exit;
64 }
65
66 $http_code = wp_remote_retrieve_response_code($response);
67 if ($http_code !== 200) {
68 echo json_encode(['error' => 'HTTP error: ' . $http_code]);
69 exit;
70 }
71
72 $response_body = wp_remote_retrieve_body($response);
73 $data = json_decode($response_body, true);
74
75 if (json_last_error() !== JSON_ERROR_NONE) {
76 echo json_encode(['error' => 'Invalid JSON format received from the external API']);
77 exit;
78 }
79 echo json_encode(['success' => true, 'data' => $data]);
80
81
82
83
84