endpoint_output(); } /** * Return the endpoint data via shortcode */ function wpgetapi_endpoint_shortcode( $atts = array() ) { $a = shortcode_atts( array( 'api_id' => '', 'endpoint_id' => '', 'debug' => false, 'args' => array(), 'keys' => array(), 'endpoint_variables' => array(), 'query_variables' => array(), 'body_variables' => array(), 'format' => '', 'html_tag' => 'div', 'html_labels' => 'false', 'html_url' => '', 'html_to_link' => '', 'img_key' => '', 'img_prepend' => '', 'img_link' => '', 'on' => '', 'button_text' => '', 'hide_button' => '', 'button_spinner' => '', 'button_id' => '', 'ajax_output' => '.wpgetapi_ajax_output', 'chain' => '', 'chain_delay' => '0', ), $atts ); if( ! isset( $a['api_id'] ) || $a['api_id'] == '' ) return __( 'api_id shortcode attribute is not set.', 'wpgetapi' ); if( ! isset( $a['endpoint_id'] ) || $a['endpoint_id'] == '' ) return __( 'endpoint_id shortcode attribute is not set.', 'wpgetapi' ); // sort out our keys if using them if( ! empty( $a['keys'] ) ) { // Create our array of values for keys // First, sanitize the data and remove white spaces $no_whitespaces_keys = preg_replace( '/\s*,\s*/', ',', filter_var( $a['keys'], FILTER_SANITIZE_STRING ) ); $a['keys'] = explode( ',', $no_whitespaces_keys ); } // sort out our endpoint_variables if using them if( ! empty( $a['endpoint_variables'] ) ) { // Create our array of values for endpoint_variables // First, sanitize the data and remove white spaces $no_whitespaces_vars = preg_replace( '/\s*,\s*/', ',', filter_var( $a['endpoint_variables'], FILTER_SANITIZE_STRING ) ); $a['endpoint_variables'] = explode( ',', $no_whitespaces_vars ); } // add our shortcode args to the actual 'args' within the endpoint call $a['args']['debug'] = $a['debug']; $a['args']['endpoint_variables'] = $a['endpoint_variables']; $a['args']['query_variables'] = $a['query_variables']; $a['args']['body_variables'] = $a['body_variables']; $a['args']['format'] = $a['format']; $a['args']['html_tag'] = $a['html_tag']; $a['args']['html_labels'] = $a['html_labels']; $a['args']['html_url'] = $a['html_url']; $a['args']['html_to_link'] = $a['html_to_link']; $a['args']['img_key'] = $a['img_key']; $a['args']['img_prepend'] = $a['img_prepend']; $a['args']['img_link'] = $a['img_link']; $a['args']['shortcode'] = true; $a['args']['on'] = $a['on']; $a['args']['button_text'] = $a['button_text']; $a['args']['hide_button'] = $a['hide_button']; $a['args']['button_spinner'] = $a['button_spinner']; $a['args']['button_id'] = $a['button_id']; $a['args']['ajax_output'] = $a['ajax_output']; $a['args']['chain'] = $a['chain']; $a['args']['chain_delay'] = $a['chain_delay']; // if we are doing ajax if( isset( $a['args']['on'] ) && $a['args']['on'] == 'ajax' && ! wp_doing_ajax() ) { if( class_exists( 'WpGetApi_Extras_Extend' ) ) { add_action( 'wp_footer', array( 'WpGetApi_Extras_Extend', 'ajax_function' ) ); $button_text = isset( $a['args']['button_text'] ) && $a['args']['button_text'] != '' ? $a['args']['button_text'] : 'Call API'; ob_start(); ?>