| @@ -1,22 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | -function ___tagembed__wpApiCall($apiUrl, $body, $header = null, $breakResponse = false) | |
| 2 | +if (!defined('ABSPATH')) : | |
| 3 | + exit; | |
| 4 | +endif; | |
| 5 | +function ___tagembed__wpApiCall($apiUrl, $body, $header = null) | |
| 3 | 6 | { |
| 4 | - $header = (null != $header ? $header : []); | |
| 5 | - $args = ['body' => $body, 'timeout' => '30', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => $header, 'cookies' => []]; | |
| 7 | + $header = (null != $header ? $header : []); | |
| 8 | + $args = ['body' => $body, 'timeout' => '30', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => $header, 'cookies' => []]; | |
| 6 | 9 | $response = wp_remote_post($apiUrl, $args); |
| 7 | - if ($breakResponse) : | |
| 8 | - ___tagembed__dd($response); | |
| 10 | + if (is_wp_error($response)) : | |
| 11 | + return; | |
| 9 | 12 | endif; |
| 10 | - if (!is_wp_error($response)) : | |
| 11 | - if (isset($response['body']) && !empty($response['body'])) : | |
| 12 | - return json_decode($response['body']); | |
| 13 | - else : | |
| 14 | - return; | |
| 15 | - endif; | |
| 16 | - else : | |
| 17 | - ___tagembed__wpApiCall($apiUrl, $body, $header = null, $breakResponse = false); | |
| 13 | + if (isset($response['body']) && !empty($response['body'])) : | |
| 14 | + return json_decode($response['body']); | |
| 18 | 15 | endif; |
| 16 | + return; | |
| 19 | 17 | } |
| 20 | 18 | function ___tagembed__manageApiResponse($response) |
| 21 | 19 | { |
| 22 | 20 | if (empty($response->head)) : |
| @@ -58,51 +56,27 @@ | ||
| 58 | 56 | return ___tagembed__exitWithDanger(); |
| 59 | 57 | endif; |
| 60 | 58 | } |
| 61 | 59 | } |
| 62 | -function ___tagembed__IsBase64($data) | |
| 63 | -{ | |
| 64 | - $decoded_data = base64_decode($data, true); | |
| 65 | - $encoded_data = base64_encode($decoded_data); | |
| 66 | - if ($encoded_data != $data) : | |
| 67 | - return false; | |
| 68 | - elseif (!ctype_print($decoded_data)) : | |
| 69 | - return false; | |
| 70 | - else : | |
| 71 | - return true; | |
| 72 | - endif; | |
| 73 | -} | |
| 60 | + | |
| 74 | 61 | function ___tagembed__exitWithSuccess($data = null) |
| 75 | 62 | { |
| 76 | - echo wp_json_encode(['status' => (bool)true, 'data' => (array)$data, 'message' => (string)'OK']); | |
| 77 | - exit; | |
| 63 | + wp_send_json(['status' => (bool)true, 'data' => (array)$data, 'message' => (string)'OK']); | |
| 78 | 64 | } |
| 79 | 65 | function ___tagembed__exitWithDanger($error = null, $data = []) |
| 80 | 66 | { |
| 81 | - echo wp_json_encode(['status' => (bool)false, 'data' => (array)$data, 'message' => (string)('' != $error ? $error : 'Oh snap! Something went wrong.')]); | |
| 82 | - exit; | |
| 67 | + wp_send_json(['status' => (bool)false, 'data' => (array)$data, 'message' => (string)('' != $error ? $error : 'Oh snap! Something went wrong.')]); | |
| 83 | 68 | } |
| 84 | -function ___tagembed__d($data = 'NONE') | |
| 85 | -{ | |
| 86 | - echo '<pre>'; | |
| 87 | - print_r($data); | |
| 88 | - echo '</pre>'; | |
| 89 | -} | |
| 90 | -function ___tagembed__dd($data = 'NONE') | |
| 91 | -{ | |
| 92 | - echo '<pre>'; | |
| 93 | - print_r($data); | |
| 94 | - echo '</pre>'; | |
| 95 | - die; | |
| 96 | -} | |
| 97 | -function ___tagembed__convertObjectToArray($data) | |
| 98 | -{ | |
| 99 | - $data = wp_json_encode($data); | |
| 100 | - return json_decode($data, true); | |
| 101 | -} | |
| 69 | + | |
| 102 | 70 | /* --Start__ Sanetize All Input */ |
| 103 | 71 | function ___tagembed__inputSanetize($data) |
| 104 | 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; | |
| 105 | 79 | $data = (string)$data; |
| 106 | 80 | if (preg_match('/<[^>]*>/', $data)) : |
| 107 | 81 | return ___tagembed__exitWithDanger('Special characters are not allowed. Please remove them and try again.'); |
| 108 | 82 | endif; |
| @@ -112,9 +86,13 @@ | ||
| 112 | 86 | function ___tagembed__sanitizeRequestData($__tagembed__request_input_data) |
| 113 | 87 | { |
| 114 | 88 | $__tagembed__Input_return_data = []; |
| 115 | 89 | foreach ($__tagembed__request_input_data as $__tagembed__request_input_key => $__tagembed__request_input) : |
| 116 | - $__tagembed__Input_return_data[$__tagembed__request_input_key] = sanitize_text_field($__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; | |
| 117 | 95 | endforeach; |
| 118 | 96 | return $__tagembed__Input_return_data; |
| 119 | 97 | } |
| 120 | 98 | /*--End-- Sanitize Request Data*/ |