| @@ -26,9 +26,8 @@ | ||
| 26 | 26 | 'args' => array(), |
| 27 | 27 | 'keys' => array(), |
| 28 | 28 | 'endpoint_variables' => array(), |
| 29 | 29 | 'query_variables' => array(), |
| 30 | - 'body_variables' => array(), | |
| 31 | 30 | 'format' => '', |
| 32 | 31 | 'html_tag' => 'div', |
| 33 | 32 | 'html_labels' => 'false', |
| 34 | 33 | 'html_url' => '', |
| @@ -34,17 +33,13 @@ | ||
| 34 | 33 | 'html_url' => '', |
| 35 | 34 | 'html_to_link' => '', |
| 36 | 35 | 'img_key' => '', |
| 37 | 36 | 'img_prepend' => '', |
| 38 | - 'img_link' => '', | |
| 39 | 37 | 'on' => '', |
| 40 | 38 | 'button_text' => '', |
| 41 | 39 | 'hide_button' => '', |
| 42 | 40 | 'button_spinner' => '', |
| 43 | - 'button_id' => '', | |
| 44 | - 'ajax_output' => '.wpgetapi_ajax_output', | |
| 45 | 41 | 'chain' => '', |
| 46 | - 'chain_delay' => '0', | |
| 47 | 42 | ), $atts ); |
| 48 | 43 | |
| 49 | 44 | if( ! isset( $a['api_id'] ) || $a['api_id'] == '' ) |
| 50 | 45 | return __( 'api_id shortcode attribute is not set.', 'wpgetapi' ); |
| @@ -73,9 +68,8 @@ | ||
| 73 | 68 | // add our shortcode args to the actual 'args' within the endpoint call |
| 74 | 69 | $a['args']['debug'] = $a['debug']; |
| 75 | 70 | $a['args']['endpoint_variables'] = $a['endpoint_variables']; |
| 76 | 71 | $a['args']['query_variables'] = $a['query_variables']; |
| 77 | - $a['args']['body_variables'] = $a['body_variables']; | |
| 78 | 72 | $a['args']['format'] = $a['format']; |
| 79 | 73 | $a['args']['html_tag'] = $a['html_tag']; |
| 80 | 74 | $a['args']['html_labels'] = $a['html_labels']; |
| 81 | 75 | $a['args']['html_url'] = $a['html_url']; |
| @@ -81,18 +75,14 @@ | ||
| 81 | 75 | $a['args']['html_url'] = $a['html_url']; |
| 82 | 76 | $a['args']['html_to_link'] = $a['html_to_link']; |
| 83 | 77 | $a['args']['img_key'] = $a['img_key']; |
| 84 | 78 | $a['args']['img_prepend'] = $a['img_prepend']; |
| 85 | - $a['args']['img_link'] = $a['img_link']; | |
| 86 | 79 | $a['args']['shortcode'] = true; |
| 87 | 80 | $a['args']['on'] = $a['on']; |
| 88 | 81 | $a['args']['button_text'] = $a['button_text']; |
| 89 | 82 | $a['args']['hide_button'] = $a['hide_button']; |
| 90 | 83 | $a['args']['button_spinner'] = $a['button_spinner']; |
| 91 | - $a['args']['button_id'] = $a['button_id']; | |
| 92 | - $a['args']['ajax_output'] = $a['ajax_output']; | |
| 93 | 84 | $a['args']['chain'] = $a['chain']; |
| 94 | - $a['args']['chain_delay'] = $a['chain_delay']; | |
| 95 | 85 | |
| 96 | 86 | |
| 97 | 87 | // if we are doing ajax |
| 98 | 88 | if( isset( $a['args']['on'] ) && $a['args']['on'] == 'ajax' && ! wp_doing_ajax() ) { |
| @@ -104,23 +94,17 @@ | ||
| 104 | 94 | $button_text = isset( $a['args']['button_text'] ) && $a['args']['button_text'] != '' ? $a['args']['button_text'] : 'Call API'; |
| 105 | 95 | |
| 106 | 96 | ob_start(); ?> |
| 107 | 97 | |
| 108 | - <div class="wpgetapi_ajax_wrap" data-id="<?php esc_html_e( $a['api_id'] ); ?>-<?php esc_html_e( $a['endpoint_id'] ); ?>"> | |
| 109 | - <button | |
| 110 | - class="button btn btn-primary wpgetapi_ajax_request" | |
| 111 | - id="<?php esc_html_e( $a['button_id'] ); ?>" | |
| 112 | - data-api="<?php esc_html_e( $a['api_id'] ); ?>" | |
| 113 | - data-endpoint="<?php esc_html_e( $a['endpoint_id'] ); ?>" | |
| 114 | - data-args="<?php esc_html_e( json_encode( $a['args'] ) ); ?>" | |
| 115 | - data-keys="<?php esc_html_e( json_encode( $a['keys'] ) ); ?>" | |
| 116 | - data-post_id="<?php esc_html_e( get_the_ID() ); ?>"> | |
| 117 | - <span class="button_text"><?php esc_html_e( $button_text ); ?></span> | |
| 118 | - </button> | |
| 119 | - | |
| 120 | - <div class="wpgetapi_ajax_output"></div> | |
| 121 | - | |
| 122 | - </div> | |
| 98 | + <button | |
| 99 | + class="button btn btn-primary wpgetapi_ajax_request" | |
| 100 | + data-api="<?php esc_html_e( $a['api_id'] ); ?>" | |
| 101 | + data-endpoint="<?php esc_html_e( $a['endpoint_id'] ); ?>" | |
| 102 | + data-args="<?php esc_html_e( json_encode( $a['args'] ) ); ?>" | |
| 103 | + data-keys="<?php esc_html_e( json_encode( $a['keys'] ) ); ?>"> | |
| 104 | + <span class="button_text"><?php esc_html_e( $button_text ); ?></span> | |
| 105 | + </button> | |
| 106 | + <div class="wpgetapi_ajax_output"></div> | |
| 123 | 107 | |
| 124 | 108 | <?php |
| 125 | 109 | $result = ob_get_contents(); |
| 126 | 110 | ob_end_clean(); |
| @@ -132,23 +116,22 @@ | ||
| 132 | 116 | } |
| 133 | 117 | |
| 134 | 118 | } else { |
| 135 | 119 | |
| 120 | + // [wpgetapi_endpoint api_id='livelearn' endpoint_id='dezzp1' chain='start' keys='UUID'] | |
| 121 | + // [wpgetapi_endpoint api_id='livelearn' endpoint_id='dezzp2' chain='end'] | |
| 122 | + | |
| 136 | 123 | // if we are starting the chain |
| 137 | - if( ! empty( $a['args']['chain'] ) ) { | |
| 124 | + if( isset( $a['args']['chain'] ) ) { | |
| 138 | 125 | |
| 139 | - $delay = absint( $a['args']['chain_delay'] ); | |
| 140 | - | |
| 141 | 126 | // get our result from this chain |
| 142 | 127 | $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] ); |
| 143 | 128 | |
| 144 | - if( $delay > 0 && ! is_admin() ) | |
| 145 | - sleep( $delay ); | |
| 146 | - | |
| 147 | 129 | // set the transient for this chain if not the last chain |
| 148 | 130 | if( $a['args']['chain'] !== 'end' ) |
| 149 | - set_transient( 'wpgetapi_chain_' . sanitize_text_field( $a['args']['chain'] ), $result, $delay + 10 ); | |
| 131 | + set_transient( 'wpgetapi_chain_' . sanitize_text_field( $a['args']['chain'] ), $result, 10 ); | |
| 150 | 132 | |
| 133 | + | |
| 151 | 134 | } else { |
| 152 | 135 | |
| 153 | 136 | // do our standard return |
| 154 | 137 | $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] ); |
| @@ -154,14 +137,17 @@ | ||
| 154 | 137 | $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] ); |
| 155 | 138 | |
| 156 | 139 | } |
| 157 | 140 | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 158 | 144 | } |
| 159 | 145 | |
| 160 | 146 | if( is_array( $result ) ) { |
| 161 | 147 | $result = sprintf( |
| 162 | 148 | __( 'The <b>Results Format</b> for this endpoint is set to \'PHP array data\' - shortcodes are unable to output this type of data.<br>Please change the Results Format to \'JSON string\' in the endpoint settings page.<br>Alternatively, please see our tutorial on %1s.', 'wpgetapi' ), |
| 163 | - '<a target="_blank" href="https://wpgetapi.com/docs/format-api-data-as-html/?utm_campaign=Shortcode JSON&utm_medium=Admin&utm_source=User">how to format your API data as HTML</a>.' | |
| 149 | + '<a target="_blank" href="https://wpgetapi.com/docs/format-api-data-as-html/?utm_campaign=Shortcode JSON&utm_medium=Admin&utm_source=User">how to format your API data as HTML</a>' | |
| 164 | 150 | ); |
| 165 | 151 | } |
| 166 | 152 | |
| 167 | 153 | if( $a['args']['format'] !== 'no_display' ) |