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 +138 -576 2.2.31.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,20 +189,19 @@
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 - 'classes' => 'api-name',
214 196 'attributes' => array(
215 197 'required' => true,
216 198 'placeholder' => 'Google Maps',
217 199 ),
218 - 'desc' => '',
200 + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ),
219 201 ),
220 202 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>',
203 + 'name' => __( 'Unique ID', 'wpgetapi' ),
222 204 'id' => 'id',
223 205 'type' => 'text',
224 206 'attributes' => array(
225 207 'required' => true,
@@ -224,20 +206,19 @@
224 206 'attributes' => array(
225 207 'required' => true,
226 208 'placeholder' => 'google_maps',
227 209 ),
228 - 'desc' => '',
229 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
210 + 'desc' => __( 'A unique ID for your API.', 'wpgetapi' ),
230 211 ),
231 212 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>',
213 + 'name' => __( 'Base URL', 'wpgetapi' ),
233 214 'id' => 'base_url',
234 215 'type' => 'text',
235 216 'attributes' => array(
236 217 'required' => true,
237 - 'placeholder' => 'https://maps.googleapis.com/maps/api',
218 + 'placeholder' => 'http://maps.googleapis.com/maps/api',
238 219 ),
239 - 'desc' => '',
220 + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ),
240 221 ),
241 222
242 223 )
243 224 );
@@ -247,52 +228,50 @@
247 228 }
248 229
249 230
250 231 /**
251 - * Endpoint settings.
232 + * Site wide info on the current sale.
252 233 * @return sale info array
253 234 *
254 235 */
255 - public function endpoint_fields( $type = '', $api_id = '', $base_url = '' ) {
236 + public function api_fields( $type = '', $api_id = '', $base_url = '' ) {
256 237
257 238 $fields = array();
258 239
259 - $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.';
262 -
263 240 $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array(
264 241 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>',
242 + 'name' => __( 'Unique ID', 'wpgetapi' ),
266 243 'id' => 'id',
267 244 'type' => 'text',
268 - 'classes' => 'field-id field-half',
245 + 'classes' => 'field-id',
269 246 'attributes' => array(
270 247 'required' => true,
271 248 'placeholder' => 'new_endpoint',
272 249 ),
273 - 'desc' => '',
274 - 'before_row' => "wpgetapi_output_top_of_endpoint",
275 - 'api_id' => $api_id,
276 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
277 -
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 + ",
278 257 ),
279 258 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>',
259 + 'name' => __( 'Endpoint', 'wpgetapi' ),
281 260 'id' => 'endpoint',
282 261 'type' => 'text',
283 - 'classes' => 'field-endpoint field-half',
262 + 'classes' => 'field-endpoint',
284 263 'attributes' => array(
285 264 'required' => true,
286 265 'placeholder' => '/newendpoint',
287 266 ),
288 - 'desc' => '',
267 + 'desc' => __( 'The endpoint that will be appended to the base URL.', 'wpgetapi' ),
289 268 ),
290 269 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>',
270 + 'name' => __( 'Method', 'wpgetapi' ),
292 271 'id' => 'method',
293 272 'type' => 'select',
294 - 'classes' => 'field-method field-half',
273 + 'classes' => 'field-method',
295 274 'attributes' => array(
296 275 'required' => true,
297 276 ),
298 277 'options' => array(
@@ -297,160 +276,70 @@
297 276 ),
298 277 'options' => array(
299 278 'GET' => 'GET',
300 279 'POST' => 'POST',
301 - 'PUT' => 'PUT',
302 - 'PATCH' => 'PATCH',
303 - 'DELETE' => 'DELETE',
304 280 ),
305 - 'desc' => '',
281 + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ),
306 282 ),
307 -
308 283 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>',
284 + 'name' => __( 'Results Format', 'wpgetapi' ),
316 285 'id' => 'results_format',
317 286 'type' => 'select',
318 - 'classes' => 'field-results-format field-half',
287 + 'classes' => 'field-results-format',
319 288 'attributes' => array(
320 289 'required' => true,
321 290 ),
322 291 'options_cb' => 'wpgetapi_results_format_options',
323 - 'desc' => ''
292 + 'desc' => __( 'The format of the results.', 'wpgetapi' ),
324 293 ),
325 -
326 294 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>',
347 - 'id' => 'cache_time',
348 - 'type' => 'text',
349 - 'classes' => 'field-cache-time field-half',
350 - 'attributes' => array(
351 - 'placeholder' => '3600',
352 - $cache_disabled => $cache_disabled,
353 - ),
354 - 'desc' => $cache_desc,
355 - 'after_row' => '</div>'
356 - ),
357 -
358 - 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>',
295 + 'name' => __( 'Query String', 'wpgetapi' ),
366 296 'id' => 'query_parameters',
367 297 'type' => 'parameter',
368 298 'classes' => 'field-query-parameters',
369 299 'repeatable' => true,
370 - 'desc' => '',
371 - 'before_row' => '<div class="fields-wrapper">'
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 + )
372 304 ),
373 305 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>',
306 + 'name' => __( 'Headers', 'wpgetapi' ),
381 307 'id' => 'header_parameters',
382 308 'type' => 'parameter',
383 309 'classes' => 'field-header-parameters',
384 310 'repeatable' => true,
385 - '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 + )
386 315 ),
387 316 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>',
317 + 'name' => __( 'Body POST Fields', 'wpgetapi' ),
395 318 'id' => 'body_parameters',
396 319 'type' => 'parameter',
397 320 'classes' => 'field-body-parameters',
398 321 'repeatable' => true,
399 - '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 + )
400 326 ),
401 327 array(
402 - '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' ),
403 329 'id' => 'body_json_encode',
404 330 'type' => 'select',
405 331 'classes' => 'field-body-json-encode',
406 - '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 -
332 + 'options' => array(
333 + 'false' => __( 'No encoding', 'wpgetapi' ),
334 + 'true' => __( 'JSON encode', 'wpgetapi' ),
335 + 'url' => __( 'URL encode', 'wpgetapi' ),
413 336 ),
414 - 'desc' => '',
415 - 'after_row' => '</div>',
337 + 'desc' => __( 'Should Body parameters be encoded (if set). ', 'wpgetapi' ),
416 338 ),
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' ),
339 + ) );
433 340
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 341
451 - ) );
452 -
453 342 $fields[] = array(
454 343 'id' => 'endpoints',
455 344 'type' => 'group',
456 345 'name' => '',
@@ -459,13 +348,10 @@
459 348 'group_title' => __( 'Endpoint {#}', 'wpgetapi' ),
460 349 'add_button' => __( 'Add Endpoint', 'wpgetapi' ),
461 350 'remove_button' => __( 'Remove Endpoint', 'wpgetapi' ),
462 351 'sortable' => true, // beta
463 - //'closed' => true,
464 352 ),
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>',
353 + 'before_group' => '<pre class="url">Base URL: <span>' . $base_url . '</span></pre>',
468 354 'fields' => $endpoint_fields,
469 355 );
470 356
471 357 return apply_filters( 'wpgetapi_fields', $fields );
@@ -473,9 +359,8 @@
473 359 }
474 360
475 361
476 362 public function add_options_pages() {
477 - add_thickbox();
478 363
479 364 $option_tabs = self::option_fields();
480 365
481 366 foreach ($option_tabs as $index => $option_tab) {
@@ -480,9 +365,9 @@
480 365
481 366 foreach ($option_tabs as $index => $option_tab) {
482 367 if ( $index == 0) {
483 368
484 - $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'
485 370 ); //Link admin menu to first tab
486 371
487 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
488 373 } else {
@@ -504,69 +389,46 @@
504 389 public function admin_page_display() {
505 390
506 391 $option_tabs = self::option_fields(); //get all option tabs
507 392 $tab_forms = array();
508 -
509 - $l = '';
510 - if( $this->pro_plugin ) {
511 - $l = get_option( 'wpgetapi_pro_license_status' );
512 - }
513 -
514 393 ?>
515 394
516 - <div class="wrap wpgetapi <?php esc_attr_e( $l ); ?>">
395 + <div class="wrap wpgetapi">
517 396
518 397 <div class="main_content_cell">
519 398
520 - <h1 class="wp-heading-inline">
521 - <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 - </h1>
399 + <h1 class="wp-heading-inline"><?php esc_html_e( $this->title, 'wpgetapi' ) ?></h1>
400 + <!-- Options Page Nav Tabs -->
401 + <h2 class="nav-tab-wrapper">
402 + <?php foreach ($option_tabs as $option_tab) :
403 + $tab_slug = $option_tab['id'];
404 + $nav_class = 'nav-tab';
405 + if ( $tab_slug == $_GET['page'] ) {
406 + $nav_class .= ' nav-tab-active'; //add active class to current tab
407 + $tab_forms[] = $option_tab; //add current tab to forms to be rendered
408 + }
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>
411 + <?php endforeach; ?>
412 + </h2>
413 + <!-- End of Nav Tabs -->
523 414
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 - }
415 + <?php foreach ($tab_forms as $tab_form) : //render all tab forms (normaly just 1 form)
535 416
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>
539 -
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>
417 + ?>
418 +
419 + <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
420 + <div class="metabox-holder">
421 + <div class="pmpbox pad">
422 + <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
423 + <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
424 + <?php cmb2_metabox_form( $tab_form, $tab_form['id'] ); ?>
562 425 </div>
563 426 </div>
427 + </div>
564 428
565 - <?php endforeach; ?>
429 + <?php endforeach; ?>
566 430
567 - </div>
568 -
569 431 </div>
570 432
571 433 <div class="sidebar_cell">
572 434
@@ -583,302 +445,9 @@
583 445
584 446 }
585 447
586 448
587 - public function test_the_endpoint() {
588 -
589 - $api_id = sanitize_text_field( $_POST['api_id'] );
590 - $endpoint_id = sanitize_text_field( $_POST['endpoint_id'] );
591 - $data = wpgetapi_endpoint( $api_id, $endpoint_id, array( 'test_endpoint' => true ) );
592 -
593 - $output = array(
594 - 'data' => $data,
595 - 'endpoint_id' => $endpoint_id
596 - );
597 - echo json_encode( $output );
598 -
599 - wp_die(); // this is required to terminate immediately and return a proper response
600 -
601 - }
602 -
603 - public function get_import_export() {
604 - ob_start(); ?>
605 -
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 449 /**
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 - if( ! current_user_can( 'manage_options' ) ) {
672 - echo 'Admin privelages are required to import endpoints.';
673 - wp_die();
674 - }
675 -
676 - if ( isset( $_POST['nonce'] ) ) {
677 - if ( ! wp_verify_nonce( $_POST['nonce'], 'import_endpoint_nonce' ) ) {
678 - echo 'Nope.';
679 - wp_die();
680 - }
681 - }
682 -
683 - $api_id = sanitize_text_field( $_POST['api_id'] );
684 - $textarea = sanitize_textarea_field( $_POST['textarea'] );
685 - $existing_data = get_option( $api_id );
686 -
687 - if( ! $textarea ) {
688 - echo 'No data found.';
689 - wp_die();
690 - }
691 -
692 - $new_data = json_decode( stripslashes( $textarea ), true );
693 - if( ! isset( $new_data['endpoints'] ) ){
694 - echo 'No endpoints found.';
695 - wp_die();
696 - }
697 -
698 - $encryption = new WpGetApi_Encryption();
699 -
700 - foreach ( $new_data['endpoints'] as $i => $endpoint ) {
701 - if( isset( $endpoint['query_parameters'] ) ) {
702 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
703 - if( isset( $query_parameters['value'] ) )
704 - $new_data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->encrypt( $query_parameters['value'] );
705 - }
706 - }
707 - if( isset( $endpoint['header_parameters'] ) ) {
708 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
709 - if( isset( $header_parameters['value'] ) )
710 - $new_data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->encrypt( $header_parameters['value'] );
711 - }
712 - }
713 - if( isset( $endpoint['body_parameters'] ) ) {
714 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
715 - if( isset( $body_parameters['value'] ) )
716 - $new_data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->encrypt( $body_parameters['value'] );
717 - }
718 - }
719 - }
720 -
721 - // if no existing endpoints, simply add it
722 - if( ! $existing_data ) {
723 - update_option( $api_id, $new_data, 'no' );
724 - } else {
725 -
726 - $merged['endpoints'] = array_merge( $existing_data['endpoints'], $new_data['endpoints'] );
727 - update_option( $api_id, $merged, 'no' );
728 - }
729 -
730 - echo 'Successfully imported. Reloading...';
731 - wp_die(); // this is required to terminate immediately and return a proper response
732 - }
733 -
734 -
735 - public function load_testing_javascript() { ?>
736 -
737 - <script type="text/javascript" >
738 -
739 - jQuery(document).ready(function($) {
740 -
741 - /**
742 - * Collapse the endpoints
743 - *
744 - */
745 - $('body').on( 'click', '.wpgetapi .collapse .button', function(){
746 -
747 - var $this = $(this);
748 - var $collapse = $(this).parents('.collapse');
749 - var status = 'open';
750 -
751 - $collapse.toggleClass('open');
752 -
753 - if( ! $collapse.hasClass( 'open' ) )
754 - status = 'closed';
755 -
756 - var $endpoints = $( '#endpoints_repeat .postbox.cmb-repeatable-grouping' );
757 - $endpoints.each( function() {
758 -
759 - if( status == 'closed' ) {
760 - $( this ).addClass('closed');
761 - } else {
762 - $( this ).removeClass('closed');
763 - }
764 -
765 - });
766 -
767 - });
768 -
769 - /**
770 - * Run the export
771 - *
772 - */
773 - $('body').on( 'click', '.wpgetapi-export .button', function(){
774 -
775 - var $this = $(this);
776 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
777 -
778 - // disable button
779 - $this.attr( 'disabled', true );
780 -
781 - var data = {
782 - 'action': 'wpgetapi_export_endpoints',
783 - 'api_id': api_id,
784 - };
785 -
786 - // send and get response
787 - jQuery.post(ajaxurl, data, function( response ) {
788 - $( '.wpgetapi-export .message' ).show().html( response );
789 - // enable button
790 - $( '.wpgetapi-export .button' ).attr( 'disabled', false );
791 -
792 - });
793 -
794 - });
795 -
796 - /**
797 - * Run the import
798 - *
799 - */
800 - $('body').on( 'click', '.wpgetapi-import .button', function(){
801 -
802 - var $this = $(this);
803 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
804 - var textarea = $('.wpgetapi-import textarea').val();
805 -
806 - // disable button
807 - $this.attr( 'disabled', true );
808 -
809 - var data = {
810 - 'action': 'wpgetapi_import_endpoints',
811 - 'textarea': textarea,
812 - 'api_id': api_id,
813 - 'nonce': "<?php echo wp_create_nonce( 'import_endpoint_nonce' ); ?>",
814 - };
815 -
816 - // send and get response
817 - jQuery.post(ajaxurl, data, function( response ) {
818 -
819 - $( '.wpgetapi-import .message' ).html( response );
820 -
821 - if( response == 'Successfully imported. Reloading...' ) {
822 - setTimeout(function(){
823 - location.reload();
824 - }, 1000);
825 - } else {
826 - $( '.wpgetapi-import .button' ).attr( 'disabled', false );
827 - }
828 -
829 - });
830 -
831 - });
832 -
833 - /**
834 - * Run the endpoint test
835 - *
836 - */
837 - $('body').on( 'click', '.wpgetapi .test-endpoint-button', function(){//delegated
838 -
839 - var $this = $(this);
840 - var $parent = $this.closest( '.cmb-repeatable-grouping' );
841 - var area = $parent.find( '.wpgetapi-test-area' );
842 - var api_id = $( area ).data( 'api' );
843 - var endpoint_id = $( area ).data( 'endpoint' );
844 -
845 - // disable button
846 - $this.attr( 'disabled', true );
847 -
848 - var data = {
849 - 'action': 'wpgetapi_test_endpoint',
850 - 'api_id': api_id,
851 - 'endpoint_id': endpoint_id
852 - };
853 -
854 - // send and get response
855 - jQuery.post(ajaxurl, data, function( response ) {
856 -
857 - var output = JSON.parse( response );
858 -
859 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show();
860 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( output.data);
861 -
862 - // enable button
863 - $( '.wpgetapi .test-endpoint-button' ).attr( 'disabled', false );
864 -
865 - });
866 -
867 - });
868 -
869 - $( '.wpgetapi-test-area .handle' ).on('click', function() {
870 - $('.wpgetapi-result').toggle();
871 - });
872 -
873 - });
874 -
875 - </script> <?php
876 -
877 - }
878 -
879 -
880 - /**
881 450 * Sidebar markup.
882 451 * @since 1.4.1
883 452 */
884 453 public function sidebar_display() {
@@ -891,22 +460,44 @@
891 460
892 461 ?>
893 462
894 463 <div class="box">
895 - <h4><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h4>
464 + <h3><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h3>
896 465 <ol>
897 - <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
898 - <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li>
899 - <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li>
900 - <li><?php _e( 'Set the desired <b>Results Format</b>', 'wpgetapi' ); ?></li>
901 - <li><?php _e( 'Other fields are optional & will depend on your API', 'wpgetapi' ); ?></li>
902 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
903 - <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>
904 472 </ol>
905 473 </div>
906 -
907 - <?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>
908 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 +
909 500 <?php
910 501 $content = ob_get_contents();
911 502 ob_end_clean();
912 503 return $content;
@@ -923,56 +514,38 @@
923 514 ob_start();
924 515 ?>
925 516
926 517 <div class="box">
927 - <h4><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h4>
518 + <h3><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h3>
928 519 <ol>
929 - <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li>
930 - <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
931 - <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li>
932 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
933 - <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>
934 523 </ol>
935 524 </div>
936 525
937 - <?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>
938 535
939 - <?php
940 - $content = ob_get_contents();
941 - ob_end_clean();
942 - return $content;
536 + <hr>
943 537
944 - }
945 -
946 -
947 - /**
948 - *
949 - * @since 1.4.4
950 - */
951 - public function help_box() {
952 -
953 - ob_start();
954 - ?>
955 -
956 - <div class="box help-box">
957 - <h4><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></h4>
538 + <div class="box">
539 + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong>
958 540 <ul>
959 - <li><?php
541 + <li><?php
960 542 printf(
961 - esc_html__( 'View the %1$s', 'cmb2' ),
962 - '<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>'
963 546 );
964 547 ?></li>
965 - <li><?php
966 - printf(
967 - esc_html__( 'View the %1$s', 'cmb2' ),
968 - '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>'
969 - );
970 - ?></li>
971 -
972 - <?php if( ! $this->pro_plugin ) { ?>
973 - <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>
974 - <?php } ?>
975 548 </ul>
976 549 </div>
977 550
978 551 <?php
@@ -981,30 +554,19 @@
981 554 return $content;
982 555
983 556 }
984 557
985 -
986 558 /**
987 559 * Tabs don't immmediately appear on save, so this hack!
988 560 * @since 0.1.0
989 561 */
990 562 public function redirect( $object_id, $updated ) {
991 -
992 - if( strpos( $object_id, 'wpgetapi_' ) !== false && strpos( $object_id, 'wpgetapi_api_importer' ) == false ) {
993 -
994 - add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' );
563 + if( $object_id == 'wpgetapi_setup' ) {
564 + add_settings_error( 'wpgetapi-notices', '', 'Settings saved.', 'updated' );
995 565 settings_errors( 'wpgetapi-notices' );
996 - ?>
997 -
998 - <script>
999 - setTimeout(function() {
1000 - location.reload();
1001 - }, 200);
1002 - </script>
1003 - <?php
1004 -
1005 - }
1006 -
566 + wp_redirect( admin_url( 'admin.php?page=' . $object_id ) );
567 + exit;
568 + }
1007 569 }
1008 570
1009 571
1010 572 /**