PluginProbe
Tagembed: Social Media Feeds and Customer Reviews Widget / trunk
Tagembed: Social Media Feeds and Customer Reviews Widget vtrunk
7.5 7.6 7.7 7.4 trunk 3.10 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 All 42 releases
tagembed-widget / helper / helper.php

helper.php in Tagembed: Social Media Feeds and Customer Reviews Widget trunk, at helper/helper.php

99 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) :
3 exit;
4 endif;
5 function ___tagembed__wpApiCall($apiUrl, $body, $header = null)
6 {
7 $header = (null != $header ? $header : []);
8 $args = ['body' => $body, 'timeout' => '30', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => $header, 'cookies' => []];
9 $response = wp_remote_post($apiUrl, $args);
10 if (is_wp_error($response)) :
11 return;
12 endif;
13 if (isset($response['body']) && !empty($response['body'])) :
14 return json_decode($response['body']);
15 endif;
16 return;
17 }
18 function ___tagembed__manageApiResponse($response)
19 {
20 if (empty($response->head)) :
21 return ___tagembed__exitWithDanger();
22 endif;
23 $responseCode = $response->head->code;
24 switch ($responseCode) {
25 case 200:
26 if ($response->head->status) :
27 if (!empty($response->body)) :
28 return $response->body;
29 endif;
30 if (!empty($response->head->message)) :
31 return ___tagembed__exitWithSuccess($response->head->message);
32 else :
33 return ___tagembed__exitWithSuccess();
34 endif;
35 else :
36 if (!empty($response->head->message)) :
37 return ___tagembed__exitWithDanger($response->head->message);
38 else :
39 return ___tagembed__exitWithDanger();
40 endif;
41 endif;
42 break;
43 case 412:
44 /* --Start-- Manage Validation Error */
45 if (empty($response->body)) :
46 return ___tagembed__exitWithDanger();
47 else :
48 return ___tagembed__exitWithDanger('Validation Error', $response->body);
49 endif;
50 /* --End-- Manage Validation Error */
51 break;
52 default:
53 if (!empty($response->head->message)) :
54 return ___tagembed__exitWithDanger($response->head->message);
55 else :
56 return ___tagembed__exitWithDanger();
57 endif;
58 }
59 }
60
61 function ___tagembed__exitWithSuccess($data = null)
62 {
63 wp_send_json(['status' => (bool)true, 'data' => (array)$data, 'message' => (string)'OK']);
64 }
65 function ___tagembed__exitWithDanger($error = null, $data = [])
66 {
67 wp_send_json(['status' => (bool)false, 'data' => (array)$data, 'message' => (string)('' != $error ? $error : 'Oh snap! Something went wrong.')]);
68 }
69
70 /* --Start__ Sanetize All Input */
71 function ___tagembed__inputSanetize($data)
72 {
73 if (is_array($data)) :
74 foreach ($data as $__tagembed__input_sanetize_item) :
75 ___tagembed__inputSanetize($__tagembed__input_sanetize_item);
76 endforeach;
77 return;
78 endif;
79 $data = (string)$data;
80 if (preg_match('/<[^>]*>/', $data)) :
81 return ___tagembed__exitWithDanger('Special characters are not allowed. Please remove them and try again.');
82 endif;
83 }
84 /* --End Sanetize All Input */
85 /* --Start-- Sanitize Request Data */
86 function ___tagembed__sanitizeRequestData($__tagembed__request_input_data)
87 {
88 $__tagembed__Input_return_data = [];
89 foreach ($__tagembed__request_input_data as $__tagembed__request_input_key => $__tagembed__request_input) :
90 if (is_array($__tagembed__request_input)) :
91 $__tagembed__Input_return_data[$__tagembed__request_input_key] = ___tagembed__sanitizeRequestData($__tagembed__request_input);
92 else :
93 $__tagembed__Input_return_data[$__tagembed__request_input_key] = sanitize_text_field($__tagembed__request_input);
94 endif;
95 endforeach;
96 return $__tagembed__Input_return_data;
97 }
98 /*--End-- Sanitize Request Data*/
99