PluginProbe
WPGet API – Connect to any external REST API / 1.9.0
WPGet API – Connect to any external REST API v1.9.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 +93 -235 2.2.01.9.0 View file →
@@ -28,9 +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 32 public $body_xml_format = ''; // xml format body
34 33 public $xml_root_node = 'root'; // root node for xml
35 34
36 35 public $response = ''; // the returned response
@@ -39,15 +38,11 @@
39 38 public $final_request_args = array(); // final request_args
40 39
41 40 public $results_format = 'json_string'; // results format
42 41
43 - public $response_code = ''; // the response code from the call
44 -
45 42 public $timeout = 10; // the timeout
46 - public $sslverify = 1; // ssl verify
43 + public $sslverify = 1; // the paramaters
47 44 public $debug = false;
48 -
49 - public $pro_plugin = false;
50 45
51 46
52 47 /**
53 48 * Main constructor
@@ -65,9 +60,8 @@
65 60 $this->endpoint_id = sanitize_text_field( $endpoint_id );
66 61 $this->keys = $keys;
67 62 $this->args = $args;
68 63
69 - add_filter( 'wpgetapi_raw_error_data', array( $this, 'maybe_add_debug_info' ), 99, 2 );
70 64 add_filter( 'wpgetapi_raw_data', array( $this, 'maybe_add_debug_info' ), 99, 2 );
71 65
72 66 }
73 67
@@ -76,17 +70,11 @@
76 70 * Init our api data
77 71 */
78 72 public function init() {
79 73
80 - if ( ! function_exists( 'is_plugin_active' ) ) {
81 - include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
82 - }
83 -
84 - $this->pro_plugin = is_plugin_active( 'wpgetapi-extras/wpgetapi-extras.php' ) ? true : false;
85 -
86 74 // if we are doing importer plugin,
87 75 // we need to intercept and modify most of our methods values
88 - if( $this->api_id === 'wpgetapi_importer' ) {
76 + if( $this->api_id == 'wpgetapi_importer' ) {
89 77
90 78 $data = apply_filters( 'wpgetapi_api_importer_init', $this );
91 79
92 80 if( $data ) {
@@ -125,9 +113,8 @@
125 113
126 114 if( $this->endpoint_id == $endpoint['id'] ) {
127 115
128 116 $this->method = isset( $endpoint['method'] ) && $endpoint['method'] != '' ? sanitize_text_field( $endpoint['method'] ) : 'GET';
129 - $this->timeout = isset( $endpoint['timeout'] ) && ! empty( $endpoint['timeout'] ) ? absint( $endpoint['timeout'] ) : '';
130 117 $this->cache_time = isset( $endpoint['cache_time'] ) && ! empty( $endpoint['cache_time'] ) ? absint( $endpoint['cache_time'] ) : '';
131 118 $this->endpoint = isset( $endpoint['endpoint'] ) && ! empty( $endpoint['endpoint'] ) ? sanitize_text_field( $endpoint['endpoint'] ) : '';
132 119
133 120 $this->query_parameters = isset( $endpoint['query_parameters'] ) && ! empty( $endpoint['query_parameters'] ) ? $this->do_parameters( $endpoint['query_parameters'] ) : array();
@@ -135,14 +122,11 @@
135 122 $this->header_parameters = isset( $endpoint['header_parameters'] ) && ! empty( $endpoint['header_parameters'] ) ? $this->do_parameters( $endpoint['header_parameters'] ) : array();
136 123
137 124 $this->body_parameters = isset( $endpoint['body_parameters'] ) && ! empty( $endpoint['body_parameters'] ) ? $this->do_parameters( $endpoint['body_parameters'] ) : array();
138 125
139 - // how to encode the body
140 126 $this->body_json_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'true' ? true : false;
141 127 $this->body_url_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'url' ? true : false;
142 - $this->body_base64_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'base64' ? true : false;
143 128 $this->body_xml_format = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'xml' ? true : false;
144 -
145 129 $this->xml_root_node = isset( $endpoint['xml_root'] ) && ! empty( $endpoint['xml_root'] ) ? $endpoint['xml_root'] : $this->xml_root_node;
146 130
147 131 $this->results_format = isset( $endpoint['results_format'] ) ? sanitize_text_field( $endpoint['results_format'] ) : $this->results_format;
148 132
@@ -148,9 +132,9 @@
148 132
149 133
150 134 if(
151 135 // set the format to php array data if html format is set
152 - ( isset( $this->args['format'] ) && $this->args['format'] == 'html' && $this->results_format != 'xml_array' ) ||
136 + ( isset( $this->args['format'] ) && $this->args['format'] == 'html' ) ||
153 137 // set the format to php array data if it is set in the args (coming from the importer)
154 138 ( isset( $this->args['results_format'] ) && $this->args['results_format'] == 'json_decoded' )
155 139 ) {
156 140 $this->results_format = 'json_decoded';
@@ -155,18 +139,8 @@
155 139 ) {
156 140 $this->results_format = 'json_decoded';
157 141 }
158 142
159 - // set the format to JSON string if it is set in the args (coming from the wpdatatables integration)
160 - if( isset( $this->args['results_format'] ) && $this->args['results_format'] == 'json_string' ) {
161 - $this->results_format = 'json_string';
162 - }
163 -
164 - // set the format to JSON string if it is set in the args (coming from the wpdatatables integration)
165 - if( isset( $this->args['results_format'] ) && $this->args['results_format'] == 'json_decoded' ) {
166 - $this->results_format = 'json_decoded';
167 - }
168 -
169 143 }
170 144
171 145 }
172 146
@@ -219,12 +193,8 @@
219 193 // PUT request
220 194 if( $this->method == 'PUT' )
221 195 $this->response = $this->PUT_request();
222 196
223 - // PATCH request
224 - if( $this->method == 'PATCH' )
225 - $this->response = $this->PATCH_request();
226 -
227 197 // GET request
228 198 if( $this->method == 'GET' )
229 199 $this->response = $this->GET_request();
230 200
@@ -237,12 +207,12 @@
237 207 return apply_filters( 'wpgetapi_raw_error_data', json_encode( $this->response ), $this );
238 208 }
239 209
240 210 // get response_code
241 - $this->response_code = wp_remote_retrieve_response_code( $this->response );
211 + $response_code = wp_remote_retrieve_response_code( $this->response );
242 212
243 213 // action to intercept call depending on response_code
244 - $this->response = apply_filters( 'wpgetapi_before_retrieve_body', $this->response, $this->response_code, $this );
214 + $this->response = apply_filters( 'wpgetapi_before_retrieve_body', $this->response, $response_code, $this );
245 215
246 216 // get body
247 217 // modified in version 1.6.1 to allow for OAuth 2.0 plugin returning body already
248 218 $data = isset( $this->response['body'] ) ? $this->response['body'] : $this->response;
@@ -267,14 +237,8 @@
267 237 // first make sure our endpoint starts with a slash
268 238 if ( substr( $this->endpoint, 0, 1 ) != '/' )
269 239 $this->endpoint = '/' . $this->endpoint;
270 240
271 - // if we have item_key from api to posts plugin
272 - // replace our keyword with the actual item_key value
273 - if ( isset( $this->args['item_key'] ) && strpos( $this->endpoint, '(importer:item_key)' ) !== false ) {
274 - $this->endpoint = str_replace( '(importer:item_key)', $this->args['item_key'], $this->endpoint );
275 - }
276 -
277 241 $this->endpoint = apply_filters( 'wpgetapi_endpoint', $this->endpoint, $this );
278 242
279 243 $url = untrailingslashit( $this->base_url ) . $this->endpoint;
280 244
@@ -288,12 +252,10 @@
288 252
289 253 // add empty array - was getting errors if it was just null or false
290 254 $params = empty( $params ) ? array(''=>'') : $params;
291 255
292 - $result = add_query_arg( $params, $url );
256 + return add_query_arg( $params, $url );
293 257
294 - return $result;
295 -
296 258 }
297 259
298 260
299 261 /**
@@ -307,13 +269,13 @@
307 269 ), $this );
308 270
309 271
310 272 // if doing POST request, include body paramters
311 - if( $this->method == 'POST' || $this->method == 'PUT' || $this->method == 'DELETE' || $this->method == 'PATCH' ) {
273 + if( $this->method == 'POST' || $this->method == 'PUT' || $this->method == 'DELETE' ) {
312 274
313 275 // tokens are sent through here
314 276 $this->body_parameters = apply_filters( 'wpgetapi_body_parameters', $this->body_parameters, $this );
315 -
277 +
316 278 // do we json_encode the entire body
317 279 if( $this->body_json_encode == true ) {
318 280 $this->body_parameters = json_encode( $this->body_parameters );
319 281 }
@@ -318,9 +280,9 @@
318 280 $this->body_parameters = json_encode( $this->body_parameters );
319 281 }
320 282
321 283 // do we urlencode the entire body
322 - if( $this->body_parameters && $this->body_url_encode == true ) {
284 + if( $this->body_url_encode == true ) {
323 285
324 286 // checking if the parameters have a json string (raw)
325 287 if (
326 288 ( ! is_array( $this->body_parameters ) ) &&
@@ -333,15 +295,11 @@
333 295
334 296 }
335 297
336 298 // do we xml the entire body
337 - if( $this->body_parameters && $this->body_xml_format == true ) {
338 -
339 - $root_node = $this->xml_root_node != '' ? '<' . $this->xml_root_node . '/>' : '';
299 + if( $this->body_xml_format == true ) {
340 300
341 - $xml_element = apply_filters( 'wpgetapi_xml_element', '<?xml version="1.0" encoding="UTF-8"?>' . $root_node );
342 -
343 - $xml = new SimpleXmlElement( $xml_element );
301 + $xml = new SimpleXmlElement( '<' . $this->xml_root_node . '/>' );
344 302
345 303 foreach( $this->body_parameters as $key => $value) {
346 304 $xml->addChild( $key, $value );
347 305 }
@@ -349,18 +307,8 @@
349 307 $this->body_parameters = $xml->asXML();
350 308
351 309 }
352 310
353 - // do we base64 encode the entire body
354 - if( $this->body_parameters && $this->body_base64_encode == true ) {
355 -
356 - $this->body_parameters = is_array( $this->body_parameters ) ? json_encode( $this->body_parameters ) : $this->body_parameters;
357 - $this->body_parameters = base64_encode( $this->body_parameters );
358 -
359 - }
360 -
361 - $this->body_parameters = apply_filters( 'wpgetapi_modify_formatted_body_parameters', $this->body_parameters, $this );
362 -
363 311 // add our body parameters
364 312 if( $this->body_parameters && ! empty( $this->body_parameters ) )
365 313 $headers['body'] = $this->body_parameters;
366 314
@@ -365,18 +313,14 @@
365 313 $headers['body'] = $this->body_parameters;
366 314
367 315 }
368 316
369 - // get our body paramters as they are formatted
370 - // this won't change anything, it just allows us to get the parameters
371 - $this->body_parameters = apply_filters( 'wpgetapi_final_body_parameters', $this->body_parameters, $this );
372 -
373 317 // add headers to our final request args
374 318 $this->final_request_args = wp_parse_args( $headers, $this->final_request_args );
375 319
376 320 // build the args taht are sent to the request
377 321 $default_args = apply_filters( 'wpgetapi_default_request_args_parameters', array(
378 - 'timeout' => ( absint( $this->timeout ) > 0 ? absint( $this->timeout ) : 10 ),
322 + 'timeout' => $this->timeout,
379 323 'sslverify' => $this->sslverify,
380 324 'redirection' => 5,
381 325 'blocking' => true,
382 326 'cookies' => array(),
@@ -392,9 +336,8 @@
392 336 /**
393 337 * Do a GET request
394 338 */
395 339 public function GET_request() {
396 -
397 340 $response = '';
398 341 // so we can so something before the remote_get (caching)
399 342 $response = apply_filters( 'wpgetapi_before_get_request', $response, $this );
400 343
@@ -399,11 +342,9 @@
399 342 $response = apply_filters( 'wpgetapi_before_get_request', $response, $this );
400 343
401 344 if( empty( $response ) )
402 345 $response = wp_remote_get( $this->final_url, $this->final_request_args );
403 -
404 346 return $response;
405 -
406 347 }
407 348
408 349 /**
409 350 * Do a POST request
@@ -408,18 +349,10 @@
408 349 /**
409 350 * Do a POST request
410 351 */
411 352 public function POST_request() {
412 -
413 - $response = '';
414 - // so we can so something before the remote_post (caching)
415 - $response = apply_filters( 'wpgetapi_before_post_request', $response, $this );
416 -
417 - //$this->final_request_args['method'] = 'POST';
418 -
419 - if( empty( $response ) )
420 - $response = wp_remote_post( $this->final_url, $this->final_request_args );
421 -
353 + $this->final_request_args['method'] = 'POST';
354 + $response = wp_remote_post( $this->final_url, $this->final_request_args );
422 355 return $response;
423 356 }
424 357
425 358 /**
@@ -431,17 +364,8 @@
431 364 return $response;
432 365 }
433 366
434 367 /**
435 - * Do a PATCH request
436 - */
437 - public function PATCH_request() {
438 - $this->final_request_args['method'] = 'PATCH';
439 - $response = wp_remote_request( $this->final_url, $this->final_request_args );
440 - return $response;
441 - }
442 -
443 - /**
444 368 * Do a DELETE request
445 369 */
446 370 public function DELETE_request() {
447 371 $this->final_request_args['method'] = 'DELETE';
@@ -455,9 +379,9 @@
455 379 */
456 380 public function return_data( $data ) {
457 381
458 382 $data = apply_filters( 'wpgetapi_json_response_body_before_decode', $data, $this->keys );
459 -
383 +
460 384 // converts all data to arrays, removing objects
461 385 if( is_string( $data ) ) {
462 386 $decode = json_decode( $data, true );
463 387 if( json_last_error() ) {
@@ -465,13 +389,13 @@
465 389 } else {
466 390 $data = $decode;
467 391 }
468 392 }
469 -
393 +
470 394 $data = apply_filters( 'wpgetapi_json_response_body', $data, $this->keys );
471 395
472 396 if( $this->results_format == 'json_string' )
473 - return trim( json_encode( $data, JSON_PRETTY_PRINT ),'"');
397 + return trim( json_encode( $data ),'"');
474 398
475 399 if( $this->results_format == 'json_decoded' )
476 400 return $data;
477 401
@@ -480,9 +404,9 @@
480 404 /**
481 405 * Sort out the parameters if they exist
482 406 */
483 407 public function do_parameters( $parameters ) {
484 -
408 +
485 409 $new_array = array();
486 410 $raw = '';
487 411 $parameters = $this->decrypt( $parameters );
488 412
@@ -498,14 +422,8 @@
498 422 unset( $parameters[ $key ] );
499 423 continue;
500 424 }
501 425
502 - // if we have item_key from api to posts plugin
503 - // replace our keyword with the actual item_key value
504 - if ( isset( $this->args['item_key'] ) && strpos( $parameter['value'], '(importer:item_key)' ) !== false ) {
505 - $parameter['value'] = str_replace( '(importer:item_key)', $this->args['item_key'], $parameter['value'] );
506 - }
507 -
508 426 $new_array[ sanitize_text_field( $parameter['name'] ) ] = $parameter['value'];
509 427
510 428 // if we are sending raw body
511 429 } else if( empty( $parameter['name'] ) && ! empty( $parameter['value'] ) ) {
@@ -516,20 +434,17 @@
516 434
517 435 }
518 436 }
519 437
520 - // now look for array or json string and sort these out - for using such things in shortcode
438 + // look for array or json string and sort these out - for using such things in shortcode
521 439 if( ! empty( $new_array ) ) {
522 440
523 441 foreach ( $new_array as $key => $value ) {
524 442
525 443 // checking if the parameters have a json string
526 - if ( strpos( $value, '{"' ) !== false && strpos( $value, '}' ) !== false ) {
527 -
528 - $tmp_val = $value;
529 - $tmp_val = json_decode( $tmp_val, true );
530 - $new_array[ $key ] = $tmp_val ? $tmp_val : $value;
531 -
444 + if ( strpos( $value, '{' ) !== false && strpos( $value, '}' ) !== false ) {
445 + //if ( substr( $value, 0, 1 ) === '{' && substr( $value, -1 ) === '}' ) {
446 + $new_array[ $key ] = json_decode( $value, true );
532 447 } else
533 448
534 449 // checking if the parameters have an array within the string
535 450 // if they do, create them as an actual array
@@ -539,38 +454,17 @@
539 454 }
540 455
541 456 // set value as integer
542 457 if ( strpos( $value, 'integer(' ) !== false && substr( $value, -1 ) === ')' ) {
543 -
544 458 preg_match("/\(([^\)]*)\)/", $value, $match );
545 - $result = trim( $match[1] );
546 -
547 - // checking if we have additional token within
548 - // and we need to send this directly to PRO plugin from here
549 - if( strpos( $value, '(' ) !== false && strpos( $value, ':' ) !== false && $this->pro_plugin ) {
550 - $result = $this->replace_tokens( $result );
551 - } else {
552 - $result = $result;
553 - }
554 -
459 + $result = $match[1];
555 460 $new_array[ $key ] = absint( $result );
556 -
557 461 }
558 462
559 463 // set value as float
560 464 if ( strpos( $value, 'float(' ) !== false && substr( $value, -1 ) === ')' ) {
561 -
562 465 preg_match("/\(([^\)]*)\)/", $value, $match );
563 - $result = trim( $match[1] );
564 - if ( substr( $result, 0, 1 ) === '"' && substr( $result, -1 ) === '"' )
565 - $result = trim( $result,'""' );
566 -
567 - // checking if we have additional token within
568 - // and we need to send this directly to PRO plugin from here
569 - if( strpos( $value, '(' ) !== false && strpos( $value, ':' ) !== false && $this->pro_plugin ) {
570 - $result = $this->replace_tokens( $result );
571 - }
572 -
466 + $result = $match[1];
573 467 $new_array[ $key ] = (float) $result;
574 468
575 469 }
576 470
@@ -577,19 +471,9 @@
577 471 // set value as boolean
578 472 if ( strpos( $value, 'boolean(' ) !== false && substr( $value, -1 ) === ')' ) {
579 473 preg_match("/\(([^\)]*)\)/", $value, $match );
580 474 $result = $match[1];
581 -
582 - // checking if we have additional token within
583 - // and we need to send this directly to PRO plugin from here
584 - if( strpos( $value, '(' ) !== false && strpos( $value, ':' ) !== false && $this->pro_plugin ) {
585 - $result = $this->replace_tokens( $result );
586 - } else {
587 - $result = $result;
588 - }
589 -
590 475 $result = filter_var( $result, FILTER_VALIDATE_BOOLEAN );
591 -
592 476 $new_array[ $key ] = $result;
593 477
594 478 }
595 479
@@ -595,9 +479,9 @@
595 479
596 480 }
597 481
598 482 }
599 -
483 +
600 484 return $raw ? $raw : $new_array;
601 485
602 486 }
603 487
@@ -602,20 +486,8 @@
602 486 }
603 487
604 488
605 489 /**
606 - * Do a direct token replacement if PRO plugin installed and is required.
607 - */
608 - public function replace_tokens( $value ) {
609 - $tokens = new WpGetApi_Extras_Tokens();
610 - $action_args = isset( $this->args['action_args'] ) ? $this->args['action_args'] : null;
611 - $value = ( substr( $value, -1 ) !== ')' ? $value . ')' : $value );
612 - $result = $tokens->replace_tokens( $value, $action_args );
613 - return $result;
614 - }
615 -
616 -
617 - /**
618 490 * decrypt our parameters from the DB
619 491 */
620 492 public function decrypt( $array_or_string ) {
621 493
@@ -649,100 +521,85 @@
649 521 ) {
650 522
651 523 $this->debug = true;
652 524
653 - // admin test endpoint button
654 525 $testing = isset( $this->args['test_endpoint'] ) && ( $this->args['test_endpoint'] === true ) ? true : false;
655 526
656 - // get api status from response code
657 - $status = array(
658 - 'title' => 'Error in API response.',
659 - 'desc' => 'Check all details within your endpoint. Something is misconfigured.',
660 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
661 - );
527 + ob_start(); ?>
662 528
663 - $search = 'cURL error 28';
664 - if( isset( $data ) && preg_match( "/{$search}/i", $data ) ) {
665 - $status = array(
666 - 'title' => 'Error!',
667 - 'desc' => 'Timeout error. Try increasing the timeout value.',
668 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
669 - );
670 - }
529 +<style>
671 530
672 - $search = 'cURL error 60';
673 - if( isset( $data ) && preg_match( "/{$search}/i", $data ) ) {
674 - $status = array(
675 - 'title' => 'Error!',
676 - 'desc' => 'SSL verification has failed. See <a href="https://wordpress.stackexchange.com/a/167910/11827" target="_blank">here</a> for possible solution.',
677 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
678 - );
679 - }
531 +.wpgetapi-debug {
532 + background: #fff;
533 + padding: 20px;
534 + box-shadow: 0 0 1px #aaa;
535 + margin: 20px;
536 + font-size: 15px;
537 +}
538 +.wpgetapi-debug
539 +.wpgetapi-debug p
540 +.wpgetapi-debug h5
541 +.wpgetapi-debug h6 {
542 + color: #000;
543 + line-height: 1 !important;
544 + text-transform: none !important;
545 + font-family: sans-serif !important;
546 + letter-spacing: 0px !important;
547 +}
548 +.wpgetapi-debug p.small {
549 + font-size: 85%;
550 + color: #999;
551 + margin: 0 0 12px !important;
552 +}
553 +.wpgetapi-debug h5 {
554 + font-weight: bold;
555 + font-size: 18px;
556 + margin: 0 0 3px;
557 + text-transform: none !important;
558 +}
559 +.wpgetapi-debug .debug-item {
560 + margin: 10px 0;
561 + background: #fff;
562 + padding: 15px 20px;
563 + display: inline-block !important;
564 + width: 100% !important;
565 + box-shadow: 3px 3px 0 rgb(0 0 0 / 8%);
566 + border: 1px solid #efefef;
567 +}
568 +.wpgetapi-debug .debug-item h6 {
569 + font-weight: bold;
570 + font-size: 14px;
571 + margin: 0;
572 + text-transform: none !important;
573 +}
574 +.wpgetapi-debug .debug-item .debug-result,
575 +.wpgetapi-debug .debug-item .debug-result pre {
576 + font-family: monospace !important;
577 + font-size: 13px !important;
578 + margin: 0 !important;
579 + padding: 8px 12px;
580 + background: #f8f8f8;
581 +}
582 +.wpgetapi-debug .debug-item .debug-result pre {
583 + border: none;
584 + padding: 5px
585 +}
680 586
681 - if( $this->response_code >= 200 && $this->response_code <= 299 ) {
682 - $status = array(
683 - 'title' => 'Success!',
684 - '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.',
685 - 'type' => '<span class="dashicons dashicons-yes-alt"></span>'
686 - );
687 - }
688 - if( $this->response_code >= 400 && $this->response_code <= 499 ) {
689 - $status = array(
690 - 'title' => 'Bad Request',
691 - '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.',
692 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
693 - );
694 - }
695 - if( $this->response_code == 401 ) {
696 - $status = array(
697 - 'title' => 'Unauthorised',
698 - '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.',
699 - 'type' => '<span class="dashicons dashicons-warning"></span>'
700 - );
701 - }
702 - if( $this->response_code == 403 ) {
703 - $status = array(
704 - 'title' => 'Forbidden',
705 - '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.',
706 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
707 - );
708 - }
709 - if( $this->response_code == 405 ) {
710 - $status = array(
711 - 'title' => 'Method Not Allowed',
712 - 'desc' => 'Try changing the Request Method within the endpoint settings.',
713 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
714 - );
715 - }
716 - if( $this->response_code == 415 ) {
717 - $status = array(
718 - 'title' => 'Unsupported Media Type',
719 - '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>.',
720 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
721 - );
722 - }
723 - if( $this->response_code >= 500 && $this->response_code <= 599 ) {
724 - $status = array(
725 - 'title' => 'Internal Server Error',
726 - 'desc' => 'This indicates an issue with the API server. Contact your API provider.',
727 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
728 - );
729 - }
587 +.wpgetapi-debug.testing {
588 + background: transparent;
589 + padding: 0;
590 + box-shadow: none;
591 +}
592 +.wpgetapi-debug.testing .debug-item {
593 + margin: 5px 0;
594 +}
595 +</style>
730 596
731 -
732 - ob_start(); ?>
733 -
734 597 <div class="wpgetapi-debug <?php echo $testing ? 'testing' : ''; ?>">
735 598
736 599 <?php if( $testing ) { ?>
737 600
738 - <div class="debug-item status">
739 - <div class="">
740 - <h5><?php _e( $status['type'] ); ?> <?php esc_html_e( $status['title'] ); ?></h5>
741 - <span class="desc"><?php _e( $status['desc'] ); ?></span>
742 - </div>
743 - </div>
744 - <div class="debug-item">
601 + <div class="debug-item">
745 602 <h6><?php esc_html_e( 'Full URL', 'wpgetapi' ); ?></h6>
746 603 <p class="small"><?php esc_html_e( 'The full URL that is being called.', 'wpgetapi' ); ?></p>
747 604 <div class="debug-result"><?php esc_html_e( $this->final_url ); ?></div>
748 605 </div>
@@ -749,8 +606,9 @@
749 606
750 607 <div class="debug-item">
751 608 <h6><?php esc_html_e( 'Data Output', 'wpgetapi' ); ?></h6>
752 609 <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>
610 + <p class="small"><?php esc_html_e( 'See the ', 'wpgetapi' ); ?> <a target="_blank" href="https://wpgetapi.com/docs/?utm_campaign=Test Endpoint&utm_medium=Admin&utm_source=User"><?php esc_html_e( 'documentation', 'wpgetapi' ); ?></a> <?php esc_html_e( ' for help in formatting.', 'wpgetapi' ); ?></p>
753 611 <div class="debug-result"><?php wpgetapi_pp( $data ); ?></div>
754 612 </div>
755 613
756 614 <div class="debug-item">