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 +113 -483 2.1.01.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,20 +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 -
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 -
88 + add_action( "cmb2_save_options-page_fields", array( $this, 'redirect' ), 98, 2 );
104 89 }
105 90
106 -
107 91 /**
108 92 * Setup our custom fields
109 93 * @since 0.1.0
110 94 */
@@ -117,9 +101,8 @@
117 101 * Register our setting to WP
118 102 * @since 0.1.0
119 103 */
120 104 public function init() {
121 - $this->pro_plugin = is_plugin_active( 'wpgetapi-extras/wpgetapi-extras.php' ) ? true : false;
122 105 $option_tabs = self::option_fields();
123 106 foreach ($option_tabs as $index => $option_tab) {
124 107 register_setting( $option_tab['id'], $option_tab['id'] );
125 108 }
@@ -153,9 +136,9 @@
153 136 $option_metabox[] = array(
154 137 'title' => __( 'Setup', 'wpgetapi' ),
155 138 'menu_title' => __( 'Setup', 'wpgetapi' ),
156 139 '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' ),
140 + 'desc' => __( 'Add the details of each API you are using.', 'wpgetapi' ),
158 141 'show_on' => array( 'key' => 'options-page', 'value' => array( 'wpgetapi_setup' ), ),
159 142 'show_names' => true,
160 143 'fields' => $this->setup_fields(),
161 144 );
@@ -178,9 +161,9 @@
178 161 'id' => $metabox_id,
179 162 'desc' => '',
180 163 'show_on' => array( 'key' => 'options-page', 'value' => array( $metabox_id ), ),
181 164 'show_names' => true,
182 - 'fields' => $this->endpoint_fields( $type, $api_id, $base_url ),
165 + 'fields' => $this->api_fields( $type, $api_id, $base_url ),
183 166 );
184 167
185 168 }
186 169
@@ -206,9 +189,9 @@
206 189 'sortable' => true, // beta
207 190 ),
208 191 'fields' => array(
209 192 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>',
193 + 'name' => __( 'API Name', 'wpgetapi' ),
211 194 'id' => 'name',
212 195 'type' => 'text',
213 196 'attributes' => array(
214 197 'required' => true,
@@ -213,12 +196,12 @@
213 196 'attributes' => array(
214 197 'required' => true,
215 198 'placeholder' => 'Google Maps',
216 199 ),
217 - 'desc' => '',
200 + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ),
218 201 ),
219 202 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>',
203 + 'name' => __( 'Unique ID', 'wpgetapi' ),
221 204 'id' => 'id',
222 205 'type' => 'text',
223 206 'attributes' => array(
224 207 'required' => true,
@@ -223,20 +206,19 @@
223 206 'attributes' => array(
224 207 'required' => true,
225 208 'placeholder' => 'google_maps',
226 209 ),
227 - 'desc' => '',
228 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
210 + 'desc' => __( 'A unique ID for your API.', 'wpgetapi' ),
229 211 ),
230 212 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>',
213 + 'name' => __( 'Base URL', 'wpgetapi' ),
232 214 'id' => 'base_url',
233 215 'type' => 'text',
234 216 'attributes' => array(
235 217 'required' => true,
236 - 'placeholder' => 'https://maps.googleapis.com/maps/api',
218 + 'placeholder' => 'http://maps.googleapis.com/maps/api',
237 219 ),
238 - 'desc' => '',
220 + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ),
239 221 ),
240 222
241 223 )
242 224 );
@@ -246,23 +228,19 @@
246 228 }
247 229
248 230
249 231 /**
250 - * Endpoint settings.
232 + * Site wide info on the current sale.
251 233 * @return sale info array
252 234 *
253 235 */
254 - public function endpoint_fields( $type = '', $api_id = '', $base_url = '' ) {
236 + public function api_fields( $type = '', $api_id = '', $base_url = '' ) {
255 237
256 238 $fields = array();
257 239
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 -
262 240 $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array(
263 241 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>',
242 + 'name' => __( 'Unique ID', 'wpgetapi' ),
265 243 'id' => 'id',
266 244 'type' => 'text',
267 245 'classes' => 'field-id',
268 246 'attributes' => array(
@@ -268,16 +246,18 @@
268 246 'attributes' => array(
269 247 'required' => true,
270 248 'placeholder' => 'new_endpoint',
271 249 ),
272 - 'desc' => '',
273 - 'before_row' => "wpgetapi_output_top_of_endpoint",
274 - 'api_id' => $api_id,
275 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
276 -
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 + ",
277 257 ),
278 258 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>',
259 + 'name' => __( 'Endpoint', 'wpgetapi' ),
280 260 'id' => 'endpoint',
281 261 'type' => 'text',
282 262 'classes' => 'field-endpoint',
283 263 'attributes' => array(
@@ -283,12 +263,12 @@
283 263 'attributes' => array(
284 264 'required' => true,
285 265 'placeholder' => '/newendpoint',
286 266 ),
287 - 'desc' => '',
267 + 'desc' => __( 'The endpoint that will be appended to the base URL.', 'wpgetapi' ),
288 268 ),
289 269 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>',
270 + 'name' => __( 'Method', 'wpgetapi' ),
291 271 'id' => 'method',
292 272 'type' => 'select',
293 273 'classes' => 'field-method',
294 274 'attributes' => array(
@@ -296,23 +276,13 @@
296 276 ),
297 277 'options' => array(
298 278 'GET' => 'GET',
299 279 'POST' => 'POST',
300 - 'PUT' => 'PUT',
301 - 'PATCH' => 'PATCH',
302 - 'DELETE' => 'DELETE',
303 280 ),
304 - 'desc' => '',
281 + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ),
305 282 ),
306 -
307 283 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>',
284 + 'name' => __( 'Results Format', 'wpgetapi' ),
315 285 'id' => 'results_format',
316 286 'type' => 'select',
317 287 'classes' => 'field-results-format',
318 288 'attributes' => array(
@@ -318,123 +288,58 @@
318 288 'attributes' => array(
319 289 'required' => true,
320 290 ),
321 291 'options_cb' => 'wpgetapi_results_format_options',
322 - 'desc' => ''
292 + 'desc' => __( 'The format of the results.', 'wpgetapi' ),
323 293 ),
324 -
325 294 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>',
295 + 'name' => __( 'Query String', 'wpgetapi' ),
351 296 'id' => 'query_parameters',
352 297 'type' => 'parameter',
353 298 'classes' => 'field-query-parameters',
354 299 'repeatable' => true,
355 - '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 + )
356 304 ),
357 305 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>',
306 + 'name' => __( 'Headers', 'wpgetapi' ),
365 307 'id' => 'header_parameters',
366 308 'type' => 'parameter',
367 309 'classes' => 'field-header-parameters',
368 310 'repeatable' => true,
369 - '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 + )
370 315 ),
371 316 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>',
317 + 'name' => __( 'Body POST Fields', 'wpgetapi' ),
379 318 'id' => 'body_parameters',
380 319 'type' => 'parameter',
381 320 'classes' => 'field-body-parameters',
382 321 'repeatable' => true,
383 - '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 + )
384 326 ),
385 327 array(
386 - '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' ),
387 329 'id' => 'body_json_encode',
388 330 'type' => 'select',
389 331 '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 -
332 + 'options' => array(
333 + 'false' => __( 'No encoding', 'wpgetapi' ),
334 + 'true' => __( 'JSON encode', 'wpgetapi' ),
335 + 'url' => __( 'URL encode', 'wpgetapi' ),
397 336 ),
398 - 'desc' => '',
337 + 'desc' => __( 'Should Body parameters be encoded (if set). ', 'wpgetapi' ),
399 338 ),
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' ),
339 + ) );
416 340
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 341
434 - ) );
435 -
436 -
437 342 $fields[] = array(
438 343 'id' => 'endpoints',
439 344 'type' => 'group',
440 345 'name' => '',
@@ -444,9 +349,9 @@
444 349 'add_button' => __( 'Add Endpoint', 'wpgetapi' ),
445 350 'remove_button' => __( 'Remove Endpoint', 'wpgetapi' ),
446 351 'sortable' => true, // beta
447 352 ),
448 - 'before_group' => '<pre class="url"><div>Base URL:</div> <span>' . $base_url . '</span></pre><div class="import-export"><a href="#TB_inline?&width=600&height=550&inlineId=my-content-id" class="button thickbox">Import/Export</a></div>',
353 + 'before_group' => '<pre class="url">Base URL: <span>' . $base_url . '</span></pre>',
449 354 'fields' => $endpoint_fields,
450 355 );
451 356
452 357 return apply_filters( 'wpgetapi_fields', $fields );
@@ -454,9 +359,8 @@
454 359 }
455 360
456 361
457 362 public function add_options_pages() {
458 - add_thickbox();
459 363
460 364 $option_tabs = self::option_fields();
461 365
462 366 foreach ($option_tabs as $index => $option_tab) {
@@ -461,9 +365,9 @@
461 365
462 366 foreach ($option_tabs as $index => $option_tab) {
463 367 if ( $index == 0) {
464 368
465 - $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'
466 370 ); //Link admin menu to first tab
467 371
468 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
469 373 } else {
@@ -491,15 +395,12 @@
491 395 <div class="wrap wpgetapi">
492 396
493 397 <div class="main_content_cell">
494 398
495 - <h1 class="wp-heading-inline">
496 - <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>
497 - </h1>
399 + <h1 class="wp-heading-inline"><?php esc_html_e( $this->title, 'wpgetapi' ) ?></h1>
498 400 <!-- Options Page Nav Tabs -->
499 401 <h2 class="nav-tab-wrapper">
500 402 <?php foreach ($option_tabs as $option_tab) :
501 -
502 403 $tab_slug = $option_tab['id'];
503 404 $nav_class = 'nav-tab';
504 405 if ( $tab_slug == $_GET['page'] ) {
505 406 $nav_class .= ' nav-tab-active'; //add active class to current tab
@@ -504,34 +405,24 @@
504 405 if ( $tab_slug == $_GET['page'] ) {
505 406 $nav_class .= ' nav-tab-active'; //add active class to current tab
506 407 $tab_forms[] = $option_tab; //add current tab to forms to be rendered
507 408 }
508 -
509 - ?>
510 -
511 - <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>
512 -
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>
513 411 <?php endforeach; ?>
514 412 </h2>
515 413 <!-- End of Nav Tabs -->
516 414
517 - <?php
518 - //render all tab forms (normaly just 1 form)
519 - foreach ($tab_forms as $tab_form) : ?>
415 + <?php foreach ($tab_forms as $tab_form) : //render all tab forms (normaly just 1 form)
416 +
417 + ?>
520 418
521 419 <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
522 420 <div class="metabox-holder">
523 -
524 - <div id="my-content-id" style="display:none;">
525 - <div>
526 - <?php echo $this->get_import_export(); ?>
527 - </div>
528 - </div>
529 -
530 421 <div class="pmpbox pad">
531 422 <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
532 423 <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
533 - <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?>
424 + <?php cmb2_metabox_form( $tab_form, $tab_form['id'] ); ?>
534 425 </div>
535 426 </div>
536 427 </div>
537 428
@@ -554,261 +445,9 @@
554 445
555 446 }
556 447
557 448
558 -
559 - public function test_the_endpoint() {
560 -
561 - $api_id = sanitize_text_field( $_POST['api_id'] );
562 - $endpoint_id = sanitize_text_field( $_POST['endpoint_id'] );
563 - $data = wpgetapi_endpoint( $api_id, $endpoint_id, array( 'test_endpoint' => true ) );
564 -
565 - $output = array(
566 - 'data' => $data,
567 - 'endpoint_id' => $endpoint_id
568 - );
569 - echo json_encode( $output );
570 -
571 - wp_die(); // this is required to terminate immediately and return a proper response
572 -
573 - }
574 -
575 - public function get_import_export() {
576 - ob_start(); ?>
577 -
578 - <div class="wpgetapi-export">
579 - <h3><span class="dashicons dashicons-download"></span> Export Endpoints</h3>
580 - <p>Export the endpoints for this API.<br>After clicking the button below, copy the entire contents of the export.</p>
581 - <button class="button button-primary">Export Endpoints</button>
582 - <div class="message"></div>
583 - </div>
584 -
585 - <div class="wpgetapi-import">
586 - <h3><span class="dashicons dashicons-upload"></span> Import Endpoints</h3>
587 - <p>Paste your exported JSON data into the field below to import endpoints into this API.</p>
588 - <textarea></textarea>
589 - <button class="button button-primary">Import Endpoints</button>
590 - <div class="message"></div>
591 - </div>
592 -
593 - <?php
594 - $content = ob_get_contents();
595 - ob_end_clean();
596 - return $content;
597 - }
598 -
599 449 /**
600 - * AJAX function to get our endpoints for export.
601 - *
602 - */
603 - public function export_endpoints() {
604 - $api_id = sanitize_text_field( $_POST['api_id'] );
605 - $data = get_option( $api_id );
606 -
607 - if( ! isset( $data['endpoints'] ) )
608 - wp_die();
609 -
610 - $encryption = new WpGetApi_Encryption();
611 -
612 - foreach ( $data['endpoints'] as $i => $endpoint ) {
613 - if( isset( $endpoint['query_parameters'] ) ) {
614 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
615 - if( isset( $query_parameters['value'] ) )
616 - $data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->decrypt( $query_parameters['value'] );
617 - }
618 - }
619 - if( isset( $endpoint['header_parameters'] ) ) {
620 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
621 - if( isset( $header_parameters['value'] ) )
622 - $data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->decrypt( $header_parameters['value'] );
623 - }
624 - }
625 - if( isset( $endpoint['body_parameters'] ) ) {
626 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
627 - if( isset( $body_parameters['value'] ) )
628 - $data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->decrypt( $body_parameters['value'] );
629 - }
630 - }
631 - }
632 -
633 - echo json_encode( $data );
634 - wp_die(); // this is required to terminate immediately and return a proper response
635 - }
636 -
637 - /**
638 - * AJAX function to import our endpoints.
639 - *
640 - */
641 - public function import_endpoints() {
642 -
643 - $api_id = sanitize_text_field( $_POST['api_id'] );
644 - $textarea = sanitize_textarea_field( $_POST['textarea'] );
645 - $existing_data = get_option( $api_id );
646 -
647 - if( ! $textarea ) {
648 - echo 'No data found.';
649 - wp_die();
650 - }
651 -
652 - $new_data = json_decode( stripslashes( $textarea ), true );
653 - if( ! isset( $new_data['endpoints'] ) ){
654 - echo 'No endpoints found.';
655 - wp_die();
656 - }
657 -
658 - $encryption = new WpGetApi_Encryption();
659 -
660 - foreach ( $new_data['endpoints'] as $i => $endpoint ) {
661 - if( isset( $endpoint['query_parameters'] ) ) {
662 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
663 - if( isset( $query_parameters['value'] ) )
664 - $new_data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->encrypt( $query_parameters['value'] );
665 - }
666 - }
667 - if( isset( $endpoint['header_parameters'] ) ) {
668 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
669 - if( isset( $header_parameters['value'] ) )
670 - $new_data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->encrypt( $header_parameters['value'] );
671 - }
672 - }
673 - if( isset( $endpoint['body_parameters'] ) ) {
674 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
675 - if( isset( $body_parameters['value'] ) )
676 - $new_data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->encrypt( $body_parameters['value'] );
677 - }
678 - }
679 - }
680 -
681 - // if no existing endpoints, simply add it
682 - if( ! $existing_data ) {
683 - update_option( $api_id, $new_data );
684 - } else {
685 -
686 - $merged['endpoints'] = array_merge( $existing_data['endpoints'], $new_data['endpoints'] );
687 - update_option( $api_id, $merged );
688 - }
689 -
690 - echo 'Successfully imported. Reloading...';
691 - wp_die(); // this is required to terminate immediately and return a proper response
692 - }
693 -
694 -
695 - public function load_testing_javascript() { ?>
696 -
697 - <script type="text/javascript" >
698 -
699 - jQuery(document).ready(function($) {
700 -
701 - /**
702 - * Run the export
703 - *
704 - */
705 - $('body').on( 'click', '.wpgetapi-export .button', function(){
706 -
707 - var $this = $(this);
708 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
709 -
710 - // disable button
711 - $this.attr( 'disabled', true );
712 -
713 - var data = {
714 - 'action': 'wpgetapi_export_endpoints',
715 - 'api_id': api_id,
716 - };
717 -
718 - // send and get response
719 - jQuery.post(ajaxurl, data, function( response ) {
720 - $( '.wpgetapi-export .message' ).show().html( response );
721 - // enable button
722 - $( '.wpgetapi-export .button' ).attr( 'disabled', false );
723 -
724 - });
725 -
726 - });
727 -
728 - /**
729 - * Run the import
730 - *
731 - */
732 - $('body').on( 'click', '.wpgetapi-import .button', function(){
733 -
734 - var $this = $(this);
735 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
736 - var textarea = $('.wpgetapi-import textarea').val();
737 -
738 - // disable button
739 - $this.attr( 'disabled', true );
740 -
741 - var data = {
742 - 'action': 'wpgetapi_import_endpoints',
743 - 'textarea': textarea,
744 - 'api_id': api_id,
745 - };
746 -
747 - // send and get response
748 - jQuery.post(ajaxurl, data, function( response ) {
749 -
750 - $( '.wpgetapi-import .message' ).html( response );
751 -
752 - if( response == 'Successfully imported. Reloading...' ) {
753 - setTimeout(function(){
754 - location.reload();
755 - }, 2000);
756 - } else {
757 - $( '.wpgetapi-import .button' ).attr( 'disabled', false );
758 - }
759 -
760 - });
761 -
762 - });
763 -
764 - /**
765 - * Run the endpoint test
766 - *
767 - */
768 - $('body').on( 'click', '.wpgetapi-test-area .test-button', function(){//delegated
769 -
770 - var $this = $(this);
771 - var area = $this.parents( '.wpgetapi-test-area' );
772 - var api_id = $( area ).data( 'api' );
773 - var endpoint_id = $( area ).data( 'endpoint' );
774 -
775 - // disable button
776 - $this.attr( 'disabled', true );
777 -
778 - var data = {
779 - 'action': 'wpgetapi_test_endpoint',
780 - 'api_id': api_id,
781 - 'endpoint_id': endpoint_id
782 - };
783 -
784 - // send and get response
785 - jQuery.post(ajaxurl, data, function( response ) {
786 -
787 - var output = JSON.parse( response );
788 -
789 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show();
790 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( output.data);
791 -
792 - // enable button
793 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .test-button' ).attr( 'disabled', false );
794 -
795 - });
796 -
797 - });
798 -
799 - $( '.wpgetapi-test-area .handle' ).on('click', function() {
800 - $('.wpgetapi-result').toggle();
801 - });
802 -
803 - });
804 -
805 - </script> <?php
806 -
807 - }
808 -
809 -
810 - /**
811 450 * Sidebar markup.
812 451 * @since 1.4.1
813 452 */
814 453 public function sidebar_display() {
@@ -821,22 +460,44 @@
821 460
822 461 ?>
823 462
824 463 <div class="box">
825 - <h4><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h4>
464 + <h3><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h3>
826 465 <ol>
827 - <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
828 - <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li>
829 - <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li>
830 - <li><?php _e( 'Set the desired <b>Results Format</b>', 'wpgetapi' ); ?></li>
831 - <li><?php _e( 'Other fields are optional & will depend on your API', 'wpgetapi' ); ?></li>
832 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
833 - <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>
834 472 </ol>
835 473 </div>
836 -
837 - <?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>
838 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 +
839 500 <?php
840 501 $content = ob_get_contents();
841 502 ob_end_clean();
842 503 return $content;
@@ -853,58 +514,38 @@
853 514 ob_start();
854 515 ?>
855 516
856 517 <div class="box">
857 - <h4><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h4>
518 + <h3><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h3>
858 519 <ol>
859 - <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li>
860 - <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
861 - <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li>
862 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
863 - <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>
864 523 </ol>
865 524 </div>
866 525
867 - <?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>
868 535
869 - <?php
870 - $content = ob_get_contents();
871 - ob_end_clean();
872 - return $content;
873 -
874 - }
875 -
876 -
877 - /**
878 - *
879 - * @since 1.4.4
880 - */
881 - public function help_box() {
882 -
883 - ob_start();
884 - ?>
885 -
886 536 <hr>
887 537
888 - <div class="box help-box">
889 - <h4><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></h4>
538 + <div class="box">
539 + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong>
890 540 <ul>
891 - <li><?php
541 + <li><?php
892 542 printf(
893 - esc_html__( 'View the %1$s', 'cmb2' ),
894 - '<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>'
895 546 );
896 547 ?></li>
897 - <li><?php
898 - printf(
899 - esc_html__( 'View the %1$s', 'cmb2' ),
900 - '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>'
901 - );
902 - ?></li>
903 -
904 - <?php if( ! $this->pro_plugin ) { ?>
905 - <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>
906 - <?php } ?>
907 548 </ul>
908 549 </div>
909 550
910 551 <?php
@@ -913,30 +554,19 @@
913 554 return $content;
914 555
915 556 }
916 557
917 -
918 558 /**
919 559 * Tabs don't immmediately appear on save, so this hack!
920 560 * @since 0.1.0
921 561 */
922 562 public function redirect( $object_id, $updated ) {
923 -
924 - if( strpos( $object_id, 'wpgetapi_' ) !== false && strpos( $object_id, 'wpgetapi_api_importer' ) == false ) {
925 -
926 - add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' );
563 + if( $object_id == 'wpgetapi_setup' ) {
564 + add_settings_error( 'wpgetapi-notices', '', 'Settings saved.', 'updated' );
927 565 settings_errors( 'wpgetapi-notices' );
928 - ?>
929 -
930 - <script>
931 - setTimeout(function() {
932 - location.reload();
933 - }, 200);
934 - </script>
935 - <?php
936 -
937 - }
938 -
566 + wp_redirect( admin_url( 'admin.php?page=' . $object_id ) );
567 + exit;
568 + }
939 569 }
940 570
941 571
942 572 /**