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