PluginProbe
WPGet API – Connect to any external REST API / 1.7.0
WPGet API – Connect to any external REST API v1.7.0
1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.10 2.2.2 2.2.3 All 97 releases
← All changes | includes/class-api.php +74 -409 2.1.11.7.0 View file →
@@ -28,11 +28,8 @@
28 28 public $header_parameters = ''; // the header paramaters
29 29 public $body_parameters = ''; // the body paramaters
30 30 public $body_json_encode = ''; // body_json_encode body
31 31 public $body_url_encode = ''; // urlencode body
32 - public $body_base64_encode = ''; // base64 encode body
33 - public $body_xml_format = ''; // xml format body
34 - public $xml_root_node = 'root'; // root node for xml
35 32
36 33 public $response = ''; // the returned response
37 34
38 35 public $final_url = ''; // final URL
@@ -37,14 +34,12 @@
37 34
38 35 public $final_url = ''; // final URL
39 36 public $final_request_args = array(); // final request_args
40 37
41 - public $results_format = 'json_string'; // results format
38 + public $results_format = 'json_string'; // reseults format
42 39
43 - public $response_code = ''; // the response code from the call
44 -
45 40 public $timeout = 10; // the timeout
46 - public $sslverify = 1; // ssl verify
41 + public $sslverify = 1; // the paramaters
47 42 public $debug = false;
48 43
49 44
50 45 /**
@@ -63,9 +58,9 @@
63 58 $this->endpoint_id = sanitize_text_field( $endpoint_id );
64 59 $this->keys = $keys;
65 60 $this->args = $args;
66 61
67 - add_filter( 'wpgetapi_raw_data', array( $this, 'maybe_add_debug_info' ), 99, 2 );
62 + add_filter( 'wpgetapi_raw_data', array( $this, 'maybe_add_debug_info' ), 5, 2 );
68 63
69 64 }
70 65
71 66
@@ -73,29 +68,8 @@
73 68 * Init our api data
74 69 */
75 70 public function init() {
76 71
77 - // if we are doing importer plugin,
78 - // we need to intercept and modify most of our methods values
79 - if( $this->api_id === 'wpgetapi_importer' ) {
80 -
81 - $data = apply_filters( 'wpgetapi_api_importer_init', $this );
82 -
83 - if( $data ) {
84 -
85 - foreach ($data as $key => $value) {
86 - $this->{$key} = $value;
87 - }
88 -
89 - $this->query_parameters = ! empty( $this->query_parameters ) ? $this->do_parameters( $this->query_parameters ) : array();
90 - $this->header_parameters = ! empty( $this->header_parameters ) ? $this->do_parameters( $this->header_parameters ) : array();
91 - $this->body_parameters = ! empty( $this->body_parameters ) ? $this->do_parameters( $this->body_parameters ) : array();
92 - return;
93 -
94 - }
95 -
96 - }
97 -
98 72 // do some checks
99 73 if( empty( $this->setup ) || ! isset( $this->setup['apis'] ) || empty( $this->setup['apis'] ) )
100 74 return 'No API found.';
101 75
@@ -114,9 +88,9 @@
114 88 // loop through endpoints
115 89 foreach ( $this->api['endpoints'] as $index => $endpoint ) {
116 90
117 91 if( $this->endpoint_id == $endpoint['id'] ) {
118 -
92 +
119 93 $this->method = isset( $endpoint['method'] ) && $endpoint['method'] != '' ? sanitize_text_field( $endpoint['method'] ) : 'GET';
120 94 $this->cache_time = isset( $endpoint['cache_time'] ) && ! empty( $endpoint['cache_time'] ) ? absint( $endpoint['cache_time'] ) : '';
121 95 $this->endpoint = isset( $endpoint['endpoint'] ) && ! empty( $endpoint['endpoint'] ) ? sanitize_text_field( $endpoint['endpoint'] ) : '';
122 96
@@ -125,40 +99,13 @@
125 99 $this->header_parameters = isset( $endpoint['header_parameters'] ) && ! empty( $endpoint['header_parameters'] ) ? $this->do_parameters( $endpoint['header_parameters'] ) : array();
126 100
127 101 $this->body_parameters = isset( $endpoint['body_parameters'] ) && ! empty( $endpoint['body_parameters'] ) ? $this->do_parameters( $endpoint['body_parameters'] ) : array();
128 102
129 - // how to encode the body
130 103 $this->body_json_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'true' ? true : false;
131 104 $this->body_url_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'url' ? true : false;
132 - $this->body_base64_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'base64' ? true : false;
133 - $this->body_xml_format = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'xml' ? true : false;
134 105
135 - $this->xml_root_node = isset( $endpoint['xml_root'] ) && ! empty( $endpoint['xml_root'] ) ? $endpoint['xml_root'] : $this->xml_root_node;
136 -
137 106 $this->results_format = isset( $endpoint['results_format'] ) ? sanitize_text_field( $endpoint['results_format'] ) : $this->results_format;
138 -
139 -
140 - if(
141 - // set the format to php array data if html format is set
142 - ( isset( $this->args['format'] ) && $this->args['format'] == 'html' && $this->results_format != 'xml_array' ) ||
143 - // set the format to php array data if it is set in the args (coming from the importer)
144 - ( isset( $this->args['results_format'] ) && $this->args['results_format'] == 'json_decoded' )
145 - ) {
146 - $this->results_format = 'json_decoded';
147 - }
148 -
149 - // set the format to JSON string if it is set in the args (coming from the wpdatatables integration)
150 - if( isset( $this->args['results_format'] ) && $this->args['results_format'] == 'json_string' ) {
151 - $this->results_format = 'json_string';
152 - }
153 -
154 - // set the format to JSON string if it is set in the args (coming from the wpdatatables integration)
155 - if( isset( $this->args['results_format'] ) && $this->args['results_format'] == 'json_decoded' ) {
156 - $this->results_format = 'json_decoded';
157 - }
158 -
159 107 }
160 -
161 108 }
162 109
163 110 $this->timeout = isset( $this->api['timeout'] ) && ! empty( $this->api['timeout'] ) ? $this->api['timeout'] : $this->timeout;
164 111 $this->sslverify = isset( $this->api['sslverify'] ) ? absint( $this->api['sslverify'] ) : $this->sslverify;
@@ -171,21 +118,58 @@
171 118 *
172 119 * @param string $field Field to retrieve
173 120 */
174 121 public function endpoint_output() {
122 + return $this->do_the_call();
123 + }
175 124
176 - do_action( 'wpgetapi_before_do_the_call', $this );
177 125
178 - return $this->do_the_call();
126 + /**
127 + * Sort out the parameters if they exist
128 + */
129 + public function do_parameters( $parameters ) {
130 +
131 + $new_array = array();
132 + $parameters = $this->decrypt($parameters);
179 133
134 + if( is_array( $parameters ) ) {
135 + foreach ( $parameters as $key => $parameter ) {
136 + if( ! empty( $parameter['name'] ) && ! empty( $parameter['value'] ) ) {
137 + $parameter['value'] = stripslashes( $parameter['value'] );
138 + $new_array[ sanitize_text_field( $parameter['name'] ) ] = $parameter['value'];
139 + }
140 + }
141 + }
142 +
143 + // look for array or json string and sort these out - for using such things in shortcode
144 + if( is_array( $new_array ) ) {
145 +
146 + foreach ( $new_array as $key => $value ) {
147 +
148 + // checking if the parameters have a json string
149 + if ( substr( $value, 0, 1 ) === '{' && substr( $value, -1 ) === '}' ) {
150 + $new_array[ $key ] = json_decode( $value, true);
151 + }
152 +
153 + // checking if the parameters have an array within the string
154 + // if they do, create them as an actual array
155 + if ( substr( $value, 0, 1 ) === '[' && substr( $value, -1 ) === ']' ) {
156 + $new_array[ $key ] = array( $value );
157 + }
158 +
159 + }
160 +
161 + }
162 +
163 + return $new_array;
164 +
180 165 }
181 166
182 -
183 167 /**
184 168 * Send the request and return our data
185 169 */
186 170 public function do_the_call() {
187 -
171 +
188 172 $this->init();
189 173
190 174 // build the URL
191 175 $this->final_url = apply_filters( 'wpgetapi_final_url', $this->build_url(), $this );
@@ -191,18 +175,9 @@
191 175 $this->final_url = apply_filters( 'wpgetapi_final_url', $this->build_url(), $this );
192 176
193 177 // build the request args
194 178 $this->final_request_args = apply_filters( 'wpgetapi_final_request_args', $this->build_request_args(), $this );
195 -
196 - /**
197 - * Check if we should stop or not. Setting $on to true, will stop us calling the api.
198 - * @param bool $on Whether on is set or not.
199 - */
200 179
201 - if ( apply_filters( 'wpgetapi_should_we_stop', false, $this ) ) {
202 - return;
203 - }
204 -
205 180 // POST request
206 181 if( $this->method == 'POST' )
207 182 $this->response = $this->POST_request();
208 183
@@ -209,20 +184,12 @@
209 184 // PUT request
210 185 if( $this->method == 'PUT' )
211 186 $this->response = $this->PUT_request();
212 187
213 - // PATCH request
214 - if( $this->method == 'PATCH' )
215 - $this->response = $this->PATCH_request();
216 -
217 188 // GET request
218 189 if( $this->method == 'GET' )
219 190 $this->response = $this->GET_request();
220 191
221 - // DELETE request
222 - if( $this->method == 'DELETE' )
223 - $this->response = $this->DELETE_request();
224 -
225 192 // wp error
226 193 if( is_wp_error( $this->response ) ) {
227 194 return apply_filters( 'wpgetapi_raw_error_data', json_encode( $this->response ), $this );
228 195 }
@@ -227,24 +194,21 @@
227 194 return apply_filters( 'wpgetapi_raw_error_data', json_encode( $this->response ), $this );
228 195 }
229 196
230 197 // get response_code
231 - $this->response_code = wp_remote_retrieve_response_code( $this->response );
198 + $response_code = wp_remote_retrieve_response_code( $this->response );
232 199
233 200 // action to intercept call depending on response_code
234 - $this->response = apply_filters( 'wpgetapi_before_retrieve_body', $this->response, $this->response_code, $this );
201 + $this->response = apply_filters( 'wpgetapi_before_retrieve_body', $this->response, $response_code, $this );
235 202
236 203 // get body
237 204 // modified in version 1.6.1 to allow for OAuth 2.0 plugin returning body already
238 205 $data = isset( $this->response['body'] ) ? $this->response['body'] : $this->response;
239 -
206 +
240 207 // returning in JSON format
241 208 if( $this->results_format == 'json_string' || $this->results_format == 'json_decoded' )
242 209 $data = $this->return_data( $data );
243 210
244 - if( $data === 'null' )
245 - $data = 'Result is null. Check that all endpoint settings are correct.';
246 -
247 211 return apply_filters( 'wpgetapi_raw_data', $data, $this );
248 212
249 213 }
250 214
@@ -257,23 +221,10 @@
257 221 // first make sure our endpoint starts with a slash
258 222 if ( substr( $this->endpoint, 0, 1 ) != '/' )
259 223 $this->endpoint = '/' . $this->endpoint;
260 224
261 - // if we have item_key from api to posts plugin
262 - // replace our keyword with the actual item_key value
263 - if ( isset( $this->args['item_key'] ) && strpos( $this->endpoint, '(importer:item_key)' ) !== false ) {
264 - $this->endpoint = str_replace( '(importer:item_key)', $this->args['item_key'], $this->endpoint );
265 - }
266 -
267 - $this->endpoint = apply_filters( 'wpgetapi_endpoint', $this->endpoint, $this );
268 -
269 225 $url = untrailingslashit( $this->base_url ) . $this->endpoint;
270 226
271 - // if we have a URL pagination event from the import plugin
272 - // we need to modify the URL here
273 - if( isset( $this->args['paginate_url'] ) )
274 - $url = $this->args['paginate_url'];
275 -
276 227 // filter our params - added for use in Oauth 2.0 plugin
277 228 $params = apply_filters( 'wpgetapi_query_parameters', $this->query_parameters, $this );
278 229
279 230 // add empty array - was getting errors if it was just null or false
@@ -278,12 +229,10 @@
278 229
279 230 // add empty array - was getting errors if it was just null or false
280 231 $params = empty( $params ) ? array(''=>'') : $params;
281 232
282 - $result = add_query_arg( $params, $url );
233 + return add_query_arg( $params, $url );
283 234
284 - return $result;
285 -
286 235 }
287 236
288 237
289 238 /**
@@ -297,57 +246,26 @@
297 246 ), $this );
298 247
299 248
300 249 // if doing POST request, include body paramters
301 - if( $this->method == 'POST' || $this->method == 'PUT' || $this->method == 'DELETE' || $this->method == 'PATCH' ) {
302 -
303 - // tokens are sent through here
250 + if( $this->method == 'POST' || $this->method == 'PUT' ) {
251 +
304 252 $this->body_parameters = apply_filters( 'wpgetapi_body_parameters', $this->body_parameters, $this );
305 253
306 - // do we json_encode the entire body
307 - if( $this->body_json_encode == true ) {
254 + // do we json_encode the entire body as a string
255 + if( $this->body_json_encode == true )
308 256 $this->body_parameters = json_encode( $this->body_parameters );
309 - }
310 257
311 - // do we urlencode the entire body
312 - if( $this->body_parameters && $this->body_url_encode == true ) {
313 -
314 - // checking if the parameters have a json string (raw)
315 - if (
316 - ( ! is_array( $this->body_parameters ) ) &&
317 - ( substr( $this->body_parameters, 0, 1 ) === '{' || substr( $this->body_parameters, 0, 1 ) === '[' )
318 - ) {
319 - $this->body_parameters = json_decode( $this->body_parameters, true );
258 +
259 + // do we urlencode the entire body as a string
260 + if( $this->body_url_encode == true ) {
261 + $data_raw = '';
262 + foreach ($this->body_parameters as $key => $value){
263 + $data_raw = $data_raw . $key . "=" . urlencode($value) . "&";
320 264 }
321 -
322 - $this->body_parameters = http_build_query( $this->body_parameters, '', '&' );
323 -
265 + $this->body_parameters = $data_raw;
324 266 }
325 267
326 - // do we xml the entire body
327 - if( $this->body_parameters && $this->body_xml_format == true ) {
328 -
329 - $root_node = $this->xml_root_node != '' ? '<' . $this->xml_root_node . '/>' : '';
330 - $xml = new SimpleXmlElement( '<?xml version="1.0" encoding="UTF-8"?>' . $root_node );
331 -
332 - foreach( $this->body_parameters as $key => $value) {
333 - $xml->addChild( $key, $value );
334 - }
335 -
336 - $this->body_parameters = $xml->asXML();
337 -
338 - }
339 -
340 - // do we base64 encode the entire body
341 - if( $this->body_parameters && $this->body_base64_encode == true ) {
342 -
343 - $this->body_parameters = is_array( $this->body_parameters ) ? json_encode( $this->body_parameters ) : $this->body_parameters;
344 - $this->body_parameters = base64_encode( $this->body_parameters );
345 -
346 - }
347 -
348 - $this->body_parameters = apply_filters( 'wpgetapi_modify_formatted_body_parameters', $this->body_parameters, $this );
349 -
350 268 // add our body parameters
351 269 if( $this->body_parameters && ! empty( $this->body_parameters ) )
352 270 $headers['body'] = $this->body_parameters;
353 271
@@ -352,12 +270,8 @@
352 270 $headers['body'] = $this->body_parameters;
353 271
354 272 }
355 273
356 - // get our body paramters as they are formatted
357 - // this won't change anything, it just allows us to get the parameters
358 - $this->body_parameters = apply_filters( 'wpgetapi_final_body_parameters', $this->body_parameters, $this );
359 -
360 274 // add headers to our final request args
361 275 $this->final_request_args = wp_parse_args( $headers, $this->final_request_args );
362 276
363 277 // build the args taht are sent to the request
@@ -373,40 +287,27 @@
373 287
374 288 }
375 289
376 290
377 -
378 -
379 291 /**
380 292 * Do a GET request
381 293 */
382 294 public function GET_request() {
383 -
384 295 $response = '';
385 296 // so we can so something before the remote_get (caching)
386 297 $response = apply_filters( 'wpgetapi_before_get_request', $response, $this );
387 -
388 298 if( empty( $response ) )
389 299 $response = wp_remote_get( $this->final_url, $this->final_request_args );
390 300
391 301 return $response;
302 + }
392 303
393 - }
394 304
395 305 /**
396 306 * Do a POST request
397 307 */
398 308 public function POST_request() {
399 -
400 - $response = '';
401 - // so we can so something before the remote_post (caching)
402 - $response = apply_filters( 'wpgetapi_before_post_request', $response, $this );
403 -
404 - //$this->final_request_args['method'] = 'POST';
405 -
406 - if( empty( $response ) )
407 - $response = wp_remote_post( $this->final_url, $this->final_request_args );
408 -
309 + $response = wp_remote_post( $this->final_url, $this->final_request_args );
409 310 return $response;
410 311 }
411 312
412 313 /**
@@ -417,28 +318,10 @@
417 318 $response = wp_remote_request( $this->final_url, $this->final_request_args );
418 319 return $response;
419 320 }
420 321
421 - /**
422 - * Do a PATCH request
423 - */
424 - public function PATCH_request() {
425 - $this->final_request_args['method'] = 'PATCH';
426 - $response = wp_remote_request( $this->final_url, $this->final_request_args );
427 - return $response;
428 - }
429 322
430 323 /**
431 - * Do a DELETE request
432 - */
433 - public function DELETE_request() {
434 - $this->final_request_args['method'] = 'DELETE';
435 - $response = wp_remote_request( $this->final_url, $this->final_request_args );
436 - return $response;
437 - }
438 -
439 -
440 - /**
441 324 * return data
442 325 */
443 326 public function return_data( $data ) {
444 327
@@ -444,123 +327,22 @@
444 327
445 328 $data = apply_filters( 'wpgetapi_json_response_body_before_decode', $data, $this->keys );
446 329
447 330 // converts all data to arrays, removing objects
448 - if( is_string( $data ) ) {
449 - $decode = json_decode( $data, true );
450 - if( json_last_error() ) {
451 - return esc_html( $data );
452 - } else {
453 - $data = $decode;
454 - }
455 - }
456 -
331 + if( is_string( $data ) )
332 + $data = json_decode( $data, true );
333 +
457 334 $data = apply_filters( 'wpgetapi_json_response_body', $data, $this->keys );
458 335
459 336 if( $this->results_format == 'json_string' )
460 - return trim( json_encode( $data, JSON_PRETTY_PRINT ),'"');
461 -
337 + return trim( json_encode( $data ),'"');
338 +
462 339 if( $this->results_format == 'json_decoded' )
463 340 return $data;
464 341
465 342 }
466 343
467 - /**
468 - * Sort out the parameters if they exist
469 - */
470 - public function do_parameters( $parameters ) {
471 344
472 - $new_array = array();
473 - $raw = '';
474 - $parameters = $this->decrypt( $parameters );
475 -
476 - if( is_array( $parameters ) ) {
477 - foreach ( $parameters as $key => $parameter ) {
478 -
479 - if( ! empty( $parameter['name'] ) && ! empty( $parameter['value'] ) ) {
480 -
481 - $parameter['value'] = stripslashes( $parameter['value'] );
482 -
483 - // if we have wpgetapi_on, delete it so we don't send to api
484 - if( $parameter['name'] == 'wpgetapi_on' ) {
485 - unset( $parameters[ $key ] );
486 - continue;
487 - }
488 -
489 - // if we have item_key from api to posts plugin
490 - // replace our keyword with the actual item_key value
491 - if ( isset( $this->args['item_key'] ) && strpos( $parameter['value'], '(importer:item_key)' ) !== false ) {
492 - $parameter['value'] = str_replace( '(importer:item_key)', $this->args['item_key'], $parameter['value'] );
493 - }
494 -
495 - $new_array[ sanitize_text_field( $parameter['name'] ) ] = $parameter['value'];
496 -
497 - // if we are sending raw body
498 - } else if( empty( $parameter['name'] ) && ! empty( $parameter['value'] ) ) {
499 -
500 - $raw = stripslashes( $parameter['value'] );
501 -
502 - }
503 -
504 - }
505 - }
506 -
507 - // now look for array or json string and sort these out - for using such things in shortcode
508 - if( ! empty( $new_array ) ) {
509 -
510 - foreach ( $new_array as $key => $value ) {
511 -
512 - // checking if the parameters have a json string
513 - if ( strpos( $value, '{"' ) !== false && strpos( $value, '}' ) !== false ) {
514 -
515 - $tmp_val = $value;
516 - $tmp_val = json_decode( $tmp_val, true );
517 - $new_array[ $key ] = $tmp_val ? $tmp_val : $value;
518 -
519 - } else
520 -
521 - // checking if the parameters have an array within the string
522 - // if they do, create them as an actual array
523 - if ( substr( $value, 0, 1 ) === '[' && substr( $value, -1 ) === ']' ) {
524 - $value = trim( $value,"[]" );
525 - $new_array[ $key ] = array( $value );
526 - }
527 -
528 - // set value as integer
529 - if ( strpos( $value, 'integer(' ) !== false && substr( $value, -1 ) === ')' ) {
530 - preg_match("/\(([^\)]*)\)/", $value, $match );
531 - $result = $match[1];
532 - $new_array[ $key ] = absint( $result );
533 - }
534 -
535 - // set value as float
536 - if ( strpos( $value, 'float(' ) !== false && substr( $value, -1 ) === ')' ) {
537 - preg_match("/\(([^\)]*)\)/", $value, $match );
538 - $result = $match[1];
539 - if ( substr( $result, 0, 1 ) === '"' && substr( $result, -1 ) === '"' )
540 - $result = trim( $result,'""' );
541 - $new_array[ $key ] = (float) $result;
542 -
543 - }
544 -
545 - // set value as boolean
546 - if ( strpos( $value, 'boolean(' ) !== false && substr( $value, -1 ) === ')' ) {
547 - preg_match("/\(([^\)]*)\)/", $value, $match );
548 - $result = $match[1];
549 - $result = filter_var( $result, FILTER_VALIDATE_BOOLEAN );
550 - $new_array[ $key ] = $result;
551 -
552 - }
553 -
554 - }
555 -
556 - }
557 -
558 - return $raw ? $raw : $new_array;
559 -
560 - }
561 -
562 -
563 345 /**
564 346 * decrypt our parameters from the DB
565 347 */
566 348 public function decrypt( $array_or_string ) {
@@ -595,69 +377,10 @@
595 377 ) {
596 378
597 379 $this->debug = true;
598 380
599 - // admin test endpoint button
600 381 $testing = isset( $this->args['test_endpoint'] ) && ( $this->args['test_endpoint'] === true ) ? true : false;
601 382
602 - // get api status from response code
603 - $status = array(
604 - 'title' => 'Error in API response.',
605 - 'desc' => 'Check all details within your endpoint. Something is misconfigured.',
606 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
607 - );
608 -
609 - if( $this->response_code >= 200 && $this->response_code <= 299 ) {
610 - $status = array(
611 - 'title' => 'Success!',
612 - 'desc' => 'Your API is returning a success message and is returning the data as shown in the Data Output section below. You can modify this by changing the Results Format option or see <a href="https://wpgetapi.com/docs/format-api-data-as-html/">here</a> for info on formatting this data.',
613 - 'type' => '<span class="dashicons dashicons-yes-alt"></span>'
614 - );
615 - }
616 - if( $this->response_code >= 400 && $this->response_code <= 499 ) {
617 - $status = array(
618 - 'title' => 'Bad Request',
619 - 'desc' => 'This could indicate that the URL you are calling is incorrect or that some other data is missing or incorrect. Please check your Base URL and Endpoint are correct as well as the Request Method.',
620 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
621 - );
622 - }
623 - if( $this->response_code == 401 ) {
624 - $status = array(
625 - 'title' => 'Unauthorised',
626 - 'desc' => 'You are successfully connecting to your API. But your API key, login or API credentials are incorrect. See <a href="https://wpgetapi.com/docs/authentication-authorization/">here</a> for info on correctly authorizing your API requests.',
627 - 'type' => '<span class="dashicons dashicons-warning"></span>'
628 - );
629 - }
630 - if( $this->response_code == 403 ) {
631 - $status = array(
632 - 'title' => 'Forbidden',
633 - 'desc' => 'This could indicate that you may need to get your IP address whitelisted with your API provider or that you do not have access to this API.',
634 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
635 - );
636 - }
637 - if( $this->response_code == 405 ) {
638 - $status = array(
639 - 'title' => 'Method Not Allowed',
640 - 'desc' => 'Try changing the Request Method within the endpoint settings.',
641 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
642 - );
643 - }
644 - if( $this->response_code == 415 ) {
645 - $status = array(
646 - 'title' => 'Unsupported Media Type',
647 - 'desc' => 'Try adding "Content-type" to the Headers with the Value of "json/application" as shown <a href="https://wpgetapi.com/docs/troubleshooting/">here</a>.',
648 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
649 - );
650 - }
651 - if( $this->response_code >= 500 && $this->response_code <= 599 ) {
652 - $status = array(
653 - 'title' => 'Internal Server Error',
654 - 'desc' => 'This indicates an issue with the API server. Contact your API provider.',
655 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
656 - );
657 - }
658 -
659 -
660 383 ob_start(); ?>
661 384
662 385 <style>
663 386
@@ -694,11 +417,10 @@
694 417 background: #fff;
695 418 padding: 15px 20px;
696 419 display: inline-block !important;
697 420 width: 100% !important;
698 - box-shadow: 0 4px 4px -2px rgb(0 0 0 / 9%);
699 - border: 1px solid #eee;
700 - margin-bottom: 20px !important;
421 + box-shadow: 3px 3px 0 rgb(0 0 0 / 8%);
422 + border: 1px solid #efefef;
701 423 }
702 424 .wpgetapi-debug .debug-item h6 {
703 425 font-weight: bold;
704 426 font-size: 14px;
@@ -710,14 +432,15 @@
710 432 font-family: monospace !important;
711 433 font-size: 13px !important;
712 434 margin: 0 !important;
713 435 padding: 8px 12px;
714 - background: #f4f7f9;
436 + background: #f8f8f8;
715 437 }
716 438 .wpgetapi-debug .debug-item .debug-result pre {
717 439 border: none;
718 440 padding: 5px
719 441 }
442 +
720 443 .wpgetapi-debug.testing {
721 444 background: transparent;
722 445 padding: 0;
723 446 box-shadow: none;
@@ -724,72 +447,16 @@
724 447 }
725 448 .wpgetapi-debug.testing .debug-item {
726 449 margin: 5px 0;
727 450 }
728 -.wpgetapi-debug.testing .debug-item.status {
729 - border: none;
730 - box-shadow: none;
731 - margin-bottom: 15px;
732 -}
733 -.wpgetapi-debug .debug-item.status h5 {
734 - font-size: 15px;
735 -}
736 -.wpgetapi-debug .status .dashicons {
737 - margin: 0 5px 3px 0;
738 -}
739 -.wpgetapi-debug .status .dashicons-yes-alt {
740 - color: #5e9929;
741 -}
742 -.wpgetapi-debug .status .dashicons-dismiss {
743 - color: #cc4646;
744 -}
745 -.wpgetapi-debug .status .dashicons-warning {
746 - color: #dfa12e;
747 -}
748 -.wpgetapi-debug .status .desc {
749 - font-size: 14px;
750 - font-weight: 400 !important;
751 -}
752 451 </style>
753 452
754 453 <div class="wpgetapi-debug <?php echo $testing ? 'testing' : ''; ?>">
755 454
756 - <?php if( $testing ) { ?>
757 -
758 - <div class="debug-item status">
759 - <div class="">
760 - <h5><?php _e( $status['type'] ); ?> <?php esc_html_e( $status['title'] ); ?></h5>
761 - <span class="desc"><?php _e( $status['desc'] ); ?></span>
762 - </div>
763 - </div>
764 - <div class="debug-item">
765 - <h6><?php esc_html_e( 'Full URL', 'wpgetapi' ); ?></h6>
766 - <p class="small"><?php esc_html_e( 'The full URL that is being called.', 'wpgetapi' ); ?></p>
767 - <div class="debug-result"><?php esc_html_e( $this->final_url ); ?></div>
768 - </div>
769 -
770 - <div class="debug-item">
771 - <h6><?php esc_html_e( 'Data Output', 'wpgetapi' ); ?></h6>
772 - <p class="small"><?php esc_html_e( 'The output that has been returned from the API. This is what the shortcode or template tag will display and can be formatted however you like.', 'wpgetapi' ); ?></p>
773 - <div class="debug-result"><?php wpgetapi_pp( $data ); ?></div>
774 - </div>
775 -
776 - <div class="debug-item">
777 - <h6><?php esc_html_e( 'Final Request Arguments', 'wpgetapi' ); ?></h6>
778 - <p class="small"><?php esc_html_e( 'The final request arguments sent in the API request. Includes headers and body arguments.', 'wpgetapi' ); ?></p>
779 - <div class="debug-result"><?php wpgetapi_pp( $this->final_request_args ); ?></div>
780 - </div>
781 -
782 - <div class="debug-item">
783 - <h6><?php esc_html_e( 'Response', 'wpgetapi' ); ?></h6>
784 - <p class="small"><?php esc_html_e( 'The full response from the API request.', 'wpgetapi' ); ?></p>
785 - <div class="debug-result"><?php wpgetapi_pp( $this->response); ?></div>
786 - </div>
787 -
788 - <?php } else { ?>
789 -
790 - <h5><strong><?php esc_html_e( 'WPGetAPI, Debug Mode - Plugin Version', 'wpgetapi' ); ?> <?php esc_html_e( WpGetApi()->version ); ?></strong></h5>
455 + <?php if( ! $testing ) { ?>
456 + <h5><strong><?php esc_html_e( 'WPGetAPI, Debug Mode - Plugin Version', 'wpgetapi' ); ?> <?php esc_html_e( WpGetApi()->version ); ?></strong></h5>
791 457 <p class="small"><?php esc_html_e( 'Below you will find debug info for the current API call. To turn this off, set debug to false in your shortcode or template tag.', 'wpgetapi' ); ?><br><?php esc_html_e( 'Connecting to API\'s can be tricky - if you require help, please see the', 'wpgetapi' ); ?> <a target="_blank" href="https://wpgetapi.com/docs/"><?php esc_html_e( 'Documentation', 'wpgetapi' ); ?></a>.</p>
458 + <?php } ?>
792 459
793 460 <div class="debug-item">
794 461 <h6><?php esc_html_e( 'Full URL', 'wpgetapi' ); ?></h6>
795 462 <p class="small"><?php esc_html_e( 'The full URL that is being called.', 'wpgetapi' ); ?></p>
@@ -836,10 +503,8 @@
836 503 <h6><?php esc_html_e( 'Response', 'wpgetapi' ); ?></h6>
837 504 <p class="small"><?php esc_html_e( 'The full response from the API request.', 'wpgetapi' ); ?></p>
838 505 <div class="debug-result"><?php wpgetapi_pp( $this->response); ?></div>
839 506 </div>
840 -
841 - <?php } ?>
842 507
843 508 </div>
844 509
845 510 <?php