| 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 |
), $atts ); |
| 29 |
|
| 30 |
if( ! isset( $a['api_id'] ) || $a['api_id'] == '' ) |
| 31 |
return 'api_id shortcode attribute is not set.'; |
| 32 |
|
| 33 |
if( ! isset( $a['endpoint_id'] ) || $a['endpoint_id'] == '' ) |
| 34 |
return 'endpoint_id shortcode attribute is not set.'; |
| 35 |
|
| 36 |
$a['args']['debug'] = $a['debug']; |
| 37 |
|
| 38 |
if( ! empty( $a['keys'] ) ) { |
| 39 |
// Create our array of values for keys |
| 40 |
// First, sanitize the data and remove white spaces |
| 41 |
$no_whitespaces_keys = preg_replace( '/\s*,\s*/', ',', filter_var( $a['keys'], FILTER_SANITIZE_STRING ) ); |
| 42 |
$a['keys'] = explode( ',', $no_whitespaces_keys ); |
| 43 |
} |
| 44 |
|
| 45 |
return wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );; |
| 46 |
|
| 47 |
} |
| 48 |
add_shortcode( 'wpgetapi_endpoint', 'wpgetapi_endpoint_shortcode' ); |