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 +10 -101 1.9.41.9.0 View file →
@@ -38,10 +38,8 @@
38 38 public $final_request_args = array(); // final request_args
39 39
40 40 public $results_format = 'json_string'; // results format
41 41
42 - public $response_code = ''; // the response code from the call
43 -
44 42 public $timeout = 10; // the timeout
45 43 public $sslverify = 1; // the paramaters
46 44 public $debug = false;
47 45
@@ -124,13 +122,11 @@
124 122 $this->header_parameters = isset( $endpoint['header_parameters'] ) && ! empty( $endpoint['header_parameters'] ) ? $this->do_parameters( $endpoint['header_parameters'] ) : array();
125 123
126 124 $this->body_parameters = isset( $endpoint['body_parameters'] ) && ! empty( $endpoint['body_parameters'] ) ? $this->do_parameters( $endpoint['body_parameters'] ) : array();
127 125
128 - // how to encode the body
129 126 $this->body_json_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'true' ? true : false;
130 127 $this->body_url_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'url' ? true : false;
131 128 $this->body_xml_format = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'xml' ? true : false;
132 -
133 129 $this->xml_root_node = isset( $endpoint['xml_root'] ) && ! empty( $endpoint['xml_root'] ) ? $endpoint['xml_root'] : $this->xml_root_node;
134 130
135 131 $this->results_format = isset( $endpoint['results_format'] ) ? sanitize_text_field( $endpoint['results_format'] ) : $this->results_format;
136 132
@@ -136,9 +132,9 @@
136 132
137 133
138 134 if(
139 135 // set the format to php array data if html format is set
140 - ( isset( $this->args['format'] ) && $this->args['format'] == 'html' && $this->results_format != 'xml_array' ) ||
136 + ( isset( $this->args['format'] ) && $this->args['format'] == 'html' ) ||
141 137 // set the format to php array data if it is set in the args (coming from the importer)
142 138 ( isset( $this->args['results_format'] ) && $this->args['results_format'] == 'json_decoded' )
143 139 ) {
144 140 $this->results_format = 'json_decoded';
@@ -211,12 +207,12 @@
211 207 return apply_filters( 'wpgetapi_raw_error_data', json_encode( $this->response ), $this );
212 208 }
213 209
214 210 // get response_code
215 - $this->response_code = wp_remote_retrieve_response_code( $this->response );
211 + $response_code = wp_remote_retrieve_response_code( $this->response );
216 212
217 213 // action to intercept call depending on response_code
218 - $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 );
219 215
220 216 // get body
221 217 // modified in version 1.6.1 to allow for OAuth 2.0 plugin returning body already
222 218 $data = isset( $this->response['body'] ) ? $this->response['body'] : $this->response;
@@ -483,9 +479,9 @@
483 479
484 480 }
485 481
486 482 }
487 -
483 +
488 484 return $raw ? $raw : $new_array;
489 485
490 486 }
491 487
@@ -525,69 +521,10 @@
525 521 ) {
526 522
527 523 $this->debug = true;
528 524
529 - // admin test endpoint button
530 525 $testing = isset( $this->args['test_endpoint'] ) && ( $this->args['test_endpoint'] === true ) ? true : false;
531 526
532 - // get api status from response code
533 - $status = array(
534 - 'title' => 'Error in API response.',
535 - 'desc' => 'Check all details within your endpoint. Something is misconfigured.',
536 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
537 - );
538 -
539 - if( $this->response_code == 200 ) {
540 - $status = array(
541 - 'title' => 'Success!',
542 - '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.',
543 - 'type' => '<span class="dashicons dashicons-yes-alt"></span>'
544 - );
545 - }
546 - if( $this->response_code == 400 || $this->response_code == 404 ) {
547 - $status = array(
548 - 'title' => 'Bad Request',
549 - '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.',
550 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
551 - );
552 - }
553 - if( $this->response_code == 401 ) {
554 - $status = array(
555 - 'title' => 'Unauthorised',
556 - '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.',
557 - 'type' => '<span class="dashicons dashicons-warning"></span>'
558 - );
559 - }
560 - if( $this->response_code == 403 ) {
561 - $status = array(
562 - 'title' => 'Forbidden',
563 - '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.',
564 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
565 - );
566 - }
567 - if( $this->response_code == 405 ) {
568 - $status = array(
569 - 'title' => 'Method Not Allowed',
570 - 'desc' => 'Try changing the Request Method within the endpoint settings.',
571 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
572 - );
573 - }
574 - if( $this->response_code == 415 ) {
575 - $status = array(
576 - 'title' => 'Unsupported Media Type',
577 - '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>.',
578 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
579 - );
580 - }
581 - if( $this->response_code == 500 ) {
582 - $status = array(
583 - 'title' => 'Internal Server Error',
584 - 'desc' => 'This indicates an issue with the server. Contact your API provider.',
585 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
586 - );
587 - }
588 -
589 -
590 527 ob_start(); ?>
591 528
592 529 <style>
593 530
@@ -624,10 +561,10 @@
624 561 background: #fff;
625 562 padding: 15px 20px;
626 563 display: inline-block !important;
627 564 width: 100% !important;
628 - box-shadow: 0 3px 8px rgb(0 0 0 / 6%);
629 - border: 1px solid #eee;
565 + box-shadow: 3px 3px 0 rgb(0 0 0 / 8%);
566 + border: 1px solid #efefef;
630 567 }
631 568 .wpgetapi-debug .debug-item h6 {
632 569 font-weight: bold;
633 570 font-size: 14px;
@@ -639,14 +576,15 @@
639 576 font-family: monospace !important;
640 577 font-size: 13px !important;
641 578 margin: 0 !important;
642 579 padding: 8px 12px;
643 - background: #f4f7f9;
580 + background: #f8f8f8;
644 581 }
645 582 .wpgetapi-debug .debug-item .debug-result pre {
646 583 border: none;
647 584 padding: 5px
648 585 }
586 +
649 587 .wpgetapi-debug.testing {
650 588 background: transparent;
651 589 padding: 0;
652 590 box-shadow: none;
@@ -653,32 +591,8 @@
653 591 }
654 592 .wpgetapi-debug.testing .debug-item {
655 593 margin: 5px 0;
656 594 }
657 -.wpgetapi-debug.testing .debug-item.status {
658 - border: none;
659 - box-shadow: none;
660 - margin-bottom: 15px;
661 -}
662 -.wpgetapi-debug .debug-item.status h5 {
663 - font-size: 15px;
664 -}
665 -.wpgetapi-debug .status .dashicons {
666 - margin: 0 5px 3px 0;
667 -}
668 -.wpgetapi-debug .status .dashicons-yes-alt {
669 - color: #5e9929;
670 -}
671 -.wpgetapi-debug .status .dashicons-dismiss {
672 - color: #cc4646;
673 -}
674 -.wpgetapi-debug .status .dashicons-warning {
675 - color: #dfa12e;
676 -}
677 -.wpgetapi-debug .status .desc {
678 - font-size: 14px;
679 - font-weight: 400 !important;
680 -}
681 595 </style>
682 596
683 597 <div class="wpgetapi-debug <?php echo $testing ? 'testing' : ''; ?>">
684 598
@@ -683,15 +597,9 @@
683 597 <div class="wpgetapi-debug <?php echo $testing ? 'testing' : ''; ?>">
684 598
685 599 <?php if( $testing ) { ?>
686 600
687 - <div class="debug-item status">
688 - <div class="">
689 - <h5><?php _e( $status['type'] ); ?> <?php esc_html_e( $status['title'] ); ?></h5>
690 - <span class="desc"><?php _e( $status['desc'] ); ?></span>
691 - </div>
692 - </div>
693 - <div class="debug-item">
601 + <div class="debug-item">
694 602 <h6><?php esc_html_e( 'Full URL', 'wpgetapi' ); ?></h6>
695 603 <p class="small"><?php esc_html_e( 'The full URL that is being called.', 'wpgetapi' ); ?></p>
696 604 <div class="debug-result"><?php esc_html_e( $this->final_url ); ?></div>
697 605 </div>
@@ -698,8 +606,9 @@
698 606
699 607 <div class="debug-item">
700 608 <h6><?php esc_html_e( 'Data Output', 'wpgetapi' ); ?></h6>
701 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>
702 611 <div class="debug-result"><?php wpgetapi_pp( $data ); ?></div>
703 612 </div>
704 613
705 614 <div class="debug-item">