PluginProbe
WPGet API – Connect to any external REST API / 1.7.0
WPGet API – Connect to any external REST API v1.7.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
wpgetapi / frontend / functions.php

functions.php in WPGet API – Connect to any external REST API 1.7.0, at frontend/functions.php

70 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Return the endpoint data
5 */
6 function wpgetapi_endpoint( $api_id = '', $endpoint_id = '', $args = array(), $keys = array() ) {
7
8 if( ! $api_id || ! $endpoint_id )
9 return false;
10
11 $api = new WpGetApi_Api( $api_id, $endpoint_id, $args, $keys );
12
13 return $api->endpoint_output();
14
15 }
16
17 /**
18 * Return the endpoint data via shortcode
19 */
20 function wpgetapi_endpoint_shortcode( $atts = array() ) {
21
22 $a = shortcode_atts( array(
23 'api_id' => '',
24 'endpoint_id' => '',
25 'debug' => false,
26 'args' => array(),
27 'keys' => array(),
28 'endpoint_variables' => array(),
29 'query_variables' => array(),
30 'format' => '',
31 'html_tag' => 'div',
32 'html_labels' => 'false',
33 ), $atts );
34
35 if( ! isset( $a['api_id'] ) || $a['api_id'] == '' )
36 return __( 'api_id shortcode attribute is not set.', 'wpgetapi' );
37
38 if( ! isset( $a['endpoint_id'] ) || $a['endpoint_id'] == '' )
39 return __( 'endpoint_id shortcode attribute is not set.', 'wpgetapi' );
40
41 // sort out our keys if using them
42 if( ! empty( $a['keys'] ) ) {
43 // Create our array of values for keys
44 // First, sanitize the data and remove white spaces
45 $no_whitespaces_keys = preg_replace( '/\s*,\s*/', ',', filter_var( $a['keys'], FILTER_SANITIZE_STRING ) );
46 $a['keys'] = explode( ',', $no_whitespaces_keys );
47 }
48
49 // sort out our endpoint_variables if using them
50 if( ! empty( $a['endpoint_variables'] ) ) {
51 // Create our array of values for endpoint_variables
52 // First, sanitize the data and remove white spaces
53 $no_whitespaces_vars = preg_replace( '/\s*,\s*/', ',', filter_var( $a['endpoint_variables'], FILTER_SANITIZE_STRING ) );
54 $a['endpoint_variables'] = explode( ',', $no_whitespaces_vars );
55 }
56
57 // add our shortcode args to the actual 'args' within the endpoint call
58 $a['args']['debug'] = $a['debug'];
59 $a['args']['endpoint_variables'] = $a['endpoint_variables'];
60 $a['args']['query_variables'] = $a['query_variables'];
61 $a['args']['format'] = $a['format'];
62 $a['args']['html_tag'] = $a['html_tag'];
63 $a['args']['html_labels'] = $a['html_labels'];
64 $a['args']['shortcode'] = true;
65
66 return wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
67
68 }
69 add_shortcode( 'wpgetapi_endpoint', 'wpgetapi_endpoint_shortcode' );
70