PluginProbe
WPGet API – Connect to any external REST API / 1.8.9
WPGet API – Connect to any external REST API v1.8.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
← All changes | frontend/functions.php +15 -30 2.0.11.8.9 View file →
@@ -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' => '',
@@ -38,12 +37,9 @@
38 37 'on' => '',
39 38 'button_text' => '',
40 39 'hide_button' => '',
41 40 'button_spinner' => '',
42 - 'button_id' => '',
43 - 'ajax_output' => '.wpgetapi_ajax_output',
44 41 'chain' => '',
45 - 'chain_delay' => '0',
46 42 ), $atts );
47 43
48 44 if( ! isset( $a['api_id'] ) || $a['api_id'] == '' )
49 45 return __( 'api_id shortcode attribute is not set.', 'wpgetapi' );
@@ -72,9 +68,8 @@
72 68 // add our shortcode args to the actual 'args' within the endpoint call
73 69 $a['args']['debug'] = $a['debug'];
74 70 $a['args']['endpoint_variables'] = $a['endpoint_variables'];
75 71 $a['args']['query_variables'] = $a['query_variables'];
76 - $a['args']['body_variables'] = $a['body_variables'];
77 72 $a['args']['format'] = $a['format'];
78 73 $a['args']['html_tag'] = $a['html_tag'];
79 74 $a['args']['html_labels'] = $a['html_labels'];
80 75 $a['args']['html_url'] = $a['html_url'];
@@ -85,12 +80,9 @@
85 80 $a['args']['on'] = $a['on'];
86 81 $a['args']['button_text'] = $a['button_text'];
87 82 $a['args']['hide_button'] = $a['hide_button'];
88 83 $a['args']['button_spinner'] = $a['button_spinner'];
89 - $a['args']['button_id'] = $a['button_id'];
90 - $a['args']['ajax_output'] = $a['ajax_output'];
91 84 $a['args']['chain'] = $a['chain'];
92 - $a['args']['chain_delay'] = $a['chain_delay'];
93 85
94 86
95 87 // if we are doing ajax
96 88 if( isset( $a['args']['on'] ) && $a['args']['on'] == 'ajax' && ! wp_doing_ajax() ) {
@@ -102,23 +94,17 @@
102 94 $button_text = isset( $a['args']['button_text'] ) && $a['args']['button_text'] != '' ? $a['args']['button_text'] : 'Call API';
103 95
104 96 ob_start(); ?>
105 97
106 - <div class="wpgetapi_ajax_wrap" data-id="<?php esc_html_e( $a['api_id'] ); ?>-<?php esc_html_e( $a['endpoint_id'] ); ?>">
107 - <button
108 - class="button btn btn-primary wpgetapi_ajax_request"
109 - id="<?php esc_html_e( $a['button_id'] ); ?>"
110 - data-api="<?php esc_html_e( $a['api_id'] ); ?>"
111 - data-endpoint="<?php esc_html_e( $a['endpoint_id'] ); ?>"
112 - data-args="<?php esc_html_e( json_encode( $a['args'] ) ); ?>"
113 - data-keys="<?php esc_html_e( json_encode( $a['keys'] ) ); ?>"
114 - data-post_id="<?php esc_html_e( get_the_ID() ); ?>">
115 - <span class="button_text"><?php esc_html_e( $button_text ); ?></span>
116 - </button>
117 -
118 - <div class="wpgetapi_ajax_output"></div>
119 -
120 - </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>
121 107
122 108 <?php
123 109 $result = ob_get_contents();
124 110 ob_end_clean();
@@ -134,22 +120,18 @@
134 120 // [wpgetapi_endpoint api_id='livelearn' endpoint_id='dezzp1' chain='start' keys='UUID']
135 121 // [wpgetapi_endpoint api_id='livelearn' endpoint_id='dezzp2' chain='end']
136 122
137 123 // if we are starting the chain
138 - if( ! empty( $a['args']['chain'] ) ) {
124 + if( isset( $a['args']['chain'] ) ) {
139 125
140 - $delay = absint( $a['args']['chain_delay'] );
141 -
142 126 // get our result from this chain
143 127 $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
144 128
145 - if( $delay > 0 && ! is_admin() )
146 - sleep( $delay );
147 -
148 129 // set the transient for this chain if not the last chain
149 130 if( $a['args']['chain'] !== 'end' )
150 - 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 );
151 132
133 +
152 134 } else {
153 135
154 136 // do our standard return
155 137 $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
@@ -154,8 +136,11 @@
154 136 // do our standard return
155 137 $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
156 138
157 139 }
140 +
141 +
142 +
158 143
159 144 }
160 145
161 146 if( is_array( $result ) ) {