PluginProbe
WPGet API – Connect to any external REST API / 1.7.0
WPGet API – Connect to any external REST API v1.7.0
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 +1 -103 2.1.11.7.0 View file →
@@ -26,25 +26,11 @@
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 - 'html_url' => '',
35 - 'html_to_link' => '',
36 - 'img_key' => '',
37 - 'img_prepend' => '',
38 - 'img_link' => '',
39 - 'on' => '',
40 - 'button_text' => '',
41 - 'hide_button' => '',
42 - 'button_spinner' => '',
43 - 'button_id' => '',
44 - 'ajax_output' => '.wpgetapi_ajax_output',
45 - 'chain' => '',
46 - 'chain_delay' => '0',
47 33 ), $atts );
48 34
49 35 if( ! isset( $a['api_id'] ) || $a['api_id'] == '' )
50 36 return __( 'api_id shortcode attribute is not set.', 'wpgetapi' );
@@ -51,10 +37,8 @@
51 37
52 38 if( ! isset( $a['endpoint_id'] ) || $a['endpoint_id'] == '' )
53 39 return __( 'endpoint_id shortcode attribute is not set.', 'wpgetapi' );
54 40
55 -
56 -
57 41 // sort out our keys if using them
58 42 if( ! empty( $a['keys'] ) ) {
59 43 // Create our array of values for keys
60 44 // First, sanitize the data and remove white spaces
@@ -73,99 +57,13 @@
73 57 // add our shortcode args to the actual 'args' within the endpoint call
74 58 $a['args']['debug'] = $a['debug'];
75 59 $a['args']['endpoint_variables'] = $a['endpoint_variables'];
76 60 $a['args']['query_variables'] = $a['query_variables'];
77 - $a['args']['body_variables'] = $a['body_variables'];
78 61 $a['args']['format'] = $a['format'];
79 62 $a['args']['html_tag'] = $a['html_tag'];
80 63 $a['args']['html_labels'] = $a['html_labels'];
81 - $a['args']['html_url'] = $a['html_url'];
82 - $a['args']['html_to_link'] = $a['html_to_link'];
83 - $a['args']['img_key'] = $a['img_key'];
84 - $a['args']['img_prepend'] = $a['img_prepend'];
85 - $a['args']['img_link'] = $a['img_link'];
86 64 $a['args']['shortcode'] = true;
87 - $a['args']['on'] = $a['on'];
88 - $a['args']['button_text'] = $a['button_text'];
89 - $a['args']['hide_button'] = $a['hide_button'];
90 - $a['args']['button_spinner'] = $a['button_spinner'];
91 - $a['args']['button_id'] = $a['button_id'];
92 - $a['args']['ajax_output'] = $a['ajax_output'];
93 - $a['args']['chain'] = $a['chain'];
94 - $a['args']['chain_delay'] = $a['chain_delay'];
95 65
96 -
97 - // if we are doing ajax
98 - if( isset( $a['args']['on'] ) && $a['args']['on'] == 'ajax' && ! wp_doing_ajax() ) {
99 -
100 - if( class_exists( 'WpGetApi_Extras_Extend' ) ) {
101 -
102 - add_action( 'wp_footer', array( 'WpGetApi_Extras_Extend', 'ajax_function' ) );
103 -
104 - $button_text = isset( $a['args']['button_text'] ) && $a['args']['button_text'] != '' ? $a['args']['button_text'] : 'Call API';
105 -
106 - ob_start(); ?>
107 -
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>
123 -
124 - <?php
125 - $result = ob_get_contents();
126 - ob_end_clean();
127 -
128 - } else {
129 -
130 - $result = 'You need the <a href="https://wpgetapi.com/downloads/pro-plugin">PRO plugin</a> for this AJAX functionality.';
131 -
132 - }
133 -
134 - } else {
135 -
136 - // if we are starting the chain
137 - if( ! empty( $a['args']['chain'] ) ) {
138 -
139 - $delay = absint( $a['args']['chain_delay'] );
140 -
141 - // get our result from this chain
142 - $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
143 -
144 - if( $delay > 0 && ! is_admin() )
145 - sleep( $delay );
146 -
147 - // set the transient for this chain if not the last chain
148 - if( $a['args']['chain'] !== 'end' )
149 - set_transient( 'wpgetapi_chain_' . sanitize_text_field( $a['args']['chain'] ), $result, $delay + 10 );
150 -
151 - } else {
152 -
153 - // do our standard return
154 - $result = wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
155 -
156 - }
157 -
158 - }
159 -
160 - if( is_array( $result ) ) {
161 - $result = sprintf(
162 - __( '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>.'
164 - );
165 - }
166 -
167 - if( $a['args']['format'] !== 'no_display' )
168 - return $result;
66 + return wpgetapi_endpoint( $a['api_id'], $a['endpoint_id'], $a['args'], $a['keys'] );
169 67
170 68 }
171 69 add_shortcode( 'wpgetapi_endpoint', 'wpgetapi_endpoint_shortcode' );