PluginProbe
WPGet API – Connect to any external REST API / 1.4.0
WPGet API – Connect to any external REST API v1.4.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 | includes/class-admin-options.php +89 -600 2.1.41.4.0 View file →
@@ -45,14 +45,8 @@
45 45 */
46 46 public $options_pages = array();
47 47
48 48 /**
49 - * Is pro plugin installed
50 - * @var array
51 - */
52 - public $pro_plugin = false;
53 -
54 - /**
55 49 * Holds an instance of the object
56 50 *
57 51 * @var Myprefix_Admin
58 52 **/
@@ -65,9 +59,8 @@
65 59 private function __construct() {
66 60 // Set our title
67 61 $this->menu_title = __( 'WPGetAPI', 'wpgetapi' );
68 62 $this->title = __( 'WPGetAPI', 'wpgetapi' );
69 -
70 63 }
71 64
72 65 /**
73 66 * Returns the running object
@@ -89,26 +82,11 @@
89 82 public function hooks() {
90 83 add_action( 'admin_init', array( $this, 'init' ) );
91 84 add_action( 'admin_menu', array( $this, 'add_options_pages' ) );
92 85
93 - add_action( 'cmb2_admin_init', array( $this, 'init_custom_fields' ) );
94 -
95 - add_action( "cmb2_save_options-page_fields", array( $this, 'redirect' ), 1, 2 );
96 -
97 - add_action( 'admin_footer', array( $this, 'load_testing_javascript' ) );
98 -
99 - add_action( 'wp_ajax_wpgetapi_test_endpoint', array( $this, 'test_the_endpoint' ) );
100 -
101 - add_action( 'wp_ajax_wpgetapi_export_endpoints', array( $this, 'export_endpoints' ) );
102 - add_action( 'wp_ajax_wpgetapi_import_endpoints', array( $this, 'import_endpoints' ) );
103 -
86 + add_action( 'cmb2_init', array( $this, 'init_custom_fields' ) );
104 87 }
105 88
106 -
107 - /**
108 - * Setup our custom fields
109 - * @since 0.1.0
110 - */
111 89 public function init_custom_fields() {
112 90 require_once WPGETAPIDIR . 'includes/class-fields.php';
113 91 WpGetApi_Parameter_Field::init_parameter();
114 92 }
@@ -117,9 +95,8 @@
117 95 * Register our setting to WP
118 96 * @since 0.1.0
119 97 */
120 98 public function init() {
121 - $this->pro_plugin = is_plugin_active( 'wpgetapi-extras/wpgetapi-extras.php' ) ? true : false;
122 99 $option_tabs = self::option_fields();
123 100 foreach ($option_tabs as $index => $option_tab) {
124 101 register_setting( $option_tab['id'], $option_tab['id'] );
125 102 }
@@ -130,12 +107,16 @@
130 107 * Get our saved API's from setup
131 108 * @since 0.1.0
132 109 */
133 110 public function get_apis() {
111 +
134 112 $setup = get_option( 'wpgetapi_setup' );
113 +
135 114 if( empty( $setup ) || ! isset( $setup['apis'] ) || empty( $setup['apis'] ) )
136 115 return;
116 +
137 117 return $setup['apis'];
118 +
138 119 }
139 120
140 121
141 122 /**
@@ -148,15 +129,15 @@
148 129 if ( ! empty( $this->option_metabox ) ) {
149 130 return $this->option_metabox;
150 131 }
151 132
152 - // setup tab
133 + // sale tab
153 134 $option_metabox[] = array(
154 135 'title' => __( 'Setup', 'wpgetapi' ),
155 136 'menu_title' => __( 'Setup', 'wpgetapi' ),
156 137 'id' => 'wpgetapi_setup',
157 - 'desc' => __( 'Add the details of the API(s) you are using. Endpoints will be setup in the next step after hitting save.', 'wpgetapi' ),
158 - 'show_on' => array( 'key' => 'options-page', 'value' => array( 'wpgetapi_setup' ), ),
138 + 'desc' => __( 'Add the details of your API(s) below and hit the Save button.', 'wpgetapi' ),
139 + 'show_on' => array( 'key' => 'options-page', 'value' => array( 'setup' ), ),
159 140 'show_names' => true,
160 141 'fields' => $this->setup_fields(),
161 142 );
162 143
@@ -178,9 +159,9 @@
178 159 'id' => $metabox_id,
179 160 'desc' => '',
180 161 'show_on' => array( 'key' => 'options-page', 'value' => array( $metabox_id ), ),
181 162 'show_names' => true,
182 - 'fields' => $this->endpoint_fields( $type, $api_id, $base_url ),
163 + 'fields' => $this->api_fields( $type, $api_id, $base_url ),
183 164 );
184 165
185 166 }
186 167
@@ -185,14 +166,13 @@
185 166 }
186 167
187 168 }
188 169
189 - $option_metabox = apply_filters( 'wpgetapi_admin_pages', $option_metabox );
190 -
191 170 return $option_metabox;
192 171
193 172 }
194 173
174 +
195 175 public function setup_fields() {
196 176
197 177 $fields[] = array(
198 178 'id' => 'apis',
@@ -200,43 +180,42 @@
200 180 'name' => '',
201 181 'description' => '',
202 182 'options' => array(
203 183 'group_title' => __( 'API {#}', 'wpgetapi' ),
204 - 'add_button' => __( 'Add New API', 'wpgetapi' ),
184 + 'add_button' => __( 'Add API', 'wpgetapi' ),
205 185 'remove_button' => __( 'Remove API', 'wpgetapi' ),
206 186 'sortable' => true, // beta
207 187 ),
208 188 'fields' => array(
209 189 array(
210 - 'name' => __( 'API Name', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The name of this API. Call it whatever you like.', 'wpgetapi' ) . '"></span>',
190 + 'name' => __( 'API Name', 'wpgetapi' ),
211 191 'id' => 'name',
212 192 'type' => 'text',
213 193 'attributes' => array(
214 194 'required' => true,
215 - 'placeholder' => 'Google Maps',
195 + 'placeholder' => 'New API Name',
216 196 ),
217 - 'desc' => '',
197 + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ),
218 198 ),
219 199 array(
220 - 'name' => __( 'Unique ID', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Choose your own unique ID for this API. Use lowercase letters and underscores only!', 'wpgetapi' ) . '"></span>',
200 + 'name' => __( 'API ID', 'wpgetapi' ),
221 201 'id' => 'id',
222 202 'type' => 'text',
223 203 'attributes' => array(
224 204 'required' => true,
225 - 'placeholder' => 'google_maps',
205 + 'placeholder' => 'new_api_name',
226 206 ),
227 - 'desc' => '',
228 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
207 + 'desc' => __( 'A unique ID for your API. Once this is set you should not change this value.', 'wpgetapi' ),
229 208 ),
230 209 array(
231 - 'name' => __( 'Base URL', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The base URL of the API you are connecting to.', 'wpgetapi' ) . '"></span>',
210 + 'name' => __( 'Base URL', 'wpgetapi' ),
232 211 'id' => 'base_url',
233 212 'type' => 'text',
234 213 'attributes' => array(
235 214 'required' => true,
236 - 'placeholder' => 'https://maps.googleapis.com/maps/api',
215 + 'placeholder' => 'https://newapiurl.com',
237 216 ),
238 - 'desc' => '',
217 + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ),
239 218 ),
240 219
241 220 )
242 221 );
@@ -246,23 +225,40 @@
246 225 }
247 226
248 227
249 228 /**
250 - * Endpoint settings.
229 + * Site wide info on the current sale.
251 230 * @return sale info array
252 231 *
253 232 */
254 - public function endpoint_fields( $type = '', $api_id = '', $base_url = '' ) {
233 + public function api_fields( $type = '', $api_id = '', $base_url = '' ) {
255 234
256 235 $fields = array();
257 236
258 - $cache_disabled = $this->pro_plugin ? '' : 'disabled';
259 - $cache_url = $this->pro_plugin ? '<a target="_blank" href="https://wpgetapi.com/docs/caching-api-calls/">Caching Help</a>' : '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=Cache">View PRO Plugin</a>';
260 - $cache_desc = $this->pro_plugin ? '' : 'Available in PRO plugin.';
261 -
237 + $fields[] = array(
238 + 'name' => __( 'Timeout', 'wpgetapi' ),
239 + 'id' => 'timeout',
240 + 'type' => 'text',
241 + 'desc' => __( 'Timeout of the API call.', 'wpgetapi' ),
242 + 'attributes' => array(
243 + 'placeholder' => '10'
244 + ),
245 + 'before_row' => '<pre class="url"><span>Base URL: </span>' . $base_url . '</pre>',
246 + );
247 + $fields[] = array(
248 + 'name' => __( 'SSL Verify', 'wpgetapi' ),
249 + 'id' => 'sslverify',
250 + 'type' => 'select',
251 + 'desc' => __( 'This should normally be set to true. If you are having issues, you can try false.', 'wpgetapi' ),
252 + 'options' => array(
253 + '1' => 'True',
254 + '0' => 'False'
255 + ),
256 + );
257 +
262 258 $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array(
263 259 array(
264 - 'name' => __( 'Unique ID', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Choose your own unique ID for this endpoint. Use lowercase letters and underscores only!', 'wpgetapi' ) . '"></span>',
260 + 'name' => __( 'Unique ID', 'wpgetapi' ),
265 261 'id' => 'id',
266 262 'type' => 'text',
267 263 'classes' => 'field-id',
268 264 'attributes' => array(
@@ -268,16 +264,18 @@
268 264 'attributes' => array(
269 265 'required' => true,
270 266 'placeholder' => 'new_endpoint',
271 267 ),
272 - 'desc' => '',
273 - 'before_row' => "wpgetapi_output_top_of_endpoint",
274 - 'api_id' => $api_id,
275 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
276 -
268 + 'desc' => __( 'Choose a unique ID for this endpoint. Once this is set you should not change this value.', 'wpgetapi' ),
269 + 'before_row' => "
270 + <pre class='functions'>
271 + Template Tag: </span><span>wpgetapi_endpoint( '" . $api_id . "', '<span class='endpoint_id'></span>', array('debug' => false) );</span><br>
272 + Shortcode: <span>[wpgetapi_endpoint api_id='" . $api_id . "' endpoint_id='<span class='endpoint_id'></span>' debug='false']</span>
273 + </pre>
274 + ",
277 275 ),
278 276 array(
279 - 'name' => __( 'Endpoint', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'This Endpoint will be appended to the Base URL to create the full URL that will be called.', 'wpgetapi' ) . '"></span>',
277 + 'name' => __( 'Endpoint', 'wpgetapi' ),
280 278 'id' => 'endpoint',
281 279 'type' => 'text',
282 280 'classes' => 'field-endpoint',
283 281 'attributes' => array(
@@ -283,12 +281,12 @@
283 281 'attributes' => array(
284 282 'required' => true,
285 283 'placeholder' => '/newendpoint',
286 284 ),
287 - 'desc' => '',
285 + 'desc' => __( 'The endpoint that will be appended to the base URL to get the data. Include slash at beginning.', 'wpgetapi' ),
288 286 ),
289 287 array(
290 - 'name' => __( 'Method', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The Request Method for this endpoint. If you are displaying data from the API, it will usually be GET. If you are sending to the API, it will usually be POST.', 'wpgetapi' ) . '"></span>',
288 + 'name' => __( 'Method', 'wpgetapi' ),
291 289 'id' => 'method',
292 290 'type' => 'select',
293 291 'classes' => 'field-method',
294 292 'attributes' => array(
@@ -296,23 +294,13 @@
296 294 ),
297 295 'options' => array(
298 296 'GET' => 'GET',
299 297 'POST' => 'POST',
300 - 'PUT' => 'PUT',
301 - 'PATCH' => 'PATCH',
302 - 'DELETE' => 'DELETE',
303 298 ),
304 - 'desc' => '',
299 + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ),
305 300 ),
306 -
307 301 array(
308 - 'name' => __( 'Results Format', 'wpgetapi' ) .
309 - '<span class="dashicons dashicons-editor-help" data-tip="' .
310 - sprintf(
311 - __( 'The format that the API data will be returned in. To format the data as HTML, click the link below to learn how. %1s', 'wpgetapi' ),
312 - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/formatting-json-data/?utm_campaign=Shortcode JSON&utm_medium=Admin&utm_source=User">Format as HTML</a>' )
313 - ) .
314 - '"></span>',
302 + 'name' => __( 'Results Format', 'wpgetapi' ),
315 303 'id' => 'results_format',
316 304 'type' => 'select',
317 305 'classes' => 'field-results-format',
318 306 'attributes' => array(
@@ -318,126 +306,52 @@
318 306 'attributes' => array(
319 307 'required' => true,
320 308 ),
321 309 'options_cb' => 'wpgetapi_results_format_options',
322 - 'desc' => ''
310 + 'desc' => __( 'The format of the results.', 'wpgetapi' ),
323 311 ),
324 -
325 312 array(
326 - 'name' => __( 'Cache Time', 'wpgetapi' ) .
327 - '<span class="dashicons dashicons-editor-help" data-tip="' .
328 - sprintf(
329 - __( 'The time in seconds to cache this request for. %1s', 'wpgetapi' ),
330 - htmlentities( '<br>' . $cache_url )
331 - ) .
332 - '"></span>',
333 - 'id' => 'cache_time',
334 - 'type' => 'text',
335 - 'classes' => 'field-cache-time',
336 - 'attributes' => array(
337 - 'placeholder' => '3600',
338 - $cache_disabled => $cache_disabled,
339 - ),
340 - 'desc' => $cache_desc
341 - ),
342 -
343 - array(
344 - 'name' => __( 'Query String', 'wpgetapi' ) .
345 - '<span class="dashicons dashicons-editor-help" data-tip="' .
346 - sprintf(
347 - __( 'Parameters as name/value pairs that will be appended to the URL. The query string is the part of the URL after the question mark, like so: https://yoururl.com<b>?key=value&key3=value3</b> %1s', 'wpgetapi' ),
348 - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/adding-query-string-parameters/?utm_campaign=Query String&utm_medium=Admin&utm_source=User">More Info</a>' )
349 - ) .
350 - '"></span>',
313 + 'name' => __( 'Query String', 'wpgetapi' ),
351 314 'id' => 'query_parameters',
352 315 'type' => 'parameter',
353 316 'classes' => 'field-query-parameters',
354 317 'repeatable' => true,
355 - 'desc' => ''
318 + 'desc' => __( 'Parameters as name/value pairs that will be appended to the URL. ', 'wpgetapi' ),
356 319 ),
357 320 array(
358 - 'name' => __( 'Headers', 'wpgetapi' ) .
359 - '<span class="dashicons dashicons-editor-help" data-tip="' .
360 - sprintf(
361 - __( 'Parameters as name/value pairs, sent in the Headers. %1s', 'wpgetapi' ),
362 - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/sending-headers-in-request/?utm_campaign=Headers&utm_medium=Admin&utm_source=User">More Info</a>' )
363 - ) .
364 - '"></span>',
321 + 'name' => __( 'Headers', 'wpgetapi' ),
365 322 'id' => 'header_parameters',
366 323 'type' => 'parameter',
367 324 'classes' => 'field-header-parameters',
368 325 'repeatable' => true,
369 - 'desc' => ''
326 + 'desc' => __( 'Parameters as name/value pairs that will be included in the header. ', 'wpgetapi' ),
370 327 ),
371 328 array(
372 - 'name' => __( 'Body POST Fields', 'wpgetapi' ) .
373 - '<span class="dashicons dashicons-editor-help" data-tip="' .
374 - sprintf(
375 - __( 'Parameters as name/value pairs, sent in the Body as POST fields. %1s', 'wpgetapi' ),
376 - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/sending-post-fields-in-request/?utm_campaign=Body&utm_medium=Admin&utm_source=User">More Info</a>' )
377 - ) .
378 - '"></span>',
329 + 'name' => __( 'Body', 'wpgetapi' ),
379 330 'id' => 'body_parameters',
380 331 'type' => 'parameter',
381 332 'classes' => 'field-body-parameters',
382 333 'repeatable' => true,
383 - 'desc' => ''
334 + 'desc' => __( 'Parameters as name/value pairs that will be included in the POST body fields. Only used when POST method is selected. ', 'wpgetapi' ),
384 335 ),
385 336 array(
386 - 'name' => __( 'Encode Body', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Encoding of the above Body parameters.', 'wpgetapi' ) . '"></span>',
337 + 'name' => __( 'JSON Encode Body', 'wpgetapi' ),
387 338 'id' => 'body_json_encode',
388 339 'type' => 'select',
389 340 'classes' => 'field-body-json-encode',
390 - 'options' => array(
391 - 'false' => __( 'No encoding (raw)', 'wpgetapi' ),
392 - 'true' => __( 'JSON encode', 'wpgetapi' ),
393 - 'url' => __( 'URL encode (x-www-form-urlencoded)', 'wpgetapi' ),
394 - 'base64' => __( 'Base64 encode', 'wpgetapi' ),
395 - 'xml' => __( 'XML format (available in PRO)', 'wpgetapi' ),
396 -
341 + 'options' => array(
342 + 'true' => __( 'Yes', 'wpgetapi' ),
343 + 'false' => __( 'No', 'wpgetapi' ),
397 344 ),
398 - 'desc' => '',
345 + 'desc' => __( 'Do you want to JSON encode the Body parameters above. ', 'wpgetapi' ),
399 346 ),
400 - array(
401 - 'name' => __( 'Actions', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' .
402 - sprintf(
403 - __( 'Call this endpoint when your chosen action runs. This feature is available in the PRO plugin. %1s', 'wpgetapi' ),
404 - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=Actions">View PRO Plugin</a>' )
405 - ) .
406 - '"></span>',
407 - 'id' => 'actions',
408 - 'type' => 'select',
409 - 'classes' => 'field-actions',
410 - 'desc' => __( 'Available in PRO plugin.', 'wpgetapi' ),
411 - 'options' => array(
412 - '' => __( '-- No Action --', 'wpgetapi-extras' ),
413 - 'new_post_published' => __( 'Post/Custom Post - New Post Published', 'wpgetapi-extras' ),
414 - 'transition_post_status' => __( 'Post/Custom Post - Status Changed', 'wpgetapi-extras' ),
415 - 'delete_post' => __( 'Post/Custom Post - Delete Post', 'wpgetapi-extras' ),
347 + ) );
416 348
417 - 'user_register' => __( 'User - New User Registered', 'wpgetapi-extras' ),
418 - 'delete_user' => __( 'User - Delete User', 'wpgetapi-extras' ),
419 - 'user_login' => __( 'User - User Logs In', 'wpgetapi-extras' ),
420 - 'woocommerce_new_product' => __( 'WooCommerce - New Product Created', 'wpgetapi-extras' ),
421 - 'woocommerce_new_order' => __( 'WooCommerce - New Order Created', 'wpgetapi-extras' ),
422 - 'woocommerce_order_status_changed' => __( 'WooCommerce - Order Status Changed', 'wpgetapi-extras' ),
423 - 'contact_form_7' => __( 'Contact Form 7', 'wpgetapi-extras' ),
424 - 'gravity_forms' => __( 'Gravity Forms', 'wpgetapi-extras' ),
425 - 'wpforms' => __( 'WPForms', 'wpgetapi-extras' ),
426 - 'jetformbuilder' => __( 'JetFormBuilder', 'wpgetapi-extras' ),
427 - 'formidable_forms' => __( 'Formidable Forms', 'wpgetapi-extras' ),
428 - 'pmp' => __( 'Paid Memberships Pro - After Checkout', 'wpgetapi-extras' ),
429 - 'edd' => __( 'Easy Digital Downloads - Complete Purchase', 'wpgetapi-extras' ),
430 - ),
431 - 'default' => '',
432 - )
433 349
434 - ) );
435 -
436 350 $fields[] = array(
437 351 'id' => 'endpoints',
438 352 'type' => 'group',
439 - 'name' => '',
353 + 'name' => __( 'Endpoints', 'wpgetapi' ),
440 354 'description' => '',
441 355 'options' => array(
442 356 'group_title' => __( 'Endpoint {#}', 'wpgetapi' ),
443 357 'add_button' => __( 'Add Endpoint', 'wpgetapi' ),
@@ -442,23 +356,18 @@
442 356 'group_title' => __( 'Endpoint {#}', 'wpgetapi' ),
443 357 'add_button' => __( 'Add Endpoint', 'wpgetapi' ),
444 358 'remove_button' => __( 'Remove Endpoint', 'wpgetapi' ),
445 359 'sortable' => true, // beta
446 - //'closed' => true,
447 360 ),
448 - 'before_group' => '<pre class="url"><div>Base URL:</div> <span>' . $base_url . '</span></pre>
449 - <div class="import-export"><a href="#TB_inline?&width=600&height=550&inlineId=my-content-id" class="button thickbox">Import/Export</a></div>
450 - <div class="collapse open"><a class="button" title="Collapse all endpoints"><span class="dashicons dashicons-arrow-down"></span></a></div>',
451 361 'fields' => $endpoint_fields,
452 362 );
453 363
454 - return apply_filters( 'wpgetapi_fields', $fields );
364 + return $fields;
455 365
456 366 }
457 367
458 368
459 369 public function add_options_pages() {
460 - add_thickbox();
461 370
462 371 $option_tabs = self::option_fields();
463 372
464 373 foreach ($option_tabs as $index => $option_tab) {
@@ -463,9 +372,9 @@
463 372
464 373 foreach ($option_tabs as $index => $option_tab) {
465 374 if ( $index == 0) {
466 375
467 - $this->options_pages[] = add_menu_page( $this->title, $this->menu_title, 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ), 'none'
376 + $this->options_pages[] = add_menu_page( $this->title, $this->menu_title, 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ), 'dashicons-editor-code'
468 377 ); //Link admin menu to first tab
469 378
470 379 add_submenu_page( $option_tabs[0]['id'], $this->menu_title, $option_tab['menu_title'], 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ) ); //Duplicate menu link for first submenu page
471 380 } else {
@@ -493,15 +402,12 @@
493 402 <div class="wrap wpgetapi">
494 403
495 404 <div class="main_content_cell">
496 405
497 - <h1 class="wp-heading-inline">
498 - <img width="24" height="22" src="<?php echo esc_url( WPGETAPIURL . 'assets/img/wpgetapi-icon.png' ); ?>" /> <?php esc_html_e( $this->title, 'wpgetapi' ) ?> <span class="vnum"><?php echo WPGETAPIVERSION; ?></span>
499 - </h1>
406 + <h2><?php esc_html_e( $this->title, 'wpgetapi' ) ?></h2>
500 407 <!-- Options Page Nav Tabs -->
501 408 <h2 class="nav-tab-wrapper">
502 409 <?php foreach ($option_tabs as $option_tab) :
503 -
504 410 $tab_slug = $option_tab['id'];
505 411 $nav_class = 'nav-tab';
506 412 if ( $tab_slug == $_GET['page'] ) {
507 413 $nav_class .= ' nav-tab-active'; //add active class to current tab
@@ -506,34 +412,22 @@
506 412 if ( $tab_slug == $_GET['page'] ) {
507 413 $nav_class .= ' nav-tab-active'; //add active class to current tab
508 414 $tab_forms[] = $option_tab; //add current tab to forms to be rendered
509 415 }
510 -
511 - ?>
512 -
513 - <a class="<?php esc_attr_e( $nav_class ); ?>" href="<?php esc_url( menu_page_url( $tab_slug ) ); ?>"><?php esc_attr_e( $option_tab['menu_title'], 'wpgetapi' ); ?></a>
514 -
416 + ?>
417 + <a class="<?php esc_attr_e( $nav_class ); ?>" href="<?php esc_url( menu_page_url( $tab_slug ) ); ?>"><?php esc_attr_e( $option_tab['title'], 'wpgetapi' ); ?></a>
515 418 <?php endforeach; ?>
516 419 </h2>
517 420 <!-- End of Nav Tabs -->
518 421
519 - <?php
520 - //render all tab forms (normaly just 1 form)
521 - foreach ($tab_forms as $tab_form) : ?>
422 + <?php foreach ($tab_forms as $tab_form) : //render all tab forms (normaly just 1 form) ?>
522 423
523 424 <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
524 425 <div class="metabox-holder">
525 -
526 - <div id="my-content-id" style="display:none;">
527 - <div>
528 - <?php echo $this->get_import_export(); ?>
529 - </div>
530 - </div>
531 -
532 426 <div class="pmpbox pad">
533 427 <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
534 428 <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
535 - <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?>
429 + <?php cmb2_metabox_form( $tab_form, $tab_form['id'] ); ?>
536 430 </div>
537 431 </div>
538 432 </div>
539 433
@@ -541,14 +435,21 @@
541 435
542 436 </div>
543 437
544 438 <div class="sidebar_cell">
545 -
546 - <?php
547 - $sidebar = self::sidebar_display();
548 - echo apply_filters( 'wpgetapi_admin_sidebar_display', $sidebar );
549 - ?>
439 + <div class="box">
440 + <h3>Help & Tips</h3>
441 + <p><a class="button-primary" target="_blank" href="https://wpgetapi.com/docs/?utm_campaign=Help&utm_medium=Admin&utm_source=User">View The Docs</a></p>
442 + <ul>
443 + <li><b>Using the Template Tag within your theme is the most flexible option and is recommended.</b></li>
444 + <li>The Template Tag will 'return' data only. To output to your page you will need to 'echo' or 'var_dump'.</li>
445 + <li>Trying to 'echo' the data when using the 'JSON (as array data)' option will result in a PHP warning. You will need to use 'var_dump' instead to see the output.</li>
446 + <li>Using the Shortcode within a page (or post) becomes a little more flexible when used in conjunction with our <a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">Pro plugin</a>.</li>
550 447
448 + <li>You can get nested data from the array using our <a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">Pro Plugin</a> extension using either Shortcode or Template Tag.</li>
449 + </ul>
450 + </div>
451 +
551 452 </div>
552 453
553 454 </div>
554 455
@@ -554,420 +455,8 @@
554 455
555 456 <?php
556 457
557 458 }
558 -
559 -
560 - public function test_the_endpoint() {
561 -
562 - $api_id = sanitize_text_field( $_POST['api_id'] );
563 - $endpoint_id = sanitize_text_field( $_POST['endpoint_id'] );
564 - $data = wpgetapi_endpoint( $api_id, $endpoint_id, array( 'test_endpoint' => true ) );
565 -
566 - $output = array(
567 - 'data' => $data,
568 - 'endpoint_id' => $endpoint_id
569 - );
570 - echo json_encode( $output );
571 -
572 - wp_die(); // this is required to terminate immediately and return a proper response
573 -
574 - }
575 -
576 - public function get_import_export() {
577 - ob_start(); ?>
578 -
579 - <div class="wpgetapi-export">
580 - <h3><span class="dashicons dashicons-download"></span> Export Endpoints</h3>
581 - <p>Export the endpoints for this API.<br>After clicking the button below, copy the entire contents of the export.</p>
582 - <button class="button button-primary">Export Endpoints</button>
583 - <div class="message"></div>
584 - </div>
585 -
586 - <div class="wpgetapi-import">
587 - <h3><span class="dashicons dashicons-upload"></span> Import Endpoints</h3>
588 - <p>Paste your exported JSON data into the field below to import endpoints into this API.</p>
589 - <textarea></textarea>
590 - <button class="button button-primary">Import Endpoints</button>
591 - <div class="message"></div>
592 - </div>
593 -
594 - <?php
595 - $content = ob_get_contents();
596 - ob_end_clean();
597 - return $content;
598 - }
599 -
600 - /**
601 - * AJAX function to get our endpoints for export.
602 - *
603 - */
604 - public function export_endpoints() {
605 - $api_id = sanitize_text_field( $_POST['api_id'] );
606 - $data = get_option( $api_id );
607 -
608 - if( ! isset( $data['endpoints'] ) )
609 - wp_die();
610 -
611 - $encryption = new WpGetApi_Encryption();
612 -
613 - foreach ( $data['endpoints'] as $i => $endpoint ) {
614 - if( isset( $endpoint['query_parameters'] ) ) {
615 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
616 - if( isset( $query_parameters['value'] ) )
617 - $data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->decrypt( $query_parameters['value'] );
618 - }
619 - }
620 - if( isset( $endpoint['header_parameters'] ) ) {
621 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
622 - if( isset( $header_parameters['value'] ) )
623 - $data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->decrypt( $header_parameters['value'] );
624 - }
625 - }
626 - if( isset( $endpoint['body_parameters'] ) ) {
627 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
628 - if( isset( $body_parameters['value'] ) )
629 - $data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->decrypt( $body_parameters['value'] );
630 - }
631 - }
632 - }
633 -
634 - echo json_encode( $data );
635 - wp_die(); // this is required to terminate immediately and return a proper response
636 - }
637 -
638 - /**
639 - * AJAX function to import our endpoints.
640 - *
641 - */
642 - public function import_endpoints() {
643 -
644 - $api_id = sanitize_text_field( $_POST['api_id'] );
645 - $textarea = sanitize_textarea_field( $_POST['textarea'] );
646 - $existing_data = get_option( $api_id );
647 -
648 - if( ! $textarea ) {
649 - echo 'No data found.';
650 - wp_die();
651 - }
652 -
653 - $new_data = json_decode( stripslashes( $textarea ), true );
654 - if( ! isset( $new_data['endpoints'] ) ){
655 - echo 'No endpoints found.';
656 - wp_die();
657 - }
658 -
659 - $encryption = new WpGetApi_Encryption();
660 -
661 - foreach ( $new_data['endpoints'] as $i => $endpoint ) {
662 - if( isset( $endpoint['query_parameters'] ) ) {
663 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
664 - if( isset( $query_parameters['value'] ) )
665 - $new_data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->encrypt( $query_parameters['value'] );
666 - }
667 - }
668 - if( isset( $endpoint['header_parameters'] ) ) {
669 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
670 - if( isset( $header_parameters['value'] ) )
671 - $new_data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->encrypt( $header_parameters['value'] );
672 - }
673 - }
674 - if( isset( $endpoint['body_parameters'] ) ) {
675 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
676 - if( isset( $body_parameters['value'] ) )
677 - $new_data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->encrypt( $body_parameters['value'] );
678 - }
679 - }
680 - }
681 -
682 - // if no existing endpoints, simply add it
683 - if( ! $existing_data ) {
684 - update_option( $api_id, $new_data );
685 - } else {
686 -
687 - $merged['endpoints'] = array_merge( $existing_data['endpoints'], $new_data['endpoints'] );
688 - update_option( $api_id, $merged );
689 - }
690 -
691 - echo 'Successfully imported. Reloading...';
692 - wp_die(); // this is required to terminate immediately and return a proper response
693 - }
694 -
695 -
696 - public function load_testing_javascript() { ?>
697 -
698 - <script type="text/javascript" >
699 -
700 - jQuery(document).ready(function($) {
701 -
702 - /**
703 - * Collapse the endpoints
704 - *
705 - */
706 - $('body').on( 'click', '.wpgetapi .collapse .button', function(){
707 -
708 - var $this = $(this);
709 - var $collapse = $(this).parents('.collapse');
710 - var status = 'open';
711 -
712 - $collapse.toggleClass('open');
713 -
714 - if( ! $collapse.hasClass( 'open' ) )
715 - status = 'closed';
716 -
717 - var $endpoints = $( '#endpoints_repeat .postbox.cmb-repeatable-grouping' );
718 - $endpoints.each( function() {
719 -
720 - if( status == 'closed' ) {
721 - $( this ).addClass('closed');
722 - } else {
723 - $( this ).removeClass('closed');
724 - }
725 -
726 - });
727 -
728 - });
729 -
730 - /**
731 - * Run the export
732 - *
733 - */
734 - $('body').on( 'click', '.wpgetapi-export .button', function(){
735 -
736 - var $this = $(this);
737 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
738 -
739 - // disable button
740 - $this.attr( 'disabled', true );
741 -
742 - var data = {
743 - 'action': 'wpgetapi_export_endpoints',
744 - 'api_id': api_id,
745 - };
746 -
747 - // send and get response
748 - jQuery.post(ajaxurl, data, function( response ) {
749 - $( '.wpgetapi-export .message' ).show().html( response );
750 - // enable button
751 - $( '.wpgetapi-export .button' ).attr( 'disabled', false );
752 -
753 - });
754 -
755 - });
756 -
757 - /**
758 - * Run the import
759 - *
760 - */
761 - $('body').on( 'click', '.wpgetapi-import .button', function(){
762 -
763 - var $this = $(this);
764 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
765 - var textarea = $('.wpgetapi-import textarea').val();
766 -
767 - // disable button
768 - $this.attr( 'disabled', true );
769 -
770 - var data = {
771 - 'action': 'wpgetapi_import_endpoints',
772 - 'textarea': textarea,
773 - 'api_id': api_id,
774 - };
775 -
776 - // send and get response
777 - jQuery.post(ajaxurl, data, function( response ) {
778 -
779 - $( '.wpgetapi-import .message' ).html( response );
780 -
781 - if( response == 'Successfully imported. Reloading...' ) {
782 - setTimeout(function(){
783 - location.reload();
784 - }, 2000);
785 - } else {
786 - $( '.wpgetapi-import .button' ).attr( 'disabled', false );
787 - }
788 -
789 - });
790 -
791 - });
792 -
793 - /**
794 - * Run the endpoint test
795 - *
796 - */
797 - $('body').on( 'click', '.wpgetapi-test-area .test-button', function(){//delegated
798 -
799 - var $this = $(this);
800 - var area = $this.parents( '.wpgetapi-test-area' );
801 - var api_id = $( area ).data( 'api' );
802 - var endpoint_id = $( area ).data( 'endpoint' );
803 -
804 - // disable button
805 - $this.attr( 'disabled', true );
806 -
807 - var data = {
808 - 'action': 'wpgetapi_test_endpoint',
809 - 'api_id': api_id,
810 - 'endpoint_id': endpoint_id
811 - };
812 -
813 - // send and get response
814 - jQuery.post(ajaxurl, data, function( response ) {
815 -
816 - var output = JSON.parse( response );
817 -
818 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show();
819 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( output.data);
820 -
821 - // enable button
822 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .test-button' ).attr( 'disabled', false );
823 -
824 - });
825 -
826 - });
827 -
828 - $( '.wpgetapi-test-area .handle' ).on('click', function() {
829 - $('.wpgetapi-result').toggle();
830 - });
831 -
832 - });
833 -
834 - </script> <?php
835 -
836 - }
837 -
838 -
839 - /**
840 - * Sidebar markup.
841 - * @since 1.4.1
842 - */
843 - public function sidebar_display() {
844 -
845 - ob_start();
846 -
847 - // do our setup page
848 - if( isset( $_GET['page'] ) && $_GET['page'] === 'wpgetapi_setup' )
849 - return $this->sidebar_setup_page();
850 -
851 - ?>
852 -
853 - <div class="box">
854 - <h4><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h4>
855 - <ol>
856 - <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
857 - <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li>
858 - <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li>
859 - <li><?php _e( 'Set the desired <b>Results Format</b>', 'wpgetapi' ); ?></li>
860 - <li><?php _e( 'Other fields are optional & will depend on your API', 'wpgetapi' ); ?></li>
861 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
862 - <li><?php _e( 'Copy the Template Tag or Shortcode & paste into page, post or theme file', 'wpgetapi' ); ?></li>
863 - </ol>
864 - </div>
865 -
866 - <?php echo $this->help_box(); ?>
867 -
868 - <?php
869 - $content = ob_get_contents();
870 - ob_end_clean();
871 - return $content;
872 -
873 - }
874 -
875 -
876 - /**
877 - * Sidebar for our setup page.
878 - * @since 1.4.4
879 - */
880 - public function sidebar_setup_page() {
881 -
882 - ob_start();
883 - ?>
884 -
885 - <div class="box">
886 - <h4><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h4>
887 - <ol>
888 - <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li>
889 - <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
890 - <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li>
891 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
892 - <li><?php _e( 'Visit the new tab that will be created', 'wpgetapi' ); ?></li>
893 - </ol>
894 - </div>
895 -
896 - <?php echo $this->help_box(); ?>
897 -
898 - <?php
899 - $content = ob_get_contents();
900 - ob_end_clean();
901 - return $content;
902 -
903 - }
904 -
905 -
906 - /**
907 - *
908 - * @since 1.4.4
909 - */
910 - public function help_box() {
911 -
912 - ob_start();
913 - ?>
914 -
915 - <hr>
916 -
917 - <div class="box help-box">
918 - <h4><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></h4>
919 - <ul>
920 - <li><?php
921 - printf(
922 - esc_html__( 'View the %1$s', 'cmb2' ),
923 - '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">Quick Start Guide</a>'
924 - );
925 - ?></li>
926 - <li><?php
927 - printf(
928 - esc_html__( 'View the %1$s', 'cmb2' ),
929 - '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>'
930 - );
931 - ?></li>
932 -
933 - <?php if( ! $this->pro_plugin ) { ?>
934 - <a class="button" target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User"><?php esc_html_e( 'Do more with the PRO Plugin', 'cmb2' ); ?></a>
935 - <?php } ?>
936 - </ul>
937 - </div>
938 -
939 - <?php
940 - $content = ob_get_contents();
941 - ob_end_clean();
942 - return $content;
943 -
944 - }
945 -
946 -
947 - /**
948 - * Tabs don't immmediately appear on save, so this hack!
949 - * @since 0.1.0
950 - */
951 - public function redirect( $object_id, $updated ) {
952 -
953 - if( strpos( $object_id, 'wpgetapi_' ) !== false && strpos( $object_id, 'wpgetapi_api_importer' ) == false ) {
954 -
955 - add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' );
956 - settings_errors( 'wpgetapi-notices' );
957 - ?>
958 -
959 - <script>
960 - setTimeout(function() {
961 - location.reload();
962 - }, 200);
963 - </script>
964 - <?php
965 -
966 - }
967 -
968 - }
969 -
970 459
971 460 /**
972 461 * Public getter method for retrieving protected/private variables
973 462 * @since 0.1.0