PluginProbe
WPGet API – Connect to any external REST API / 1.9.0
WPGet API – Connect to any external REST API v1.9.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 +136 -426 2.2.11.9.0 View file →
@@ -97,11 +97,8 @@
97 97 add_action( 'admin_footer', array( $this, 'load_testing_javascript' ) );
98 98
99 99 add_action( 'wp_ajax_wpgetapi_test_endpoint', array( $this, 'test_the_endpoint' ) );
100 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 -
104 101 }
105 102
106 103
107 104 /**
@@ -206,20 +203,19 @@
206 203 'sortable' => true, // beta
207 204 ),
208 205 'fields' => array(
209 206 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>',
207 + 'name' => __( 'API Name', 'wpgetapi' ),
211 208 'id' => 'name',
212 209 'type' => 'text',
213 - 'classes' => 'api-name',
214 210 'attributes' => array(
215 211 'required' => true,
216 212 'placeholder' => 'Google Maps',
217 213 ),
218 - 'desc' => '',
214 + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ),
219 215 ),
220 216 array(
221 - '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>',
217 + 'name' => __( 'Unique ID', 'wpgetapi' ),
222 218 'id' => 'id',
223 219 'type' => 'text',
224 220 'attributes' => array(
225 221 'required' => true,
@@ -224,13 +220,12 @@
224 220 'attributes' => array(
225 221 'required' => true,
226 222 'placeholder' => 'google_maps',
227 223 ),
228 - 'desc' => '',
229 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
224 + 'desc' => __( 'A unique ID for your API. Lowercase letters and underscores only.', 'wpgetapi' ),
230 225 ),
231 226 array(
232 - 'name' => __( 'Base URL', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The base URL of the API you are connecting to.', 'wpgetapi' ) . '"></span>',
227 + 'name' => __( 'Base URL', 'wpgetapi' ),
233 228 'id' => 'base_url',
234 229 'type' => 'text',
235 230 'attributes' => array(
236 231 'required' => true,
@@ -235,9 +230,9 @@
235 230 'attributes' => array(
236 231 'required' => true,
237 232 'placeholder' => 'https://maps.googleapis.com/maps/api',
238 233 ),
239 - 'desc' => '',
234 + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ),
240 235 ),
241 236
242 237 )
243 238 );
@@ -256,43 +251,41 @@
256 251
257 252 $fields = array();
258 253
259 254 $cache_disabled = $this->pro_plugin ? '' : 'disabled';
260 - $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>';
261 - $cache_desc = $this->pro_plugin ? '' : 'Available in PRO plugin.';
255 + $cache_url = $this->pro_plugin ? '<a target="_blank" href="https://wpgetapi.com/docs/caching-api-calls/">Help <span class="dashicons dashicons-external"></span></a>' : '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Cache Pro Plugin&utm_medium=Admin&utm_source=User">PRO Plugin<span class="dashicons dashicons-external"></span></a>';
262 256
263 257 $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array(
264 258 array(
265 - '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>',
259 + 'name' => __( 'Unique ID', 'wpgetapi' ),
266 260 'id' => 'id',
267 261 'type' => 'text',
268 - 'classes' => 'field-id field-half',
262 + 'classes' => 'field-id',
269 263 'attributes' => array(
270 264 'required' => true,
271 265 'placeholder' => 'new_endpoint',
272 266 ),
273 - 'desc' => '',
267 + 'desc' => __( 'A unique ID for this endpoint. Lowercase letters and underscores only.', 'wpgetapi' ),
274 268 'before_row' => "wpgetapi_output_top_of_endpoint",
275 269 'api_id' => $api_id,
276 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
277 270
278 271 ),
279 272 array(
280 - '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>',
273 + 'name' => __( 'Endpoint', 'wpgetapi' ),
281 274 'id' => 'endpoint',
282 275 'type' => 'text',
283 - 'classes' => 'field-endpoint field-half',
276 + 'classes' => 'field-endpoint',
284 277 'attributes' => array(
285 278 'required' => true,
286 279 'placeholder' => '/newendpoint',
287 280 ),
288 - 'desc' => '',
281 + 'desc' => __( 'The endpoint that will be appended to the base URL.', 'wpgetapi' ),
289 282 ),
290 283 array(
291 - '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>',
284 + 'name' => __( 'Method', 'wpgetapi' ),
292 285 'id' => 'method',
293 286 'type' => 'select',
294 - 'classes' => 'field-method field-half',
287 + 'classes' => 'field-method',
295 288 'attributes' => array(
296 289 'required' => true,
297 290 ),
298 291 'options' => array(
@@ -298,159 +291,92 @@
298 291 'options' => array(
299 292 'GET' => 'GET',
300 293 'POST' => 'POST',
301 294 'PUT' => 'PUT',
302 - 'PATCH' => 'PATCH',
303 295 'DELETE' => 'DELETE',
304 296 ),
305 - 'desc' => '',
297 + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ),
306 298 ),
307 299
308 300 array(
309 - 'name' => __( 'Results Format', 'wpgetapi' ) .
310 - '<span class="dashicons dashicons-editor-help" data-tip="' .
311 - sprintf(
312 - __( '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' ),
313 - 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>' )
314 - ) .
315 - '"></span>',
301 + 'name' => __( 'Results Format', 'wpgetapi' ),
316 302 'id' => 'results_format',
317 303 'type' => 'select',
318 - 'classes' => 'field-results-format field-half',
304 + 'classes' => 'field-results-format',
319 305 'attributes' => array(
320 306 'required' => true,
321 307 ),
322 308 'options_cb' => 'wpgetapi_results_format_options',
323 - 'desc' => ''
309 + 'desc' => sprintf(
310 + __( 'The format of the results. %1s', 'wpgetapi' ),
311 + '<a target="_blank" href="https://wpgetapi.com/docs/format-api-data-as-html/?utm_campaign=Shortcode JSON&utm_medium=Admin&utm_source=User">More options <span class="dashicons dashicons-external"></span></a>'
312 + )
324 313 ),
325 314
326 315 array(
327 - 'name' => __( 'Timeout', 'wpgetapi' ) .
328 - '<span class="dashicons dashicons-editor-help" data-tip="How long the connection should stay open in seconds. Default is 10. If you receive curl 28 errors, try increasing this value."></span>',
329 - 'id' => 'timeout',
330 - 'type' => 'text',
331 - 'default' => '10',
332 - 'classes' => 'field-timeout field-half',
333 - 'attributes' => array(
334 - 'placeholder' => '10',
335 - ),
336 - 'desc' => ''
337 - ),
338 -
339 - array(
340 - 'name' => __( 'Cache Time', 'wpgetapi' ) .
341 - '<span class="dashicons dashicons-editor-help" data-tip="' .
342 - sprintf(
343 - __( 'The time in seconds to cache this request for. %1s', 'wpgetapi' ),
344 - htmlentities( '<br>' . $cache_url )
345 - ) .
346 - '"></span>',
316 + 'name' => __( 'Cache Time', 'wpgetapi' ),
347 317 'id' => 'cache_time',
348 318 'type' => 'text',
349 - 'classes' => 'field-cache-time field-half',
319 + 'classes' => 'field-cache-time',
350 320 'attributes' => array(
351 - 'placeholder' => '3600',
321 + 'placeholder' => '',
352 322 $cache_disabled => $cache_disabled,
353 323 ),
354 - 'desc' => $cache_desc,
355 - 'after_row' => '</div>'
324 + 'desc' => sprintf(
325 + __( 'The time in seconds to cache this request for. %1s', 'wpgetapi' ),
326 + $cache_url
327 + )
356 328 ),
357 329
358 330 array(
359 - 'name' => __( 'Query String', 'wpgetapi' ) .
360 - '<span class="dashicons dashicons-editor-help" data-tip="' .
361 - sprintf(
362 - __( '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' ),
363 - 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>' )
364 - ) .
365 - '"></span>',
331 + 'name' => __( 'Query String', 'wpgetapi' ),
366 332 'id' => 'query_parameters',
367 333 'type' => 'parameter',
368 334 'classes' => 'field-query-parameters',
369 335 'repeatable' => true,
370 - 'desc' => '',
371 - 'before_row' => '<div class="fields-wrapper">'
336 + 'desc' => sprintf(
337 + __( 'Parameters as name/value pairs that will be appended to the URL. %1s', 'wpgetapi' ),
338 + '<a target="_blank" href="https://wpgetapi.com/docs/adding-query-string-parameters/?utm_campaign=Query String&utm_medium=Admin&utm_source=User">Help <span class="dashicons dashicons-external"></span></a>'
339 + )
372 340 ),
373 341 array(
374 - 'name' => __( 'Headers', 'wpgetapi' ) .
375 - '<span class="dashicons dashicons-editor-help" data-tip="' .
376 - sprintf(
377 - __( 'Parameters as name/value pairs, sent in the Headers. %1s', 'wpgetapi' ),
378 - 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>' )
379 - ) .
380 - '"></span>',
342 + 'name' => __( 'Headers', 'wpgetapi' ),
381 343 'id' => 'header_parameters',
382 344 'type' => 'parameter',
383 345 'classes' => 'field-header-parameters',
384 346 'repeatable' => true,
385 - 'desc' => ''
347 + 'desc' => sprintf(
348 + __( 'Parameters as name/value pairs, sent in the headers. %1s', 'wpgetapi' ),
349 + '<a target="_blank" href="https://wpgetapi.com/docs/sending-headers-in-request/?utm_campaign=Headers&utm_medium=Admin&utm_source=User">Help <span class="dashicons dashicons-external"></span></a>'
350 + )
386 351 ),
387 352 array(
388 - 'name' => __( 'Body', 'wpgetapi' ) .
389 - '<span class="dashicons dashicons-editor-help" data-tip="' .
390 - sprintf(
391 - __( 'Parameters as name/value pairs, sent in the Body as POST fields. %1s', 'wpgetapi' ),
392 - 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>' )
393 - ) .
394 - '"></span>',
353 + 'name' => __( 'Body POST Fields', 'wpgetapi' ),
395 354 'id' => 'body_parameters',
396 355 'type' => 'parameter',
397 356 'classes' => 'field-body-parameters',
398 357 'repeatable' => true,
399 - 'desc' => ''
358 + 'desc' => sprintf(
359 + __( 'Parameters as name/value pairs, sent in the body as POST fields. %1s', 'wpgetapi' ),
360 + '<a target="_blank" href="https://wpgetapi.com/docs/sending-post-fields-in-request/?utm_campaign=Body&utm_medium=Admin&utm_source=User">Help <span class="dashicons dashicons-external"></span></a>'
361 + )
400 362 ),
401 363 array(
402 - 'name' => __( 'Encode Body', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Encoding of the above Body parameters.', 'wpgetapi' ) . '"></span>',
364 + 'name' => __( 'Encode Body', 'wpgetapi' ),
403 365 'id' => 'body_json_encode',
404 366 'type' => 'select',
405 367 'classes' => 'field-body-json-encode',
406 368 'options' => array(
407 - 'false' => __( 'No encoding (raw)', 'wpgetapi' ),
408 - 'true' => __( 'JSON encode', 'wpgetapi' ),
409 - 'url' => __( 'URL encode (x-www-form-urlencoded)', 'wpgetapi' ),
410 - 'base64' => __( 'Base64 encode', 'wpgetapi' ),
411 - 'xml' => __( 'XML format (available in PRO)', 'wpgetapi' ),
412 -
369 + 'false' => __( 'No encoding (raw)', 'wpgetapi' ),
370 + 'true' => __( 'JSON encode', 'wpgetapi' ),
371 + 'url' => __( 'URL encode (x-www-form-urlencoded)', 'wpgetapi' ),
372 + 'xml' => __( 'XML format (available in PRO only)', 'wpgetapi' ),
413 373 ),
414 - 'desc' => '',
415 - 'after_row' => '</div>',
374 + 'desc' => __( 'Encoding of the above Body parameters. ', 'wpgetapi' ),
416 375 ),
417 - array(
418 - 'name' => __( 'Actions', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' .
419 - sprintf(
420 - __( 'Call this endpoint when your chosen action runs. This feature is available in the PRO plugin. %1s', 'wpgetapi' ),
421 - 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>' )
422 - ) .
423 - '"></span>',
424 - 'id' => 'actions',
425 - 'type' => 'select',
426 - 'classes' => 'field-actions',
427 - 'desc' => __( 'Available in PRO plugin.', 'wpgetapi' ),
428 - 'options' => array(
429 - '' => __( '-- No Action --', 'wpgetapi-extras' ),
430 - 'new_post_published' => __( 'Post/Custom Post - New Post Published', 'wpgetapi-extras' ),
431 - 'transition_post_status' => __( 'Post/Custom Post - Status Changed', 'wpgetapi-extras' ),
432 - 'delete_post' => __( 'Post/Custom Post - Delete Post', 'wpgetapi-extras' ),
376 + ) );
433 377
434 - 'user_register' => __( 'User - New User Registered', 'wpgetapi-extras' ),
435 - 'delete_user' => __( 'User - Delete User', 'wpgetapi-extras' ),
436 - 'user_login' => __( 'User - User Logs In', 'wpgetapi-extras' ),
437 - 'woocommerce_new_product' => __( 'WooCommerce - New Product Created', 'wpgetapi-extras' ),
438 - 'woocommerce_new_order' => __( 'WooCommerce - New Order Created', 'wpgetapi-extras' ),
439 - 'woocommerce_order_status_changed' => __( 'WooCommerce - Order Status Changed', 'wpgetapi-extras' ),
440 - 'contact_form_7' => __( 'Contact Form 7', 'wpgetapi-extras' ),
441 - 'gravity_forms' => __( 'Gravity Forms', 'wpgetapi-extras' ),
442 - 'wpforms' => __( 'WPForms', 'wpgetapi-extras' ),
443 - 'jetformbuilder' => __( 'JetFormBuilder', 'wpgetapi-extras' ),
444 - 'formidable_forms' => __( 'Formidable Forms', 'wpgetapi-extras' ),
445 - 'pmp' => __( 'Paid Memberships Pro - After Checkout', 'wpgetapi-extras' ),
446 - 'edd' => __( 'Easy Digital Downloads - Complete Purchase', 'wpgetapi-extras' ),
447 - ),
448 - 'default' => '',
449 - )
450 378
451 - ) );
452 -
453 379 $fields[] = array(
454 380 'id' => 'endpoints',
455 381 'type' => 'group',
456 382 'name' => '',
@@ -459,13 +385,10 @@
459 385 'group_title' => __( 'Endpoint {#}', 'wpgetapi' ),
460 386 'add_button' => __( 'Add Endpoint', 'wpgetapi' ),
461 387 'remove_button' => __( 'Remove Endpoint', 'wpgetapi' ),
462 388 'sortable' => true, // beta
463 - //'closed' => true,
464 389 ),
465 - 'before_group' => '<pre class="url"><div>Base URL:</div> <span>' . $base_url . '</span></pre>
466 - <div class="import-export"><a href="#TB_inline?&width=600&height=550&inlineId=my-content-id" class="button thickbox">Import/Export</a></div>
467 - <div class="collapse open"><a class="button" title="Collapse all endpoints"><span class="dashicons dashicons-arrow-down"></span></a></div>',
390 + 'before_group' => '<pre class="url">Base URL: <span>' . $base_url . '</span></pre>',
468 391 'fields' => $endpoint_fields,
469 392 );
470 393
471 394 return apply_filters( 'wpgetapi_fields', $fields );
@@ -473,9 +396,8 @@
473 396 }
474 397
475 398
476 399 public function add_options_pages() {
477 - add_thickbox();
478 400
479 401 $option_tabs = self::option_fields();
480 402
481 403 foreach ($option_tabs as $index => $option_tab) {
@@ -504,17 +426,11 @@
504 426 public function admin_page_display() {
505 427
506 428 $option_tabs = self::option_fields(); //get all option tabs
507 429 $tab_forms = array();
508 -
509 - $l = '';
510 - if( $this->pro_plugin ) {
511 - $l = get_option( 'wpgetapi_pro_license_status' );
512 - }
513 -
514 430 ?>
515 431
516 - <div class="wrap wpgetapi <?php esc_attr_e( $l ); ?>">
432 + <div class="wrap wpgetapi">
517 433
518 434 <div class="main_content_cell">
519 435
520 436 <h1 class="wp-heading-inline">
@@ -519,54 +435,43 @@
519 435
520 436 <h1 class="wp-heading-inline">
521 437 <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>
522 438 </h1>
439 + <!-- Options Page Nav Tabs -->
440 + <h2 class="nav-tab-wrapper">
441 + <?php foreach ($option_tabs as $option_tab) :
442 +
443 + $tab_slug = $option_tab['id'];
444 + $nav_class = 'nav-tab';
445 + if ( $tab_slug == $_GET['page'] ) {
446 + $nav_class .= ' nav-tab-active'; //add active class to current tab
447 + $tab_forms[] = $option_tab; //add current tab to forms to be rendered
448 + }
523 449
524 - <div class="outer-box">
525 - <!-- Options Page Nav Tabs -->
526 - <h2 class="nav-tab-wrapper">
527 - <?php foreach ($option_tabs as $option_tab) :
528 -
529 - $tab_slug = $option_tab['id'];
530 - $nav_class = 'nav-tab';
531 - if ( $tab_slug == $_GET['page'] ) {
532 - $nav_class .= ' nav-tab-active'; //add active class to current tab
533 - $tab_forms[] = $option_tab; //add current tab to forms to be rendered
534 - }
450 + ?>
451 +
452 + <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>
535 453
536 - ?>
537 -
538 - <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>
454 + <?php endforeach; ?>
455 + </h2>
456 + <!-- End of Nav Tabs -->
539 457
540 - <?php endforeach; ?>
541 - </h2>
542 - <!-- End of Nav Tabs -->
543 -
544 - <?php
545 - //render all tab forms (normaly just 1 form)
546 - foreach ($tab_forms as $tab_form) : ?>
547 -
548 - <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
549 - <div class="metabox-holder">
550 -
551 - <div id="my-content-id" style="display:none;">
552 - <div>
553 - <?php echo $this->get_import_export(); ?>
554 - </div>
555 - </div>
556 -
557 - <div class="pmpbox pad">
558 - <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
559 - <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
560 - <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?>
561 - </div>
458 + <?php
459 + //render all tab forms (normaly just 1 form)
460 + foreach ($tab_forms as $tab_form) : ?>
461 +
462 + <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
463 + <div class="metabox-holder">
464 + <div class="pmpbox pad">
465 + <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
466 + <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
467 + <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?>
562 468 </div>
563 469 </div>
470 + </div>
564 471
565 - <?php endforeach; ?>
472 + <?php endforeach; ?>
566 473
567 - </div>
568 -
569 474 </div>
570 475
571 476 <div class="sidebar_cell">
572 477
@@ -599,128 +504,9 @@
599 504 wp_die(); // this is required to terminate immediately and return a proper response
600 505
601 506 }
602 507
603 - public function get_import_export() {
604 - ob_start(); ?>
605 508
606 - <div class="wpgetapi-export">
607 - <h3><span class="dashicons dashicons-download"></span> Export Endpoints</h3>
608 - <p>Export the endpoints for this API.<br>After clicking the button below, copy the entire contents of the export.</p>
609 - <button class="button button-primary">Export Endpoints</button>
610 - <div class="message"></div>
611 - </div>
612 -
613 - <div class="wpgetapi-import">
614 - <h3><span class="dashicons dashicons-upload"></span> Import Endpoints</h3>
615 - <p>Paste your exported JSON data into the field below to import endpoints into this API.</p>
616 - <textarea></textarea>
617 - <button class="button button-primary">Import Endpoints</button>
618 - <div class="message"></div>
619 - </div>
620 -
621 - <?php
622 - $content = ob_get_contents();
623 - ob_end_clean();
624 - return $content;
625 - }
626 -
627 - /**
628 - * AJAX function to get our endpoints for export.
629 - *
630 - */
631 - public function export_endpoints() {
632 - $api_id = sanitize_text_field( $_POST['api_id'] );
633 - $data = get_option( $api_id );
634 -
635 - if( ! isset( $data['endpoints'] ) )
636 - wp_die();
637 -
638 - $encryption = new WpGetApi_Encryption();
639 -
640 - foreach ( $data['endpoints'] as $i => $endpoint ) {
641 - if( isset( $endpoint['query_parameters'] ) ) {
642 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
643 - if( isset( $query_parameters['value'] ) )
644 - $data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->decrypt( $query_parameters['value'] );
645 - }
646 - }
647 - if( isset( $endpoint['header_parameters'] ) ) {
648 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
649 - if( isset( $header_parameters['value'] ) )
650 - $data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->decrypt( $header_parameters['value'] );
651 - }
652 - }
653 - if( isset( $endpoint['body_parameters'] ) ) {
654 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
655 - if( isset( $body_parameters['value'] ) )
656 - $data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->decrypt( $body_parameters['value'] );
657 - }
658 - }
659 - }
660 -
661 - echo json_encode( $data );
662 - wp_die(); // this is required to terminate immediately and return a proper response
663 - }
664 -
665 - /**
666 - * AJAX function to import our endpoints.
667 - *
668 - */
669 - public function import_endpoints() {
670 -
671 - $api_id = sanitize_text_field( $_POST['api_id'] );
672 - $textarea = sanitize_textarea_field( $_POST['textarea'] );
673 - $existing_data = get_option( $api_id );
674 -
675 - if( ! $textarea ) {
676 - echo 'No data found.';
677 - wp_die();
678 - }
679 -
680 - $new_data = json_decode( stripslashes( $textarea ), true );
681 - if( ! isset( $new_data['endpoints'] ) ){
682 - echo 'No endpoints found.';
683 - wp_die();
684 - }
685 -
686 - $encryption = new WpGetApi_Encryption();
687 -
688 - foreach ( $new_data['endpoints'] as $i => $endpoint ) {
689 - if( isset( $endpoint['query_parameters'] ) ) {
690 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
691 - if( isset( $query_parameters['value'] ) )
692 - $new_data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->encrypt( $query_parameters['value'] );
693 - }
694 - }
695 - if( isset( $endpoint['header_parameters'] ) ) {
696 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
697 - if( isset( $header_parameters['value'] ) )
698 - $new_data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->encrypt( $header_parameters['value'] );
699 - }
700 - }
701 - if( isset( $endpoint['body_parameters'] ) ) {
702 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
703 - if( isset( $body_parameters['value'] ) )
704 - $new_data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->encrypt( $body_parameters['value'] );
705 - }
706 - }
707 - }
708 -
709 - // if no existing endpoints, simply add it
710 - if( ! $existing_data ) {
711 - update_option( $api_id, $new_data, 'no' );
712 - } else {
713 -
714 - $merged['endpoints'] = array_merge( $existing_data['endpoints'], $new_data['endpoints'] );
715 - update_option( $api_id, $merged, 'no' );
716 - }
717 -
718 - echo 'Successfully imported. Reloading...';
719 - wp_die(); // this is required to terminate immediately and return a proper response
720 - }
721 -
722 -
723 509 public function load_testing_javascript() { ?>
724 510
725 511 <script type="text/javascript" >
726 512
@@ -725,108 +511,12 @@
725 511 <script type="text/javascript" >
726 512
727 513 jQuery(document).ready(function($) {
728 514
729 - /**
730 - * Collapse the endpoints
731 - *
732 - */
733 - $('body').on( 'click', '.wpgetapi .collapse .button', function(){
515 + $('body').on( 'click', '.wpgetapi-test-area .test-button', function(){//delegated
734 516
735 517 var $this = $(this);
736 - var $collapse = $(this).parents('.collapse');
737 - var status = 'open';
738 -
739 - $collapse.toggleClass('open');
740 -
741 - if( ! $collapse.hasClass( 'open' ) )
742 - status = 'closed';
743 -
744 - var $endpoints = $( '#endpoints_repeat .postbox.cmb-repeatable-grouping' );
745 - $endpoints.each( function() {
746 -
747 - if( status == 'closed' ) {
748 - $( this ).addClass('closed');
749 - } else {
750 - $( this ).removeClass('closed');
751 - }
752 -
753 - });
754 -
755 - });
756 -
757 - /**
758 - * Run the export
759 - *
760 - */
761 - $('body').on( 'click', '.wpgetapi-export .button', function(){
762 -
763 - var $this = $(this);
764 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
765 -
766 - // disable button
767 - $this.attr( 'disabled', true );
768 -
769 - var data = {
770 - 'action': 'wpgetapi_export_endpoints',
771 - 'api_id': api_id,
772 - };
773 -
774 - // send and get response
775 - jQuery.post(ajaxurl, data, function( response ) {
776 - $( '.wpgetapi-export .message' ).show().html( response );
777 - // enable button
778 - $( '.wpgetapi-export .button' ).attr( 'disabled', false );
779 -
780 - });
781 -
782 - });
783 -
784 - /**
785 - * Run the import
786 - *
787 - */
788 - $('body').on( 'click', '.wpgetapi-import .button', function(){
789 -
790 - var $this = $(this);
791 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
792 - var textarea = $('.wpgetapi-import textarea').val();
793 -
794 - // disable button
795 - $this.attr( 'disabled', true );
796 -
797 - var data = {
798 - 'action': 'wpgetapi_import_endpoints',
799 - 'textarea': textarea,
800 - 'api_id': api_id,
801 - };
802 -
803 - // send and get response
804 - jQuery.post(ajaxurl, data, function( response ) {
805 -
806 - $( '.wpgetapi-import .message' ).html( response );
807 -
808 - if( response == 'Successfully imported. Reloading...' ) {
809 - setTimeout(function(){
810 - location.reload();
811 - }, 1000);
812 - } else {
813 - $( '.wpgetapi-import .button' ).attr( 'disabled', false );
814 - }
815 -
816 - });
817 -
818 - });
819 -
820 - /**
821 - * Run the endpoint test
822 - *
823 - */
824 - $('body').on( 'click', '.wpgetapi .test-endpoint-button', function(){//delegated
825 -
826 - var $this = $(this);
827 - var $parent = $this.closest( '.cmb-repeatable-grouping' );
828 - var area = $parent.find( '.wpgetapi-test-area' );
518 + var area = $this.parents( '.wpgetapi-test-area' );
829 519 var api_id = $( area ).data( 'api' );
830 520 var endpoint_id = $( area ).data( 'endpoint' );
831 521
832 522 // disable button
@@ -842,13 +532,18 @@
842 532 jQuery.post(ajaxurl, data, function( response ) {
843 533
844 534 var output = JSON.parse( response );
845 535
846 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show();
847 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( output.data);
536 + jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show();
848 537
538 + jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html(
539 + '<div class="side-notice"><p>These results contain the raw output of your API call as well as extra debugging information for testing purposes. <br>' +
540 + 'Using the shortcode or the template tag on the front end will display the Data Output section as shown below. The data can be formatted any way you like, depending on your requirements.</p></div>' +
541 + output.data
542 + );
543 +
849 544 // enable button
850 - $( '.wpgetapi .test-endpoint-button' ).attr( 'disabled', false );
545 + $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .test-button' ).attr( 'disabled', false );
851 546
852 547 });
853 548
854 549 });
@@ -878,9 +573,9 @@
878 573
879 574 ?>
880 575
881 576 <div class="box">
882 - <h4><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h4>
577 + <strong><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></strong>
883 578 <ol>
884 579 <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
885 580 <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li>
886 581 <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li>
@@ -890,10 +585,34 @@
890 585 <li><?php _e( 'Copy the Template Tag or Shortcode & paste into page, post or theme file', 'wpgetapi' ); ?></li>
891 586 </ol>
892 587 </div>
893 588
894 - <?php echo $this->help_box(); ?>
589 + <hr>
895 590
591 + <div class="box">
592 + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong>
593 + <ul>
594 + <li><?php
595 + printf(
596 + esc_html__( 'View the %1$s', 'cmb2' ),
597 + '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">Quick Start Guide</a>'
598 + );
599 + ?></li>
600 + <li><?php
601 + printf(
602 + esc_html__( 'View the %1$s', 'cmb2' ),
603 + '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>'
604 + );
605 + ?></li>
606 + <li><?php
607 + printf(
608 + esc_html__( 'Do more with the %1$s', 'cmb2' ),
609 + '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">PRO Plugin</a>'
610 + );
611 + ?></li>
612 + </ul>
613 + </div>
614 +
896 615 <?php
897 616 $content = ob_get_contents();
898 617 ob_end_clean();
899 618 return $content;
@@ -910,9 +629,9 @@
910 629 ob_start();
911 630 ?>
912 631
913 632 <div class="box">
914 - <h4><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h4>
633 + <strong><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></strong>
915 634 <ol>
916 635 <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li>
917 636 <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
918 637 <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li>
@@ -920,29 +639,12 @@
920 639 <li><?php _e( 'Visit the new tab that will be created', 'wpgetapi' ); ?></li>
921 640 </ol>
922 641 </div>
923 642
924 - <?php echo $this->help_box(); ?>
643 + <hr>
925 644
926 - <?php
927 - $content = ob_get_contents();
928 - ob_end_clean();
929 - return $content;
930 -
931 - }
932 -
933 -
934 - /**
935 - *
936 - * @since 1.4.4
937 - */
938 - public function help_box() {
939 -
940 - ob_start();
941 - ?>
942 -
943 - <div class="box help-box">
944 - <h4><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></h4>
645 + <div class="box">
646 + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong>
945 647 <ul>
946 648 <li><?php
947 649 printf(
948 650 esc_html__( 'View the %1$s', 'cmb2' ),
@@ -954,12 +656,14 @@
954 656 esc_html__( 'View the %1$s', 'cmb2' ),
955 657 '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>'
956 658 );
957 659 ?></li>
958 -
959 - <?php if( ! $this->pro_plugin ) { ?>
960 - <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>
961 - <?php } ?>
660 + <li><?php
661 + printf(
662 + esc_html__( 'Do more with the %1$s', 'cmb2' ),
663 + '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">PRO Plugin</a>'
664 + );
665 + ?></li>
962 666 </ul>
963 667 </div>
964 668
965 669 <?php
@@ -975,9 +679,9 @@
975 679 * @since 0.1.0
976 680 */
977 681 public function redirect( $object_id, $updated ) {
978 682
979 - if( strpos( $object_id, 'wpgetapi_' ) !== false && strpos( $object_id, 'wpgetapi_api_importer' ) == false ) {
683 + if( $object_id == 'wpgetapi_setup' ) {
980 684
981 685 add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' );
982 686 settings_errors( 'wpgetapi-notices' );
983 687 ?>
@@ -984,13 +688,19 @@
984 688
985 689 <script>
986 690 setTimeout(function() {
987 691 location.reload();
988 - }, 200);
692 + }, 1000);
989 693 </script>
990 694 <?php
991 695
992 - }
696 + } else if ( strpos( $object_id, 'wpgetapi_' ) !== false ) {
697 +
698 + $text = apply_filters( 'wpgetapi_admin_notice_text', __( 'Saved.', 'wpgetapi' ), $object_id );
699 + add_settings_error( 'wpgetapi-notices', '', $text, 'updated' );
700 + settings_errors( 'wpgetapi-notices' );
701 +
702 + }
993 703
994 704 }
995 705
996 706