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
wpgetapi / frontend / functions.php

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

64 lines 2.0 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(), // not fully tested
29 'query_variables' => array(),
30 ), $atts );
31
32 if( ! isset( $a['api_id'] ) || $a['api_id'] == '' )
33 return 'api_id shortcode attribute is not set.';
34
35 if( ! isset( $a['endpoint_id'] ) || $a['endpoint_id'] == '' )
36 return 'endpoint_id shortcode attribute is not set.';
37
38 // sort out our keys if using them
39 if( ! empty( $a['keys'] ) ) {
40 // Create our array of values for keys
41 // First, sanitize the data and remove white spaces
42 $no_whitespaces_keys = preg_replace( '/\s*,\s*/', ',', filter_var( $a['keys'], FILTER_SANITIZE_STRING ) );
43 $a['keys'] = explode( ',', $no_whitespaces_keys );
44 }
45
46 // sort out our endpoint_variables if using them
47 if( ! empty( $a['endpoint_variables'] ) ) {
48 // Create our array of values for endpoint_variables
49 // First, sanitize the data and remove white spaces
50 $no_whitespaces_vars = preg_replace( '/\s*,\s*/', ',', filter_var( $a['endpoint_variables'], FILTER_SANITIZE_STRING ) );
51 $a['endpoint_variables'] = explode( ',', $no_whitespaces_vars );
52 }
53
54 // add our shortcode args to the actual 'args' within the endpoint call
55 $a['args']['debug'] = $a['debug'];
56 $a['args']['endpoint_variables'] = $a['endpoint_variables'];
57 $a['args']['query_variables'] = $a['query_variables'];
58 $a['args']['shortcode'] = true;
59
60 return wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
61
62 }
63 add_shortcode( 'wpgetapi_endpoint', 'wpgetapi_endpoint_shortcode' );
64