PluginProbe
WPGet API – Connect to any external REST API / 1.4.9
WPGet API – Connect to any external REST API v1.4.9
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.9, at frontend/functions.php

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