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 +14 -118 1.9.51.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';
@@ -197,12 +193,8 @@
197 193 // PUT request
198 194 if( $this->method == 'PUT' )
199 195 $this->response = $this->PUT_request();
200 196
201 - // PATCH request
202 - if( $this->method == 'PATCH' )
203 - $this->response = $this->PATCH_request();
204 -
205 197 // GET request
206 198 if( $this->method == 'GET' )
207 199 $this->response = $this->GET_request();
208 200
@@ -215,12 +207,12 @@
215 207 return apply_filters( 'wpgetapi_raw_error_data', json_encode( $this->response ), $this );
216 208 }
217 209
218 210 // get response_code
219 - $this->response_code = wp_remote_retrieve_response_code( $this->response );
211 + $response_code = wp_remote_retrieve_response_code( $this->response );
220 212
221 213 // action to intercept call depending on response_code
222 - $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 );
223 215
224 216 // get body
225 217 // modified in version 1.6.1 to allow for OAuth 2.0 plugin returning body already
226 218 $data = isset( $this->response['body'] ) ? $this->response['body'] : $this->response;
@@ -277,9 +269,9 @@
277 269 ), $this );
278 270
279 271
280 272 // if doing POST request, include body paramters
281 - //if( $this->method == 'POST' || $this->method == 'PUT' || $this->method == 'DELETE' ) {
273 + if( $this->method == 'POST' || $this->method == 'PUT' || $this->method == 'DELETE' ) {
282 274
283 275 // tokens are sent through here
284 276 $this->body_parameters = apply_filters( 'wpgetapi_body_parameters', $this->body_parameters, $this );
285 277
@@ -288,9 +280,9 @@
288 280 $this->body_parameters = json_encode( $this->body_parameters );
289 281 }
290 282
291 283 // do we urlencode the entire body
292 - if( $this->body_parameters && $this->body_url_encode == true ) {
284 + if( $this->body_url_encode == true ) {
293 285
294 286 // checking if the parameters have a json string (raw)
295 287 if (
296 288 ( ! is_array( $this->body_parameters ) ) &&
@@ -303,9 +295,9 @@
303 295
304 296 }
305 297
306 298 // do we xml the entire body
307 - if( $this->body_parameters && $this->body_xml_format == true ) {
299 + if( $this->body_xml_format == true ) {
308 300
309 301 $xml = new SimpleXmlElement( '<' . $this->xml_root_node . '/>' );
310 302
311 303 foreach( $this->body_parameters as $key => $value) {
@@ -319,9 +311,9 @@
319 311 // add our body parameters
320 312 if( $this->body_parameters && ! empty( $this->body_parameters ) )
321 313 $headers['body'] = $this->body_parameters;
322 314
323 - //}
315 + }
324 316
325 317 // add headers to our final request args
326 318 $this->final_request_args = wp_parse_args( $headers, $this->final_request_args );
327 319
@@ -372,17 +364,8 @@
372 364 return $response;
373 365 }
374 366
375 367 /**
376 - * Do a PATCH request
377 - */
378 - public function PATCH_request() {
379 - $this->final_request_args['method'] = 'PATCH';
380 - $response = wp_remote_request( $this->final_url, $this->final_request_args );
381 - return $response;
382 - }
383 -
384 - /**
385 368 * Do a DELETE request
386 369 */
387 370 public function DELETE_request() {
388 371 $this->final_request_args['method'] = 'DELETE';
@@ -496,9 +479,9 @@
496 479
497 480 }
498 481
499 482 }
500 -
483 +
501 484 return $raw ? $raw : $new_array;
502 485
503 486 }
504 487
@@ -538,69 +521,10 @@
538 521 ) {
539 522
540 523 $this->debug = true;
541 524
542 - // admin test endpoint button
543 525 $testing = isset( $this->args['test_endpoint'] ) && ( $this->args['test_endpoint'] === true ) ? true : false;
544 526
545 - // get api status from response code
546 - $status = array(
547 - 'title' => 'Error in API response.',
548 - 'desc' => 'Check all details within your endpoint. Something is misconfigured.',
549 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
550 - );
551 -
552 - if( $this->response_code == 200 ) {
553 - $status = array(
554 - 'title' => 'Success!',
555 - '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.',
556 - 'type' => '<span class="dashicons dashicons-yes-alt"></span>'
557 - );
558 - }
559 - if( $this->response_code == 400 || $this->response_code == 404 ) {
560 - $status = array(
561 - 'title' => 'Bad Request',
562 - '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.',
563 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
564 - );
565 - }
566 - if( $this->response_code == 401 ) {
567 - $status = array(
568 - 'title' => 'Unauthorised',
569 - '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.',
570 - 'type' => '<span class="dashicons dashicons-warning"></span>'
571 - );
572 - }
573 - if( $this->response_code == 403 ) {
574 - $status = array(
575 - 'title' => 'Forbidden',
576 - '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.',
577 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
578 - );
579 - }
580 - if( $this->response_code == 405 ) {
581 - $status = array(
582 - 'title' => 'Method Not Allowed',
583 - 'desc' => 'Try changing the Request Method within the endpoint settings.',
584 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
585 - );
586 - }
587 - if( $this->response_code == 415 ) {
588 - $status = array(
589 - 'title' => 'Unsupported Media Type',
590 - '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>.',
591 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
592 - );
593 - }
594 - if( $this->response_code == 500 ) {
595 - $status = array(
596 - 'title' => 'Internal Server Error',
597 - 'desc' => 'This indicates an issue with the server. Contact your API provider.',
598 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
599 - );
600 - }
601 -
602 -
603 527 ob_start(); ?>
604 528
605 529 <style>
606 530
@@ -637,10 +561,10 @@
637 561 background: #fff;
638 562 padding: 15px 20px;
639 563 display: inline-block !important;
640 564 width: 100% !important;
641 - box-shadow: 0 3px 8px rgb(0 0 0 / 6%);
642 - border: 1px solid #eee;
565 + box-shadow: 3px 3px 0 rgb(0 0 0 / 8%);
566 + border: 1px solid #efefef;
643 567 }
644 568 .wpgetapi-debug .debug-item h6 {
645 569 font-weight: bold;
646 570 font-size: 14px;
@@ -652,14 +576,15 @@
652 576 font-family: monospace !important;
653 577 font-size: 13px !important;
654 578 margin: 0 !important;
655 579 padding: 8px 12px;
656 - background: #f4f7f9;
580 + background: #f8f8f8;
657 581 }
658 582 .wpgetapi-debug .debug-item .debug-result pre {
659 583 border: none;
660 584 padding: 5px
661 585 }
586 +
662 587 .wpgetapi-debug.testing {
663 588 background: transparent;
664 589 padding: 0;
665 590 box-shadow: none;
@@ -666,32 +591,8 @@
666 591 }
667 592 .wpgetapi-debug.testing .debug-item {
668 593 margin: 5px 0;
669 594 }
670 -.wpgetapi-debug.testing .debug-item.status {
671 - border: none;
672 - box-shadow: none;
673 - margin-bottom: 15px;
674 -}
675 -.wpgetapi-debug .debug-item.status h5 {
676 - font-size: 15px;
677 -}
678 -.wpgetapi-debug .status .dashicons {
679 - margin: 0 5px 3px 0;
680 -}
681 -.wpgetapi-debug .status .dashicons-yes-alt {
682 - color: #5e9929;
683 -}
684 -.wpgetapi-debug .status .dashicons-dismiss {
685 - color: #cc4646;
686 -}
687 -.wpgetapi-debug .status .dashicons-warning {
688 - color: #dfa12e;
689 -}
690 -.wpgetapi-debug .status .desc {
691 - font-size: 14px;
692 - font-weight: 400 !important;
693 -}
694 595 </style>
695 596
696 597 <div class="wpgetapi-debug <?php echo $testing ? 'testing' : ''; ?>">
697 598
@@ -696,15 +597,9 @@
696 597 <div class="wpgetapi-debug <?php echo $testing ? 'testing' : ''; ?>">
697 598
698 599 <?php if( $testing ) { ?>
699 600
700 - <div class="debug-item status">
701 - <div class="">
702 - <h5><?php _e( $status['type'] ); ?> <?php esc_html_e( $status['title'] ); ?></h5>
703 - <span class="desc"><?php _e( $status['desc'] ); ?></span>
704 - </div>
705 - </div>
706 - <div class="debug-item">
601 + <div class="debug-item">
707 602 <h6><?php esc_html_e( 'Full URL', 'wpgetapi' ); ?></h6>
708 603 <p class="small"><?php esc_html_e( 'The full URL that is being called.', 'wpgetapi' ); ?></p>
709 604 <div class="debug-result"><?php esc_html_e( $this->final_url ); ?></div>
710 605 </div>
@@ -711,8 +606,9 @@
711 606
712 607 <div class="debug-item">
713 608 <h6><?php esc_html_e( 'Data Output', 'wpgetapi' ); ?></h6>
714 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>
715 611 <div class="debug-result"><?php wpgetapi_pp( $data ); ?></div>
716 612 </div>
717 613
718 614 <div class="debug-item">