PluginProbe
WPGet API – Connect to any external REST API / 1.4.6
WPGet API – Connect to any external REST API v1.4.6
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 +111 -284 2.0.41.4.6 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
@@ -91,17 +84,11 @@
91 84 add_action( 'admin_menu', array( $this, 'add_options_pages' ) );
92 85
93 86 add_action( 'cmb2_admin_init', array( $this, 'init_custom_fields' ) );
94 87
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 -
88 + add_action( "cmb2_save_options-page_fields", array( $this, 'redirect' ), 98, 2 );
101 89 }
102 90
103 -
104 91 /**
105 92 * Setup our custom fields
106 93 * @since 0.1.0
107 94 */
@@ -114,9 +101,8 @@
114 101 * Register our setting to WP
115 102 * @since 0.1.0
116 103 */
117 104 public function init() {
118 - $this->pro_plugin = is_plugin_active( 'wpgetapi-extras/wpgetapi-extras.php' ) ? true : false;
119 105 $option_tabs = self::option_fields();
120 106 foreach ($option_tabs as $index => $option_tab) {
121 107 register_setting( $option_tab['id'], $option_tab['id'] );
122 108 }
@@ -150,9 +136,9 @@
150 136 $option_metabox[] = array(
151 137 'title' => __( 'Setup', 'wpgetapi' ),
152 138 'menu_title' => __( 'Setup', 'wpgetapi' ),
153 139 'id' => 'wpgetapi_setup',
154 - 'desc' => __( 'Add the details of the API(s) you are using. Endpoints will be setup in the next step after hitting save.', 'wpgetapi' ),
140 + 'desc' => __( 'Add the details of each API you are using.', 'wpgetapi' ),
155 141 'show_on' => array( 'key' => 'options-page', 'value' => array( 'wpgetapi_setup' ), ),
156 142 'show_names' => true,
157 143 'fields' => $this->setup_fields(),
158 144 );
@@ -175,9 +161,9 @@
175 161 'id' => $metabox_id,
176 162 'desc' => '',
177 163 'show_on' => array( 'key' => 'options-page', 'value' => array( $metabox_id ), ),
178 164 'show_names' => true,
179 - 'fields' => $this->endpoint_fields( $type, $api_id, $base_url ),
165 + 'fields' => $this->api_fields( $type, $api_id, $base_url ),
180 166 );
181 167
182 168 }
183 169
@@ -203,9 +189,9 @@
203 189 'sortable' => true, // beta
204 190 ),
205 191 'fields' => array(
206 192 array(
207 - 'name' => __( 'API Name', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The name of this API. Call it whatever you like.', 'wpgetapi' ) . '"></span>',
193 + 'name' => __( 'API Name', 'wpgetapi' ),
208 194 'id' => 'name',
209 195 'type' => 'text',
210 196 'attributes' => array(
211 197 'required' => true,
@@ -210,12 +196,12 @@
210 196 'attributes' => array(
211 197 'required' => true,
212 198 'placeholder' => 'Google Maps',
213 199 ),
214 - 'desc' => '',
200 + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ),
215 201 ),
216 202 array(
217 - '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>',
203 + 'name' => __( 'Unique ID', 'wpgetapi' ),
218 204 'id' => 'id',
219 205 'type' => 'text',
220 206 'attributes' => array(
221 207 'required' => true,
@@ -220,20 +206,19 @@
220 206 'attributes' => array(
221 207 'required' => true,
222 208 'placeholder' => 'google_maps',
223 209 ),
224 - 'desc' => '',
225 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
210 + 'desc' => __( 'A unique ID for your API.', 'wpgetapi' ),
226 211 ),
227 212 array(
228 - 'name' => __( 'Base URL', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The base URL of the API you are connecting to.', 'wpgetapi' ) . '"></span>',
213 + 'name' => __( 'Base URL', 'wpgetapi' ),
229 214 'id' => 'base_url',
230 215 'type' => 'text',
231 216 'attributes' => array(
232 217 'required' => true,
233 - 'placeholder' => 'https://maps.googleapis.com/maps/api',
218 + 'placeholder' => 'http://maps.googleapis.com/maps/api',
234 219 ),
235 - 'desc' => '',
220 + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ),
236 221 ),
237 222
238 223 )
239 224 );
@@ -243,23 +228,19 @@
243 228 }
244 229
245 230
246 231 /**
247 - * Endpoint settings.
232 + * Site wide info on the current sale.
248 233 * @return sale info array
249 234 *
250 235 */
251 - public function endpoint_fields( $type = '', $api_id = '', $base_url = '' ) {
236 + public function api_fields( $type = '', $api_id = '', $base_url = '' ) {
252 237
253 238 $fields = array();
254 239
255 - $cache_disabled = $this->pro_plugin ? '' : 'disabled';
256 - $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>';
257 - $cache_desc = $this->pro_plugin ? '' : 'Available in PRO plugin.';
258 -
259 240 $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array(
260 241 array(
261 - '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>',
242 + 'name' => __( 'Unique ID', 'wpgetapi' ),
262 243 'id' => 'id',
263 244 'type' => 'text',
264 245 'classes' => 'field-id',
265 246 'attributes' => array(
@@ -265,16 +246,18 @@
265 246 'attributes' => array(
266 247 'required' => true,
267 248 'placeholder' => 'new_endpoint',
268 249 ),
269 - 'desc' => '',
270 - 'before_row' => "wpgetapi_output_top_of_endpoint",
271 - 'api_id' => $api_id,
272 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
273 -
250 + 'desc' => __( 'A unique ID for this endpoint.', 'wpgetapi' ),
251 + 'before_row' => "
252 + <pre class='functions'>
253 + Template Tag: </span><span>wpgetapi_endpoint( '" . $api_id . "', '<span class='endpoint_id'></span>', array('debug' => false) );</span><br>
254 + Shortcode: <span>[wpgetapi_endpoint api_id='" . $api_id . "' endpoint_id='<span class='endpoint_id'></span>' debug='false']</span>
255 + </pre>
256 + ",
274 257 ),
275 258 array(
276 - '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>',
259 + 'name' => __( 'Endpoint', 'wpgetapi' ),
277 260 'id' => 'endpoint',
278 261 'type' => 'text',
279 262 'classes' => 'field-endpoint',
280 263 'attributes' => array(
@@ -280,12 +263,12 @@
280 263 'attributes' => array(
281 264 'required' => true,
282 265 'placeholder' => '/newendpoint',
283 266 ),
284 - 'desc' => '',
267 + 'desc' => __( 'The endpoint that will be appended to the base URL.', 'wpgetapi' ),
285 268 ),
286 269 array(
287 - '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>',
270 + 'name' => __( 'Method', 'wpgetapi' ),
288 271 'id' => 'method',
289 272 'type' => 'select',
290 273 'classes' => 'field-method',
291 274 'attributes' => array(
@@ -293,23 +276,13 @@
293 276 ),
294 277 'options' => array(
295 278 'GET' => 'GET',
296 279 'POST' => 'POST',
297 - 'PUT' => 'PUT',
298 - 'PATCH' => 'PATCH',
299 - 'DELETE' => 'DELETE',
300 280 ),
301 - 'desc' => '',
281 + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ),
302 282 ),
303 -
304 283 array(
305 - 'name' => __( 'Results Format', 'wpgetapi' ) .
306 - '<span class="dashicons dashicons-editor-help" data-tip="' .
307 - sprintf(
308 - __( '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' ),
309 - 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>' )
310 - ) .
311 - '"></span>',
284 + 'name' => __( 'Results Format', 'wpgetapi' ),
312 285 'id' => 'results_format',
313 286 'type' => 'select',
314 287 'classes' => 'field-results-format',
315 288 'attributes' => array(
@@ -315,120 +288,55 @@
315 288 'attributes' => array(
316 289 'required' => true,
317 290 ),
318 291 'options_cb' => 'wpgetapi_results_format_options',
319 - 'desc' => ''
292 + 'desc' => __( 'The format of the results.', 'wpgetapi' ),
320 293 ),
321 -
322 294 array(
323 - 'name' => __( 'Cache Time', 'wpgetapi' ) .
324 - '<span class="dashicons dashicons-editor-help" data-tip="' .
325 - sprintf(
326 - __( 'The time in seconds to cache this request for. %1s', 'wpgetapi' ),
327 - htmlentities( '<br>' . $cache_url )
328 - ) .
329 - '"></span>',
330 - 'id' => 'cache_time',
331 - 'type' => 'text',
332 - 'classes' => 'field-cache-time',
333 - 'attributes' => array(
334 - 'placeholder' => '3600',
335 - $cache_disabled => $cache_disabled,
336 - ),
337 - 'desc' => $cache_desc
338 - ),
339 -
340 - array(
341 - 'name' => __( 'Query String', 'wpgetapi' ) .
342 - '<span class="dashicons dashicons-editor-help" data-tip="' .
343 - sprintf(
344 - __( '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' ),
345 - 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>' )
346 - ) .
347 - '"></span>',
295 + 'name' => __( 'Query String', 'wpgetapi' ),
348 296 'id' => 'query_parameters',
349 297 'type' => 'parameter',
350 298 'classes' => 'field-query-parameters',
351 299 'repeatable' => true,
352 - 'desc' => ''
300 + 'desc' => sprintf(
301 + __( 'Parameters as name/value pairs that will be appended to the URL. %1s', 'wpgetapi' ),
302 + '<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>'
303 + )
353 304 ),
354 305 array(
355 - 'name' => __( 'Headers', 'wpgetapi' ) .
356 - '<span class="dashicons dashicons-editor-help" data-tip="' .
357 - sprintf(
358 - __( 'Parameters as name/value pairs, sent in the Headers. %1s', 'wpgetapi' ),
359 - 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>' )
360 - ) .
361 - '"></span>',
306 + 'name' => __( 'Headers', 'wpgetapi' ),
362 307 'id' => 'header_parameters',
363 308 'type' => 'parameter',
364 309 'classes' => 'field-header-parameters',
365 310 'repeatable' => true,
366 - 'desc' => ''
311 + 'desc' => sprintf(
312 + __( 'Parameters as name/value pairs, sent in the headers. %1s', 'wpgetapi' ),
313 + '<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>'
314 + )
367 315 ),
368 316 array(
369 - 'name' => __( 'Body POST Fields', 'wpgetapi' ) .
370 - '<span class="dashicons dashicons-editor-help" data-tip="' .
371 - sprintf(
372 - __( 'Parameters as name/value pairs, sent in the Body as POST fields. %1s', 'wpgetapi' ),
373 - 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>' )
374 - ) .
375 - '"></span>',
317 + 'name' => __( 'Body POST Fields', 'wpgetapi' ),
376 318 'id' => 'body_parameters',
377 319 'type' => 'parameter',
378 320 'classes' => 'field-body-parameters',
379 321 'repeatable' => true,
380 - 'desc' => ''
322 + 'desc' => sprintf(
323 + __( 'Parameters as name/value pairs, sent in the body as POST fields. %1s', 'wpgetapi' ),
324 + '<a target="_blank" href="https://wpgetapi.com/docs/sending-headers-in-request/?utm_campaign=Body&utm_medium=Admin&utm_source=User">Help <span class="dashicons dashicons-external"></span></a>'
325 + )
381 326 ),
382 327 array(
383 - 'name' => __( 'Encode Body', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Encoding of the above Body parameters.', 'wpgetapi' ) . '"></span>',
328 + 'name' => __( 'Encode Body', 'wpgetapi' ),
384 329 'id' => 'body_json_encode',
385 330 'type' => 'select',
386 331 'classes' => 'field-body-json-encode',
387 - 'options' => array(
388 - 'false' => __( 'No encoding (raw)', 'wpgetapi' ),
389 - 'true' => __( 'JSON encode', 'wpgetapi' ),
390 - 'url' => __( 'URL encode (x-www-form-urlencoded)', 'wpgetapi' ),
391 - 'base64' => __( 'Base64 encode', 'wpgetapi' ),
392 - 'xml' => __( 'XML format (available in PRO)', 'wpgetapi' ),
393 -
332 + 'options' => array(
333 + 'false' => __( 'No encoding', 'wpgetapi' ),
334 + 'true' => __( 'JSON encode', 'wpgetapi' ),
335 + 'url' => __( 'URL encode', 'wpgetapi' ),
394 336 ),
395 - 'desc' => '',
337 + 'desc' => __( 'Should Body parameters be encoded (if set). ', 'wpgetapi' ),
396 338 ),
397 - array(
398 - 'name' => __( 'Actions', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' .
399 - sprintf(
400 - __( 'Call this endpoint when your chosen action runs. This feature is available in the PRO plugin. %1s', 'wpgetapi' ),
401 - 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>' )
402 - ) .
403 - '"></span>',
404 - 'id' => 'actions',
405 - 'type' => 'select',
406 - 'classes' => 'field-actions',
407 - 'desc' => __( 'Available in PRO plugin.', 'wpgetapi' ),
408 - 'options' => array(
409 - '' => __( '-- No Action --', 'wpgetapi-extras' ),
410 - 'new_post_published' => __( 'Post/Custom Post - New Post Published', 'wpgetapi-extras' ),
411 - 'transition_post_status' => __( 'Post/Custom Post - Status Changed', 'wpgetapi-extras' ),
412 - 'delete_post' => __( 'Post/Custom Post - Delete Post', 'wpgetapi-extras' ),
413 -
414 - 'user_register' => __( 'User - New User Registered', 'wpgetapi-extras' ),
415 - 'delete_user' => __( 'User - Delete User', 'wpgetapi-extras' ),
416 - 'user_login' => __( 'User - User Logs In', 'wpgetapi-extras' ),
417 - 'woocommerce_new_product' => __( 'WooCommerce - New Product Created', 'wpgetapi-extras' ),
418 - 'woocommerce_new_order' => __( 'WooCommerce - New Order Created', 'wpgetapi-extras' ),
419 - 'woocommerce_order_status_changed' => __( 'WooCommerce - Order Status Changed', 'wpgetapi-extras' ),
420 - 'contact_form_7' => __( 'Contact Form 7', 'wpgetapi-extras' ),
421 - 'gravity_forms' => __( 'Gravity Forms', 'wpgetapi-extras' ),
422 - 'wpforms' => __( 'WPForms', 'wpgetapi-extras' ),
423 - 'jetformbuilder' => __( 'JetFormBuilder', 'wpgetapi-extras' ),
424 - 'formidable_forms' => __( 'Formidable Forms', 'wpgetapi-extras' ),
425 - 'pmp' => __( 'Paid Memberships Pro - After Checkout', 'wpgetapi-extras' ),
426 - 'edd' => __( 'Easy Digital Downloads - Complete Purchase', 'wpgetapi-extras' ),
427 - ),
428 - 'default' => '',
429 - )
430 -
431 339 ) );
432 340
433 341
434 342 $fields[] = array(
@@ -457,9 +365,9 @@
457 365
458 366 foreach ($option_tabs as $index => $option_tab) {
459 367 if ( $index == 0) {
460 368
461 - $this->options_pages[] = add_menu_page( $this->title, $this->menu_title, 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ), 'none'
369 + $this->options_pages[] = add_menu_page( $this->title, $this->menu_title, 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ), 'dashicons-editor-code'
462 370 ); //Link admin menu to first tab
463 371
464 372 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
465 373 } else {
@@ -487,15 +395,12 @@
487 395 <div class="wrap wpgetapi">
488 396
489 397 <div class="main_content_cell">
490 398
491 - <h1 class="wp-heading-inline">
492 - <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>
493 - </h1>
399 + <h1 class="wp-heading-inline"><?php esc_html_e( $this->title, 'wpgetapi' ) ?></h1>
494 400 <!-- Options Page Nav Tabs -->
495 401 <h2 class="nav-tab-wrapper">
496 402 <?php foreach ($option_tabs as $option_tab) :
497 -
498 403 $tab_slug = $option_tab['id'];
499 404 $nav_class = 'nav-tab';
500 405 if ( $tab_slug == $_GET['page'] ) {
501 406 $nav_class .= ' nav-tab-active'; //add active class to current tab
@@ -500,20 +405,17 @@
500 405 if ( $tab_slug == $_GET['page'] ) {
501 406 $nav_class .= ' nav-tab-active'; //add active class to current tab
502 407 $tab_forms[] = $option_tab; //add current tab to forms to be rendered
503 408 }
504 -
505 - ?>
506 -
507 - <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>
508 -
409 + ?>
410 + <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>
509 411 <?php endforeach; ?>
510 412 </h2>
511 413 <!-- End of Nav Tabs -->
512 414
513 - <?php
514 - //render all tab forms (normaly just 1 form)
515 - foreach ($tab_forms as $tab_form) : ?>
415 + <?php foreach ($tab_forms as $tab_form) : //render all tab forms (normaly just 1 form)
416 +
417 + ?>
516 418
517 419 <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
518 420 <div class="metabox-holder">
519 421 <div class="pmpbox pad">
@@ -518,9 +420,9 @@
518 420 <div class="metabox-holder">
519 421 <div class="pmpbox pad">
520 422 <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
521 423 <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
522 - <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?>
424 + <?php cmb2_metabox_form( $tab_form, $tab_form['id'] ); ?>
523 425 </div>
524 426 </div>
525 427 </div>
526 428
@@ -543,74 +445,8 @@
543 445
544 446 }
545 447
546 448
547 - public function test_the_endpoint() {
548 -
549 - $api_id = sanitize_text_field( $_POST['api_id'] );
550 - $endpoint_id = sanitize_text_field( $_POST['endpoint_id'] );
551 - $data = wpgetapi_endpoint( $api_id, $endpoint_id, array( 'test_endpoint' => true ) );
552 -
553 - $output = array(
554 - 'data' => $data,
555 - 'endpoint_id' => $endpoint_id
556 - );
557 - echo json_encode( $output );
558 -
559 - wp_die(); // this is required to terminate immediately and return a proper response
560 -
561 - }
562 -
563 -
564 - public function load_testing_javascript() { ?>
565 -
566 - <script type="text/javascript" >
567 -
568 - jQuery(document).ready(function($) {
569 -
570 - $('body').on( 'click', '.wpgetapi-test-area .test-button', function(){//delegated
571 -
572 - var $this = $(this);
573 - var area = $this.parents( '.wpgetapi-test-area' );
574 - var api_id = $( area ).data( 'api' );
575 - var endpoint_id = $( area ).data( 'endpoint' );
576 -
577 - // disable button
578 - $this.attr( 'disabled', true );
579 -
580 - var data = {
581 - 'action': 'wpgetapi_test_endpoint',
582 - 'api_id': api_id,
583 - 'endpoint_id': endpoint_id
584 - };
585 -
586 - // send and get response
587 - jQuery.post(ajaxurl, data, function( response ) {
588 -
589 - var output = JSON.parse( response );
590 -
591 - jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show();
592 -
593 - jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( output.data);
594 -
595 - // enable button
596 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .test-button' ).attr( 'disabled', false );
597 -
598 - });
599 -
600 - });
601 -
602 - $( '.wpgetapi-test-area .handle' ).on('click', function() {
603 - $('.wpgetapi-result').toggle();
604 - });
605 -
606 - });
607 -
608 - </script> <?php
609 -
610 - }
611 -
612 -
613 449 /**
614 450 * Sidebar markup.
615 451 * @since 1.4.1
616 452 */
@@ -624,22 +460,44 @@
624 460
625 461 ?>
626 462
627 463 <div class="box">
628 - <h4><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h4>
464 + <h3><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h3>
629 465 <ol>
630 - <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
631 - <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li>
632 - <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li>
633 - <li><?php _e( 'Set the desired <b>Results Format</b>', 'wpgetapi' ); ?></li>
634 - <li><?php _e( 'Other fields are optional & will depend on your API', 'wpgetapi' ); ?></li>
635 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
636 - <li><?php _e( 'Copy the Template Tag or Shortcode & paste into page, post or theme file', 'wpgetapi' ); ?></li>
466 + <li><?php esc_html_e( 'Fill in the Unique ID and Endpoint.', 'wpgetapi' ); ?></li>
467 + <li><?php esc_html_e( 'Set the Method.', 'wpgetapi' ); ?></li>
468 + <li><?php esc_html_e( 'Set the desired Results Format.', 'wpgetapi' ); ?></li>
469 + <li><?php esc_html_e( 'The rest of the fields are optional and will depend on the API you using.', 'wpgetapi' ); ?></li>
470 + <li><?php esc_html_e( 'Hit the Save button.', 'wpgetapi' ); ?></li>
471 + <li><?php esc_html_e( 'After saving, copy the Template Tag or the Shortcode and paste into appropriate place.', 'wpgetapi' ); ?></li>
637 472 </ol>
638 473 </div>
639 -
640 - <?php echo $this->help_box(); ?>
474 +
475 + <hr>
476 +
477 + <div class="box">
478 + <strong><?php esc_html_e( 'Notes', 'wpgetapi' ); ?></strong>
479 + <ul>
480 + <li><?php esc_html_e( 'The Unique ID can be whatever you like. This is used to identify each endpoint within the plugin.', 'wpgetapi' ); ?></li>
481 + <li><?php esc_html_e( 'The Endpoint can be found in the documentation of your API.', 'wpgetapi' ); ?></li>
482 + </ul>
483 + </div>
641 484
485 + <hr>
486 +
487 + <div class="box">
488 + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong>
489 + <ul>
490 + <li><?php
491 + printf(
492 + esc_html__( 'Visit our website for guides on %1$s or %2$s.', 'cmb2' ),
493 + '<a target="_blank" href="https://wpgetapi.com/docs/using-the-shortcode/?utm_campaign=Shortcode&utm_medium=Admin&utm_source=User">Using the Shortcode</a>',
494 + '<a target="_blank" href="https://wpgetapi.com/docs/using-the-template-function/?utm_campaign=Template Tag&utm_medium=Admin&utm_source=User">Template Tag</a>'
495 + );
496 + ?></li>
497 + </ul>
498 + </div>
499 +
642 500 <?php
643 501 $content = ob_get_contents();
644 502 ob_end_clean();
645 503 return $content;
@@ -656,58 +514,38 @@
656 514 ob_start();
657 515 ?>
658 516
659 517 <div class="box">
660 - <h4><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h4>
518 + <h3><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h3>
661 519 <ol>
662 - <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li>
663 - <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
664 - <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li>
665 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
666 - <li><?php _e( 'Visit the new tab that will be created', 'wpgetapi' ); ?></li>
520 + <li><?php esc_html_e( 'Fill in the API Name, Unique ID and Base URL of your API.', 'wpgetapi' ); ?></li>
521 + <li><?php esc_html_e( 'Hit the Save button.', 'wpgetapi' ); ?></li>
522 + <li><?php esc_html_e( 'After saving, visit the new tab that will be created.', 'wpgetapi' ); ?></li>
667 523 </ol>
668 524 </div>
669 525
670 - <?php echo $this->help_box(); ?>
526 + <hr>
527 +
528 + <div class="box">
529 + <strong><?php esc_html_e( 'Notes', 'wpgetapi' ); ?></strong>
530 + <ul>
531 + <li><?php esc_html_e( 'The API Name and Unique ID can be whatever you like. These are used to identify each API within the plugin.', 'wpgetapi' ); ?></li>
532 + <li><?php esc_html_e( 'The Base URL can be found in the documentation of your API.', 'wpgetapi' ); ?></li>
533 + </ul>
534 + </div>
671 535
672 - <?php
673 - $content = ob_get_contents();
674 - ob_end_clean();
675 - return $content;
676 -
677 - }
678 -
679 -
680 - /**
681 - *
682 - * @since 1.4.4
683 - */
684 - public function help_box() {
685 -
686 - ob_start();
687 - ?>
688 -
689 536 <hr>
690 537
691 - <div class="box help-box">
692 - <h4><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></h4>
538 + <div class="box">
539 + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong>
693 540 <ul>
694 - <li><?php
541 + <li><?php
695 542 printf(
696 - esc_html__( 'View the %1$s', 'cmb2' ),
697 - '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">Quick Start Guide</a>'
543 + esc_html__( 'Visit our website to view %1$s or %2$s.', 'cmb2' ),
544 + '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Quick Start&utm_medium=Admin&utm_source=User">Quick Start Guide</a>',
545 + '<a target="_blank" href="https://wpgetapi.com/docs/step-by-step-example/?utm_campaign=Step by Step&utm_medium=Admin&utm_source=User">Step by Step Example</a>'
698 546 );
699 547 ?></li>
700 - <li><?php
701 - printf(
702 - esc_html__( 'View the %1$s', 'cmb2' ),
703 - '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>'
704 - );
705 - ?></li>
706 -
707 - <?php if( ! $this->pro_plugin ) { ?>
708 - <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>
709 - <?php } ?>
710 548 </ul>
711 549 </div>
712 550
713 551 <?php
@@ -716,30 +554,19 @@
716 554 return $content;
717 555
718 556 }
719 557
720 -
721 558 /**
722 559 * Tabs don't immmediately appear on save, so this hack!
723 560 * @since 0.1.0
724 561 */
725 562 public function redirect( $object_id, $updated ) {
726 -
727 - if( strpos( $object_id, 'wpgetapi_' ) !== false && strpos( $object_id, 'wpgetapi_api_importer' ) == false ) {
728 -
729 - add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' );
563 + if( $object_id == 'wpgetapi_setup' ) {
564 + add_settings_error( 'wpgetapi-notices', '', 'Settings saved.', 'updated' );
730 565 settings_errors( 'wpgetapi-notices' );
731 - ?>
732 -
733 - <script>
734 - setTimeout(function() {
735 - location.reload();
736 - }, 200);
737 - </script>
738 - <?php
739 -
740 - }
741 -
566 + wp_redirect( admin_url( 'admin.php?page=' . $object_id ) );
567 + exit;
568 + }
742 569 }
743 570
744 571
745 572 /**