PluginProbe
WPGet API – Connect to any external REST API / 1.4.0
WPGet API – Connect to any external REST API v1.4.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 +103 -479 2.0.51.4.0 View file →
@@ -26,13 +26,9 @@
26 26 public $endpoint = ''; // the endpoint that we will get
27 27 public $query_parameters = ''; // the query paramaters appended to url
28 28 public $header_parameters = ''; // the header paramaters
29 29 public $body_parameters = ''; // the body paramaters
30 - public $body_json_encode = ''; // body_json_encode body
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
30 + public $body_json_encode = ''; // the body_json_encode
35 31
36 32 public $response = ''; // the returned response
37 33
38 34 public $final_url = ''; // final URL
@@ -37,15 +33,12 @@
37 33
38 34 public $final_url = ''; // final URL
39 35 public $final_request_args = array(); // final request_args
40 36
41 - public $results_format = 'json_string'; // results format
37 + public $results_format = 'json_string'; // reseults format
42 38
43 - public $response_code = ''; // the response code from the call
44 -
45 39 public $timeout = 10; // the timeout
46 - public $sslverify = 1; // ssl verify
47 - public $debug = false;
40 + public $sslverify = 1; // the paramaters
48 41
49 42
50 43 /**
51 44 * Main constructor
@@ -63,9 +56,9 @@
63 56 $this->endpoint_id = sanitize_text_field( $endpoint_id );
64 57 $this->keys = $keys;
65 58 $this->args = $args;
66 59
67 - add_filter( 'wpgetapi_raw_data', array( $this, 'maybe_add_debug_info' ), 99, 2 );
60 + add_filter( 'wpgetapi_raw_data', array( $this, 'maybe_add_debug_info' ), 5, 2 );
68 61
69 62 }
70 63
71 64
@@ -73,29 +66,8 @@
73 66 * Init our api data
74 67 */
75 68 public function init() {
76 69
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 70 // do some checks
99 71 if( empty( $this->setup ) || ! isset( $this->setup['apis'] ) || empty( $this->setup['apis'] ) )
100 72 return 'No API found.';
101 73
@@ -114,9 +86,9 @@
114 86 // loop through endpoints
115 87 foreach ( $this->api['endpoints'] as $index => $endpoint ) {
116 88
117 89 if( $this->endpoint_id == $endpoint['id'] ) {
118 -
90 +
119 91 $this->method = isset( $endpoint['method'] ) && $endpoint['method'] != '' ? sanitize_text_field( $endpoint['method'] ) : 'GET';
120 92 $this->cache_time = isset( $endpoint['cache_time'] ) && ! empty( $endpoint['cache_time'] ) ? absint( $endpoint['cache_time'] ) : '';
121 93 $this->endpoint = isset( $endpoint['endpoint'] ) && ! empty( $endpoint['endpoint'] ) ? sanitize_text_field( $endpoint['endpoint'] ) : '';
122 94
@@ -125,40 +97,11 @@
125 97 $this->header_parameters = isset( $endpoint['header_parameters'] ) && ! empty( $endpoint['header_parameters'] ) ? $this->do_parameters( $endpoint['header_parameters'] ) : array();
126 98
127 99 $this->body_parameters = isset( $endpoint['body_parameters'] ) && ! empty( $endpoint['body_parameters'] ) ? $this->do_parameters( $endpoint['body_parameters'] ) : array();
128 100
129 - // how to encode the body
130 - $this->body_json_encode = isset( $endpoint['body_json_encode'] ) && $endpoint['body_json_encode'] == 'true' ? true : false;
131 - $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 -
135 - $this->xml_root_node = isset( $endpoint['xml_root'] ) && ! empty( $endpoint['xml_root'] ) ? $endpoint['xml_root'] : $this->xml_root_node;
136 -
101 + $this->body_json_encode = isset( $endpoint['body_json_encode'] ) && ! empty( $endpoint['body_json_encode'] ) ? sanitize_text_field( $endpoint['body_json_encode'] ) : true;
137 102 $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 103 }
160 -
161 104 }
162 105
163 106 $this->timeout = isset( $this->api['timeout'] ) && ! empty( $this->api['timeout'] ) ? $this->api['timeout'] : $this->timeout;
164 107 $this->sslverify = isset( $this->api['sslverify'] ) ? absint( $this->api['sslverify'] ) : $this->sslverify;
@@ -171,21 +114,58 @@
171 114 *
172 115 * @param string $field Field to retrieve
173 116 */
174 117 public function endpoint_output() {
118 + return $this->do_the_call();
119 + }
175 120
176 - do_action( 'wpgetapi_before_do_the_call', $this );
177 121
178 - return $this->do_the_call();
122 + /**
123 + * Sort out the parameters if they exist
124 + */
125 + public function do_parameters( $parameters ) {
126 +
127 + $new_array = array();
128 + $parameters = $this->decrypt($parameters);
179 129
130 + if( is_array( $parameters ) ) {
131 + foreach ( $parameters as $key => $parameter ) {
132 + if( ! empty( $parameter['name'] ) && ! empty( $parameter['value'] ) ) {
133 + $parameter['value'] = stripslashes( $parameter['value'] );
134 + $new_array[ sanitize_text_field( $parameter['name'] ) ] = $parameter['value'];
135 + }
136 + }
137 + }
138 +
139 + // look for array or json string and sort these out - for using such things in shortcode
140 + if( is_array( $new_array ) ) {
141 +
142 + foreach ( $new_array as $key => $value ) {
143 +
144 + // checking if the parameters have a json string
145 + if ( substr( $value, 0, 1 ) === '{' && substr( $value, -1 ) === '}' ) {
146 + $new_array[ $key ] = json_decode( $value, true);
147 + }
148 +
149 + // checking if the parameters have an array within the string
150 + // if they do, create them as an actual array
151 + if ( substr( $value, 0, 1 ) === '[' && substr( $value, -1 ) === ']' ) {
152 + $new_array[ $key ] = array( $value );
153 + }
154 +
155 + }
156 +
157 + }
158 +
159 + return $new_array;
160 +
180 161 }
181 162
182 -
183 163 /**
184 164 * Send the request and return our data
185 165 */
186 166 public function do_the_call() {
187 -
167 +
188 168 $this->init();
189 169
190 170 // build the URL
191 171 $this->final_url = apply_filters( 'wpgetapi_final_url', $this->build_url(), $this );
@@ -191,60 +171,28 @@
191 171 $this->final_url = apply_filters( 'wpgetapi_final_url', $this->build_url(), $this );
192 172
193 173 // build the request args
194 174 $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 175
201 - if ( apply_filters( 'wpgetapi_should_we_stop', false, $this ) ) {
202 - return;
203 - }
204 -
205 176 // POST request
206 177 if( $this->method == 'POST' )
207 178 $this->response = $this->POST_request();
208 179
209 - // PUT request
210 - if( $this->method == 'PUT' )
211 - $this->response = $this->PUT_request();
212 -
213 - // PATCH request
214 - if( $this->method == 'PATCH' )
215 - $this->response = $this->PATCH_request();
216 -
217 180 // GET request
218 181 if( $this->method == 'GET' )
219 182 $this->response = $this->GET_request();
220 183
221 - // DELETE request
222 - if( $this->method == 'DELETE' )
223 - $this->response = $this->DELETE_request();
224 -
225 184 // wp error
226 185 if( is_wp_error( $this->response ) ) {
227 - return apply_filters( 'wpgetapi_raw_error_data', json_encode( $this->response ), $this );
186 + return apply_filters( 'wpgetapi_raw_data', json_encode( $this->response ), $this );
228 187 }
229 188
230 - // get response_code
231 - $this->response_code = wp_remote_retrieve_response_code( $this->response );
189 + $data = wp_remote_retrieve_body( $this->response );
232 190
233 - // action to intercept call depending on response_code
234 - $this->response = apply_filters( 'wpgetapi_before_retrieve_body', $this->response, $this->response_code, $this );
235 -
236 - // get body
237 - // modified in version 1.6.1 to allow for OAuth 2.0 plugin returning body already
238 - $data = isset( $this->response['body'] ) ? $this->response['body'] : $this->response;
239 -
240 191 // returning in JSON format
241 192 if( $this->results_format == 'json_string' || $this->results_format == 'json_decoded' )
242 - $data = $this->return_data( $data );
193 + $data = $this->output_json( $data );
243 194
244 - if( $data === 'null' )
245 - $data = 'Result is null. Check that all endpoint settings are correct.';
246 -
247 195 return apply_filters( 'wpgetapi_raw_data', $data, $this );
248 196
249 197 }
250 198
@@ -257,33 +205,15 @@
257 205 // first make sure our endpoint starts with a slash
258 206 if ( substr( $this->endpoint, 0, 1 ) != '/' )
259 207 $this->endpoint = '/' . $this->endpoint;
260 208
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 209 $url = untrailingslashit( $this->base_url ) . $this->endpoint;
270 210
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 - // filter our params - added for use in Oauth 2.0 plugin
277 - $params = apply_filters( 'wpgetapi_query_parameters', $this->query_parameters, $this );
278 -
279 211 // add empty array - was getting errors if it was just null or false
280 - $params = empty( $params ) ? array(''=>'') : $params;
212 + $params = empty( $this->query_parameters ) ? array(''=>'') : $this->query_parameters;
281 213
282 - $result = add_query_arg( $params, $url );
214 + return add_query_arg( $params, $url );
283 215
284 - return $result;
285 -
286 216 }
287 217
288 218
289 219 /**
@@ -297,63 +227,21 @@
297 227 ), $this );
298 228
299 229
300 230 // 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
231 + if( $this->method == 'POST' ) {
232 +
304 233 $this->body_parameters = apply_filters( 'wpgetapi_body_parameters', $this->body_parameters, $this );
305 234
306 - // do we json_encode the entire body
307 - if( $this->body_json_encode == true ) {
235 + // do we json_encode the entire body as a string
236 + if( $this->body_json_encode === true || $this->body_json_encode === 'true' )
308 237 $this->body_parameters = json_encode( $this->body_parameters );
309 - }
310 238
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 );
320 - }
321 -
322 - $this->body_parameters = http_build_query( $this->body_parameters, '', '&' );
239 + // add our body parameters
240 + $headers['headers']['body'] = $this->body_parameters;
323 241
324 - }
325 -
326 - // do we xml the entire body
327 - if( $this->body_parameters && $this->body_xml_format == true ) {
328 -
329 - $xml = new SimpleXmlElement( '<' . $this->xml_root_node . '/>' );
330 -
331 - foreach( $this->body_parameters as $key => $value) {
332 - $xml->addChild( $key, $value );
333 - }
334 -
335 - $this->body_parameters = $xml->asXML();
336 -
337 - }
338 -
339 - // do we base64 encode the entire body
340 - if( $this->body_parameters && $this->body_base64_encode == true ) {
341 -
342 - $this->body_parameters = is_array( $this->body_parameters ) ? json_encode( $this->body_parameters ) : $this->body_parameters;
343 - $this->body_parameters = base64_encode( $this->body_parameters );
344 -
345 - }
346 -
347 - // add our body parameters
348 - if( $this->body_parameters && ! empty( $this->body_parameters ) )
349 - $headers['body'] = $this->body_parameters;
350 -
351 242 }
352 243
353 - // get our body paramters as they are formatted
354 - $this->body_parameters = apply_filters( 'wpgetapi_final_body_parameters', $this->body_parameters, $this );
355 -
356 244 // add headers to our final request args
357 245 $this->final_request_args = wp_parse_args( $headers, $this->final_request_args );
358 246
359 247 // build the args taht are sent to the request
@@ -369,10 +257,8 @@
369 257
370 258 }
371 259
372 260
373 -
374 -
375 261 /**
376 262 * Do a GET request
377 263 */
378 264 public function GET_request() {
@@ -378,9 +264,8 @@
378 264 public function GET_request() {
379 265 $response = '';
380 266 // so we can so something before the remote_get (caching)
381 267 $response = apply_filters( 'wpgetapi_before_get_request', $response, $this );
382 -
383 268 if( empty( $response ) )
384 269 $response = wp_remote_get( $this->final_url, $this->final_request_args );
385 270
386 271 return $response;
@@ -385,165 +270,36 @@
385 270
386 271 return $response;
387 272 }
388 273
274 +
389 275 /**
390 276 * Do a POST request
391 277 */
392 278 public function POST_request() {
393 - $this->final_request_args['method'] = 'POST';
394 279 $response = wp_remote_post( $this->final_url, $this->final_request_args );
395 280 return $response;
396 281 }
397 282
398 - /**
399 - * Do a PUT request
400 - */
401 - public function PUT_request() {
402 - $this->final_request_args['method'] = 'PUT';
403 - $response = wp_remote_request( $this->final_url, $this->final_request_args );
404 - return $response;
405 - }
406 283
407 284 /**
408 - * Do a PATCH request
285 + * return JSON data
409 286 */
410 - public function PATCH_request() {
411 - $this->final_request_args['method'] = 'PATCH';
412 - $response = wp_remote_request( $this->final_url, $this->final_request_args );
413 - return $response;
414 - }
287 + public function output_json( $data ) {
415 288
416 - /**
417 - * Do a DELETE request
418 - */
419 - public function DELETE_request() {
420 - $this->final_request_args['method'] = 'DELETE';
421 - $response = wp_remote_request( $this->final_url, $this->final_request_args );
422 - return $response;
423 - }
424 -
425 -
426 - /**
427 - * return data
428 - */
429 - public function return_data( $data ) {
430 -
431 - $data = apply_filters( 'wpgetapi_json_response_body_before_decode', $data, $this->keys );
432 -
433 289 // converts all data to arrays, removing objects
434 - if( is_string( $data ) ) {
435 - $decode = json_decode( $data, true );
436 - if( json_last_error() ) {
437 - return esc_html( $data );
438 - } else {
439 - $data = $decode;
440 - }
441 - }
290 + $data = json_decode( $data, true );
291 + $data = apply_filters( 'wpgetapi_json_response_body', $data, $this->keys );
442 292
443 - $data = apply_filters( 'wpgetapi_json_response_body', $data, $this->keys );
444 -
445 293 if( $this->results_format == 'json_string' )
446 - return trim( json_encode( $data, JSON_PRETTY_PRINT ),'"');
447 -
294 + return trim( json_encode( $data ),'"');
295 +
448 296 if( $this->results_format == 'json_decoded' )
449 297 return $data;
450 298
451 299 }
452 300
453 - /**
454 - * Sort out the parameters if they exist
455 - */
456 - public function do_parameters( $parameters ) {
457 301
458 - $new_array = array();
459 - $raw = '';
460 - $parameters = $this->decrypt( $parameters );
461 -
462 - if( is_array( $parameters ) ) {
463 - foreach ( $parameters as $key => $parameter ) {
464 -
465 - if( ! empty( $parameter['name'] ) && ! empty( $parameter['value'] ) ) {
466 -
467 - $parameter['value'] = stripslashes( $parameter['value'] );
468 -
469 - // if we have wpgetapi_on, delete it so we don't send to api
470 - if( $parameter['name'] == 'wpgetapi_on' ) {
471 - unset( $parameters[ $key ] );
472 - continue;
473 - }
474 -
475 - // if we have item_key from api to posts plugin
476 - // replace our keyword with the actual item_key value
477 - if ( isset( $this->args['item_key'] ) && strpos( $parameter['value'], '(importer:item_key)' ) !== false ) {
478 - $parameter['value'] = str_replace( '(importer:item_key)', $this->args['item_key'], $parameter['value'] );
479 - }
480 -
481 - $new_array[ sanitize_text_field( $parameter['name'] ) ] = $parameter['value'];
482 -
483 - // if we are sending raw body
484 - } else if( empty( $parameter['name'] ) && ! empty( $parameter['value'] ) ) {
485 -
486 - $raw = stripslashes( $parameter['value'] );
487 -
488 - }
489 -
490 - }
491 - }
492 -
493 - // now look for array or json string and sort these out - for using such things in shortcode
494 - if( ! empty( $new_array ) ) {
495 -
496 - foreach ( $new_array as $key => $value ) {
497 -
498 - // checking if the parameters have a json string
499 - if ( strpos( $value, '{"' ) !== false && strpos( $value, '}' ) !== false ) {
500 - //if ( substr( $value, 0, 1 ) === '{' && substr( $value, -1 ) === '}' ) {
501 - $new_array[ $key ] = json_decode( $value, true );
502 - } else
503 -
504 - // checking if the parameters have an array within the string
505 - // if they do, create them as an actual array
506 - if ( substr( $value, 0, 1 ) === '[' && substr( $value, -1 ) === ']' ) {
507 - $value = trim( $value,"[]" );
508 - $new_array[ $key ] = array( $value );
509 - }
510 -
511 - // set value as integer
512 - if ( strpos( $value, 'integer(' ) !== false && substr( $value, -1 ) === ')' ) {
513 - preg_match("/\(([^\)]*)\)/", $value, $match );
514 - $result = $match[1];
515 - $new_array[ $key ] = absint( $result );
516 - }
517 -
518 - // set value as float
519 - if ( strpos( $value, 'float(' ) !== false && substr( $value, -1 ) === ')' ) {
520 - preg_match("/\(([^\)]*)\)/", $value, $match );
521 - $result = $match[1];
522 - if ( substr( $result, 0, 1 ) === '"' && substr( $result, -1 ) === '"' )
523 - $result = trim( $result,'""' );
524 - $new_array[ $key ] = (float) $result;
525 -
526 - }
527 -
528 - // set value as boolean
529 - if ( strpos( $value, 'boolean(' ) !== false && substr( $value, -1 ) === ')' ) {
530 - preg_match("/\(([^\)]*)\)/", $value, $match );
531 - $result = $match[1];
532 - $result = filter_var( $result, FILTER_VALIDATE_BOOLEAN );
533 - $new_array[ $key ] = $result;
534 -
535 - }
536 -
537 - }
538 -
539 - }
540 -
541 - return $raw ? $raw : $new_array;
542 -
543 - }
544 -
545 -
546 302 /**
547 303 * decrypt our parameters from the DB
548 304 */
549 305 public function decrypt( $array_or_string ) {
@@ -569,86 +325,20 @@
569 325
570 326 /**
571 327 * debug
572 328 */
573 - public function maybe_add_debug_info( $data, $wpgetapi ) {
329 + public function maybe_add_debug_info( $data, $this_data ) {
574 330
575 - if(
576 - ( isset( $this->args['debug'] ) && ( $this->args['debug'] === true || $this->args['debug'] === 'true' ) ) ||
577 - ( isset( $this->args['test_endpoint'] ) && ( $this->args['test_endpoint'] === true ) )
578 - ) {
331 + if( isset( $this->args['debug'] ) && ( $this->args['debug'] === true || $this->args['debug'] === 'true' ) ) {
579 332
580 - $this->debug = true;
581 -
582 - // admin test endpoint button
583 - $testing = isset( $this->args['test_endpoint'] ) && ( $this->args['test_endpoint'] === true ) ? true : false;
584 -
585 - // get api status from response code
586 - $status = array(
587 - 'title' => 'Error in API response.',
588 - 'desc' => 'Check all details within your endpoint. Something is misconfigured.',
589 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
590 - );
591 -
592 - if( $this->response_code >= 200 && $this->response_code <= 299 ) {
593 - $status = array(
594 - 'title' => 'Success!',
595 - '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.',
596 - 'type' => '<span class="dashicons dashicons-yes-alt"></span>'
597 - );
598 - }
599 - if( $this->response_code >= 400 && $this->response_code <= 499 ) {
600 - $status = array(
601 - 'title' => 'Bad Request',
602 - '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.',
603 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
604 - );
605 - }
606 - if( $this->response_code == 401 ) {
607 - $status = array(
608 - 'title' => 'Unauthorised',
609 - '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.',
610 - 'type' => '<span class="dashicons dashicons-warning"></span>'
611 - );
612 - }
613 - if( $this->response_code == 403 ) {
614 - $status = array(
615 - 'title' => 'Forbidden',
616 - '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.',
617 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
618 - );
619 - }
620 - if( $this->response_code == 405 ) {
621 - $status = array(
622 - 'title' => 'Method Not Allowed',
623 - 'desc' => 'Try changing the Request Method within the endpoint settings.',
624 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
625 - );
626 - }
627 - if( $this->response_code == 415 ) {
628 - $status = array(
629 - 'title' => 'Unsupported Media Type',
630 - '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>.',
631 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
632 - );
633 - }
634 - if( $this->response_code >= 500 && $this->response_code <= 599 ) {
635 - $status = array(
636 - 'title' => 'Internal Server Error',
637 - 'desc' => 'This indicates an issue with the API server. Contact your API provider.',
638 - 'type' => '<span class="dashicons dashicons-dismiss"></span>'
639 - );
640 - }
641 -
642 -
643 333 ob_start(); ?>
644 334
645 335 <style>
646 336
647 337 .wpgetapi-debug {
648 - background: #fff;
338 + background: #f4f4f4;
649 339 padding: 20px;
650 - box-shadow: 0 0 1px #aaa;
340 + border: 1px solid #ccc;
651 341 margin: 20px;
652 342 font-size: 15px;
653 343 }
654 344 .wpgetapi-debug
@@ -663,9 +353,9 @@
663 353 }
664 354 .wpgetapi-debug p.small {
665 355 font-size: 85%;
666 356 color: #999;
667 - margin: 0 0 12px !important;
357 + margin-bottom: 15px !important
668 358 }
669 359 .wpgetapi-debug h5 {
670 360 font-weight: bold;
671 361 font-size: 18px;
@@ -675,154 +365,86 @@
675 365 .wpgetapi-debug .debug-item {
676 366 margin: 10px 0;
677 367 background: #fff;
678 368 padding: 15px 20px;
679 - display: inline-block !important;
369 + display: inline-block !important;;
680 370 width: 100% !important;
681 - box-shadow: 0 3px 8px rgb(0 0 0 / 6%);
682 - border: 1px solid #eee;
371 + box-shadow: 0 0 5px rgba(0,0,0,0.1)
683 372 }
684 373 .wpgetapi-debug .debug-item h6 {
685 374 font-weight: bold;
686 - font-size: 14px;
687 - margin: 0;
375 + font-size: 16px;
376 + margin: 0 0 3px;
688 377 text-transform: none !important;
689 378 }
690 379 .wpgetapi-debug .debug-item .debug-result,
691 380 .wpgetapi-debug .debug-item .debug-result pre {
692 381 font-family: monospace !important;
693 - font-size: 13px !important;
382 + font-size: 15px !important;
694 383 margin: 0 !important;
695 - padding: 8px 12px;
696 - background: #f4f7f9;
384 + padding: 10px 12px;
385 + background: #f8f8f8;
697 386 }
698 387 .wpgetapi-debug .debug-item .debug-result pre {
699 388 border: none;
700 389 padding: 5px
701 390 }
702 -.wpgetapi-debug.testing {
703 - background: transparent;
704 - padding: 0;
705 - box-shadow: none;
706 -}
707 -.wpgetapi-debug.testing .debug-item {
708 - margin: 5px 0;
709 -}
710 -.wpgetapi-debug.testing .debug-item.status {
711 - border: none;
712 - box-shadow: none;
713 - margin-bottom: 15px;
714 -}
715 -.wpgetapi-debug .debug-item.status h5 {
716 - font-size: 15px;
717 -}
718 -.wpgetapi-debug .status .dashicons {
719 - margin: 0 5px 3px 0;
720 -}
721 -.wpgetapi-debug .status .dashicons-yes-alt {
722 - color: #5e9929;
723 -}
724 -.wpgetapi-debug .status .dashicons-dismiss {
725 - color: #cc4646;
726 -}
727 -.wpgetapi-debug .status .dashicons-warning {
728 - color: #dfa12e;
729 -}
730 -.wpgetapi-debug .status .desc {
731 - font-size: 14px;
732 - font-weight: 400 !important;
733 -}
391 +
734 392 </style>
735 393
736 - <div class="wpgetapi-debug <?php echo $testing ? 'testing' : ''; ?>">
394 + <div class="wpgetapi-debug">
737 395
738 - <?php if( $testing ) { ?>
396 + <h5><strong>WPGetAPI, Debug Mode - Plugin Version <?php esc_html_e( WpGetApi()->version ); ?></strong></h5>
397 + <p class="small">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.<br>Connecting to API's can be tricky - if you require help, please see the <a target="_blank" href="https://wpgetapi.com/docs/">Documentation</a> and if you can't find the answer then please use the contact form on our <a target="_blank" title="Connect WordPress with external API" href="https://wpgetapi.com/">website</a> to get assistance.</p>
739 398
740 - <div class="debug-item status">
741 - <div class="">
742 - <h5><?php _e( $status['type'] ); ?> <?php esc_html_e( $status['title'] ); ?></h5>
743 - <span class="desc"><?php _e( $status['desc'] ); ?></span>
744 - </div>
745 - </div>
746 - <div class="debug-item">
747 - <h6><?php esc_html_e( 'Full URL', 'wpgetapi' ); ?></h6>
748 - <p class="small"><?php esc_html_e( 'The full URL that is being called.', 'wpgetapi' ); ?></p>
749 - <div class="debug-result"><?php esc_html_e( $this->final_url ); ?></div>
750 - </div>
751 -
752 - <div class="debug-item">
753 - <h6><?php esc_html_e( 'Data Output', 'wpgetapi' ); ?></h6>
754 - <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>
755 - <div class="debug-result"><?php wpgetapi_pp( $data ); ?></div>
756 - </div>
757 -
758 - <div class="debug-item">
759 - <h6><?php esc_html_e( 'Final Request Arguments', 'wpgetapi' ); ?></h6>
760 - <p class="small"><?php esc_html_e( 'The final request arguments sent in the API request. Includes headers and body arguments.', 'wpgetapi' ); ?></p>
761 - <div class="debug-result"><?php wpgetapi_pp( $this->final_request_args ); ?></div>
762 - </div>
763 -
764 - <div class="debug-item">
765 - <h6><?php esc_html_e( 'Response', 'wpgetapi' ); ?></h6>
766 - <p class="small"><?php esc_html_e( 'The full response from the API request.', 'wpgetapi' ); ?></p>
767 - <div class="debug-result"><?php wpgetapi_pp( $this->response); ?></div>
768 - </div>
769 -
770 - <?php } else { ?>
771 -
772 - <h5><strong><?php esc_html_e( 'WPGetAPI, Debug Mode - Plugin Version', 'wpgetapi' ); ?> <?php esc_html_e( WpGetApi()->version ); ?></strong></h5>
773 - <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>
774 -
775 399 <div class="debug-item">
776 - <h6><?php esc_html_e( 'Full URL', 'wpgetapi' ); ?></h6>
777 - <p class="small"><?php esc_html_e( 'The full URL that is being called.', 'wpgetapi' ); ?></p>
400 + <h6>Full URL</h6>
401 + <p class="small">The full URL that is being called.</p>
778 402 <div class="debug-result"><?php esc_html_e( $this->final_url ); ?></div>
779 403 </div>
780 404
781 405 <div class="debug-item">
782 - <h6><?php esc_html_e( 'Data Output', 'wpgetapi' ); ?></h6>
783 - <p class="small"><?php esc_html_e( 'The resulting output that has been returned from the API.', 'wpgetapi' ); ?></p>
406 + <h6>Data Output</h6>
407 + <p class="small">The resulting output that has been returned from the API.</p>
784 408 <div class="debug-result"><?php wpgetapi_pp( $data ); ?></div>
785 409 </div>
786 410
787 411 <div class="debug-item">
788 - <h6><?php esc_html_e( 'Query String', 'wpgetapi' ); ?></h6>
789 - <p class="small"><?php esc_html_e( 'The query string parameters (if any) that you have set within the endpoint settings.', 'wpgetapi' ); ?></p>
412 + <h6>Arguments</h6>
413 + <p class="small">The arguments set within your shortcode or template tag.</p>
414 + <div class="debug-result"><?php wpgetapi_pp( $this->args ); ?></div>
415 + </div>
416 +
417 + <div class="debug-item">
418 + <h6>Query String</h6>
419 + <p class="small">The query string parameters (if any) that you have set within the endpoint settings.</p>
790 420 <div class="debug-result"><?php wpgetapi_pp( $this->query_parameters ); ?></div>
791 421 </div>
792 422
793 423 <div class="debug-item">
794 - <h6><?php esc_html_e( 'Headers', 'wpgetapi' ); ?></h6>
795 - <p class="small"><?php esc_html_e( 'The header parameters (if any) that you have set within the endpoint settings.', 'wpgetapi' ); ?></p>
424 + <h6>Headers</h6>
425 + <p class="small">The headers parameters (if any) that you have set within the endpoint settings.</p>
796 426 <div class="debug-result"><?php wpgetapi_pp( $this->header_parameters ); ?></div>
797 427 </div>
798 428
799 429 <div class="debug-item">
800 - <h6><?php esc_html_e( 'Body', 'wpgetapi' ); ?></h6>
801 - <p class="small"><?php esc_html_e( 'The body parameters (if any) that you have set within the endpoint settings.', 'wpgetapi' ); ?></p>
430 + <h6>Body</h6>
431 + <p class="small">The body parameters (if any) that you have set within the endpoint settings.</p>
802 432 <div class="debug-result"><?php wpgetapi_pp( $this->body_parameters ); ?></div>
803 433 </div>
804 434
805 435 <div class="debug-item">
806 - <h6><?php esc_html_e( 'Final Request Arguments', 'wpgetapi' ); ?></h6>
807 - <p class="small"><?php esc_html_e( 'The final request arguments sent in the API request. Includes headers and body arguments.', 'wpgetapi' ); ?></p>
436 + <h6>Final Request Arguments</h6>
437 + <p class="small">The final request arguments sent in the API request. Includes headers and body arguments.</p>
808 438 <div class="debug-result"><?php wpgetapi_pp( $this->final_request_args ); ?></div>
809 439 </div>
810 440
811 441 <div class="debug-item">
812 - <h6><?php esc_html_e( 'Arguments', 'wpgetapi' ); ?></h6>
813 - <p class="small"><?php esc_html_e( 'The arguments set within your shortcode or template tag.', 'wpgetapi' ); ?></p>
814 - <div class="debug-result"><?php wpgetapi_pp( $this->args ); ?></div>
815 - </div>
816 -
817 - <div class="debug-item">
818 - <h6><?php esc_html_e( 'Response', 'wpgetapi' ); ?></h6>
819 - <p class="small"><?php esc_html_e( 'The full response from the API request.', 'wpgetapi' ); ?></p>
442 + <h6>Response</h6>
443 + <p class="small">The full response from the API request.</p>
820 444 <div class="debug-result"><?php wpgetapi_pp( $this->response); ?></div>
821 445 </div>
822 446
823 - <?php } ?>
824 -
825 447 </div>
826 448
827 449 <?php
828 450
@@ -832,9 +454,11 @@
832 454
833 455 return $data;
834 456
835 457 }
458 +
459 +
836 460
837 461 }
838 462
839 463
840 464 }