| @@ -97,11 +97,8 @@ | ||
| 97 | 97 | add_action( 'admin_footer', array( $this, 'load_testing_javascript' ) ); |
| 98 | 98 | |
| 99 | 99 | add_action( 'wp_ajax_wpgetapi_test_endpoint', array( $this, 'test_the_endpoint' ) ); |
| 100 | 100 | |
| 101 | - add_action( 'wp_ajax_wpgetapi_export_endpoints', array( $this, 'export_endpoints' ) ); | |
| 102 | - add_action( 'wp_ajax_wpgetapi_import_endpoints', array( $this, 'import_endpoints' ) ); | |
| 103 | - | |
| 104 | 101 | } |
| 105 | 102 | |
| 106 | 103 | |
| 107 | 104 | /** |
| @@ -206,9 +203,9 @@ | ||
| 206 | 203 | 'sortable' => true, // beta |
| 207 | 204 | ), |
| 208 | 205 | 'fields' => array( |
| 209 | 206 | array( |
| 210 | - 'name' => __( 'API Name', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The name of this API. Call it whatever you like.', 'wpgetapi' ) . '"></span>', | |
| 207 | + 'name' => __( 'API Name', 'wpgetapi' ), | |
| 211 | 208 | 'id' => 'name', |
| 212 | 209 | 'type' => 'text', |
| 213 | 210 | 'attributes' => array( |
| 214 | 211 | 'required' => true, |
| @@ -213,12 +210,12 @@ | ||
| 213 | 210 | 'attributes' => array( |
| 214 | 211 | 'required' => true, |
| 215 | 212 | 'placeholder' => 'Google Maps', |
| 216 | 213 | ), |
| 217 | - 'desc' => '', | |
| 214 | + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ), | |
| 218 | 215 | ), |
| 219 | 216 | 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>', | |
| 217 | + 'name' => __( 'Unique ID', 'wpgetapi' ), | |
| 221 | 218 | 'id' => 'id', |
| 222 | 219 | 'type' => 'text', |
| 223 | 220 | 'attributes' => array( |
| 224 | 221 | 'required' => true, |
| @@ -223,13 +220,12 @@ | ||
| 223 | 220 | 'attributes' => array( |
| 224 | 221 | 'required' => true, |
| 225 | 222 | 'placeholder' => 'google_maps', |
| 226 | 223 | ), |
| 227 | - 'desc' => '', | |
| 228 | - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id' | |
| 224 | + 'desc' => __( 'A unique ID for your API. Lowercase letters and underscores only.', 'wpgetapi' ), | |
| 229 | 225 | ), |
| 230 | 226 | 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>', | |
| 227 | + 'name' => __( 'Base URL', 'wpgetapi' ), | |
| 232 | 228 | 'id' => 'base_url', |
| 233 | 229 | 'type' => 'text', |
| 234 | 230 | 'attributes' => array( |
| 235 | 231 | 'required' => true, |
| @@ -234,9 +230,9 @@ | ||
| 234 | 230 | 'attributes' => array( |
| 235 | 231 | 'required' => true, |
| 236 | 232 | 'placeholder' => 'https://maps.googleapis.com/maps/api', |
| 237 | 233 | ), |
| 238 | - 'desc' => '', | |
| 234 | + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ), | |
| 239 | 235 | ), |
| 240 | 236 | |
| 241 | 237 | ) |
| 242 | 238 | ); |
| @@ -255,14 +251,13 @@ | ||
| 255 | 251 | |
| 256 | 252 | $fields = array(); |
| 257 | 253 | |
| 258 | 254 | $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.'; | |
| 255 | + $cache_url = $this->pro_plugin ? '<a target="_blank" href="https://wpgetapi.com/docs/caching-api-calls/">Help <span class="dashicons dashicons-external"></span></a>' : '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Cache Pro Plugin&utm_medium=Admin&utm_source=User">PRO Plugin<span class="dashicons dashicons-external"></span></a>'; | |
| 261 | 256 | |
| 262 | 257 | $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array( |
| 263 | 258 | 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>', | |
| 259 | + 'name' => __( 'Unique ID', 'wpgetapi' ), | |
| 265 | 260 | 'id' => 'id', |
| 266 | 261 | 'type' => 'text', |
| 267 | 262 | 'classes' => 'field-id', |
| 268 | 263 | 'attributes' => array( |
| @@ -268,16 +263,15 @@ | ||
| 268 | 263 | 'attributes' => array( |
| 269 | 264 | 'required' => true, |
| 270 | 265 | 'placeholder' => 'new_endpoint', |
| 271 | 266 | ), |
| 272 | - 'desc' => '', | |
| 267 | + 'desc' => __( 'A unique ID for this endpoint. Lowercase letters and underscores only.', 'wpgetapi' ), | |
| 273 | 268 | 'before_row' => "wpgetapi_output_top_of_endpoint", |
| 274 | 269 | 'api_id' => $api_id, |
| 275 | - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id' | |
| 276 | 270 | |
| 277 | 271 | ), |
| 278 | 272 | 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>', | |
| 273 | + 'name' => __( 'Endpoint', 'wpgetapi' ), | |
| 280 | 274 | 'id' => 'endpoint', |
| 281 | 275 | 'type' => 'text', |
| 282 | 276 | 'classes' => 'field-endpoint', |
| 283 | 277 | 'attributes' => array( |
| @@ -283,12 +277,12 @@ | ||
| 283 | 277 | 'attributes' => array( |
| 284 | 278 | 'required' => true, |
| 285 | 279 | 'placeholder' => '/newendpoint', |
| 286 | 280 | ), |
| 287 | - 'desc' => '', | |
| 281 | + 'desc' => __( 'The endpoint that will be appended to the base URL.', 'wpgetapi' ), | |
| 288 | 282 | ), |
| 289 | 283 | 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>', | |
| 284 | + 'name' => __( 'Method', 'wpgetapi' ), | |
| 291 | 285 | 'id' => 'method', |
| 292 | 286 | 'type' => 'select', |
| 293 | 287 | 'classes' => 'field-method', |
| 294 | 288 | 'attributes' => array( |
| @@ -297,22 +291,15 @@ | ||
| 297 | 291 | 'options' => array( |
| 298 | 292 | 'GET' => 'GET', |
| 299 | 293 | 'POST' => 'POST', |
| 300 | 294 | 'PUT' => 'PUT', |
| 301 | - 'PATCH' => 'PATCH', | |
| 302 | 295 | 'DELETE' => 'DELETE', |
| 303 | 296 | ), |
| 304 | - 'desc' => '', | |
| 297 | + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ), | |
| 305 | 298 | ), |
| 306 | 299 | |
| 307 | 300 | 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>', | |
| 301 | + 'name' => __( 'Results Format', 'wpgetapi' ), | |
| 315 | 302 | 'id' => 'results_format', |
| 316 | 303 | 'type' => 'select', |
| 317 | 304 | 'classes' => 'field-results-format', |
| 318 | 305 | 'attributes' => array( |
| @@ -318,123 +305,78 @@ | ||
| 318 | 305 | 'attributes' => array( |
| 319 | 306 | 'required' => true, |
| 320 | 307 | ), |
| 321 | 308 | 'options_cb' => 'wpgetapi_results_format_options', |
| 322 | - 'desc' => '' | |
| 309 | + 'desc' => sprintf( | |
| 310 | + __( 'The format of the results. %1s', 'wpgetapi' ), | |
| 311 | + '<a target="_blank" href="https://wpgetapi.com/docs/format-api-data-as-html/?utm_campaign=Shortcode JSON&utm_medium=Admin&utm_source=User">More options <span class="dashicons dashicons-external"></span></a>' | |
| 312 | + ) | |
| 323 | 313 | ), |
| 324 | 314 | |
| 325 | 315 | 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>', | |
| 316 | + 'name' => __( 'Cache Time', 'wpgetapi' ), | |
| 333 | 317 | 'id' => 'cache_time', |
| 334 | 318 | 'type' => 'text', |
| 335 | 319 | 'classes' => 'field-cache-time', |
| 336 | 320 | 'attributes' => array( |
| 337 | - 'placeholder' => '3600', | |
| 321 | + 'placeholder' => '', | |
| 338 | 322 | $cache_disabled => $cache_disabled, |
| 339 | 323 | ), |
| 340 | - 'desc' => $cache_desc | |
| 324 | + 'desc' => sprintf( | |
| 325 | + __( 'The time in seconds to cache this request for. %1s', 'wpgetapi' ), | |
| 326 | + $cache_url | |
| 327 | + ) | |
| 341 | 328 | ), |
| 342 | 329 | |
| 343 | 330 | 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>', | |
| 331 | + 'name' => __( 'Query String', 'wpgetapi' ), | |
| 351 | 332 | 'id' => 'query_parameters', |
| 352 | 333 | 'type' => 'parameter', |
| 353 | 334 | 'classes' => 'field-query-parameters', |
| 354 | 335 | 'repeatable' => true, |
| 355 | - 'desc' => '' | |
| 336 | + 'desc' => sprintf( | |
| 337 | + __( 'Parameters as name/value pairs that will be appended to the URL. %1s', 'wpgetapi' ), | |
| 338 | + '<a target="_blank" href="https://wpgetapi.com/docs/adding-query-string-parameters/?utm_campaign=Query String&utm_medium=Admin&utm_source=User">Help <span class="dashicons dashicons-external"></span></a>' | |
| 339 | + ) | |
| 356 | 340 | ), |
| 357 | 341 | 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>', | |
| 342 | + 'name' => __( 'Headers', 'wpgetapi' ), | |
| 365 | 343 | 'id' => 'header_parameters', |
| 366 | 344 | 'type' => 'parameter', |
| 367 | 345 | 'classes' => 'field-header-parameters', |
| 368 | 346 | 'repeatable' => true, |
| 369 | - 'desc' => '' | |
| 347 | + 'desc' => sprintf( | |
| 348 | + __( 'Parameters as name/value pairs, sent in the headers. %1s', 'wpgetapi' ), | |
| 349 | + '<a target="_blank" href="https://wpgetapi.com/docs/sending-headers-in-request/?utm_campaign=Headers&utm_medium=Admin&utm_source=User">Help <span class="dashicons dashicons-external"></span></a>' | |
| 350 | + ) | |
| 370 | 351 | ), |
| 371 | 352 | 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>', | |
| 353 | + 'name' => __( 'Body POST Fields', 'wpgetapi' ), | |
| 379 | 354 | 'id' => 'body_parameters', |
| 380 | 355 | 'type' => 'parameter', |
| 381 | 356 | 'classes' => 'field-body-parameters', |
| 382 | 357 | 'repeatable' => true, |
| 383 | - 'desc' => '' | |
| 358 | + 'desc' => sprintf( | |
| 359 | + __( 'Parameters as name/value pairs, sent in the body as POST fields. %1s', 'wpgetapi' ), | |
| 360 | + '<a target="_blank" href="https://wpgetapi.com/docs/sending-post-fields-in-request/?utm_campaign=Body&utm_medium=Admin&utm_source=User">Help <span class="dashicons dashicons-external"></span></a>' | |
| 361 | + ) | |
| 384 | 362 | ), |
| 385 | 363 | array( |
| 386 | - 'name' => __( 'Encode Body', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Encoding of the above Body parameters.', 'wpgetapi' ) . '"></span>', | |
| 364 | + 'name' => __( 'Encode Body', 'wpgetapi' ), | |
| 387 | 365 | 'id' => 'body_json_encode', |
| 388 | 366 | 'type' => 'select', |
| 389 | 367 | 'classes' => 'field-body-json-encode', |
| 390 | 368 | '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 | - | |
| 369 | + 'false' => __( 'No encoding (raw)', 'wpgetapi' ), | |
| 370 | + 'true' => __( 'JSON encode', 'wpgetapi' ), | |
| 371 | + 'url' => __( 'URL encode (x-www-form-urlencoded)', 'wpgetapi' ), | |
| 372 | + 'xml' => __( 'XML format (available in PRO only)', 'wpgetapi' ), | |
| 397 | 373 | ), |
| 398 | - 'desc' => '', | |
| 374 | + 'desc' => __( 'Encoding of the above Body parameters. ', 'wpgetapi' ), | |
| 399 | 375 | ), |
| 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' ), | |
| 376 | + ) ); | |
| 416 | 377 | |
| 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 | 378 | |
| 434 | - ) ); | |
| 435 | - | |
| 436 | - | |
| 437 | 379 | $fields[] = array( |
| 438 | 380 | 'id' => 'endpoints', |
| 439 | 381 | 'type' => 'group', |
| 440 | 382 | 'name' => '', |
| @@ -444,9 +386,9 @@ | ||
| 444 | 386 | 'add_button' => __( 'Add Endpoint', 'wpgetapi' ), |
| 445 | 387 | 'remove_button' => __( 'Remove Endpoint', 'wpgetapi' ), |
| 446 | 388 | 'sortable' => true, // beta |
| 447 | 389 | ), |
| 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>', | |
| 390 | + 'before_group' => '<pre class="url">Base URL: <span>' . $base_url . '</span></pre>', | |
| 449 | 391 | 'fields' => $endpoint_fields, |
| 450 | 392 | ); |
| 451 | 393 | |
| 452 | 394 | return apply_filters( 'wpgetapi_fields', $fields ); |
| @@ -454,9 +396,8 @@ | ||
| 454 | 396 | } |
| 455 | 397 | |
| 456 | 398 | |
| 457 | 399 | public function add_options_pages() { |
| 458 | - add_thickbox(); | |
| 459 | 400 | |
| 460 | 401 | $option_tabs = self::option_fields(); |
| 461 | 402 | |
| 462 | 403 | foreach ($option_tabs as $index => $option_tab) { |
| @@ -491,11 +432,9 @@ | ||
| 491 | 432 | <div class="wrap wpgetapi"> |
| 492 | 433 | |
| 493 | 434 | <div class="main_content_cell"> |
| 494 | 435 | |
| 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> | |
| 436 | + <h1 class="wp-heading-inline"><?php esc_html_e( $this->title, 'wpgetapi' ) ?></h1> | |
| 498 | 437 | <!-- Options Page Nav Tabs --> |
| 499 | 438 | <h2 class="nav-tab-wrapper"> |
| 500 | 439 | <?php foreach ($option_tabs as $option_tab) : |
| 501 | 440 | |
| @@ -519,15 +458,8 @@ | ||
| 519 | 458 | foreach ($tab_forms as $tab_form) : ?> |
| 520 | 459 | |
| 521 | 460 | <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group"> |
| 522 | 461 | <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 | 462 | <div class="pmpbox pad"> |
| 531 | 463 | <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3> |
| 532 | 464 | <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div> |
| 533 | 465 | <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?> |
| @@ -554,9 +486,8 @@ | ||
| 554 | 486 | |
| 555 | 487 | } |
| 556 | 488 | |
| 557 | 489 | |
| 558 | - | |
| 559 | 490 | public function test_the_endpoint() { |
| 560 | 491 | |
| 561 | 492 | $api_id = sanitize_text_field( $_POST['api_id'] ); |
| 562 | 493 | $endpoint_id = sanitize_text_field( $_POST['endpoint_id'] ); |
| @@ -571,128 +502,9 @@ | ||
| 571 | 502 | wp_die(); // this is required to terminate immediately and return a proper response |
| 572 | 503 | |
| 573 | 504 | } |
| 574 | 505 | |
| 575 | - public function get_import_export() { | |
| 576 | - ob_start(); ?> | |
| 577 | 506 | |
| 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 | - /** | |
| 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 | 507 | public function load_testing_javascript() { ?> |
| 696 | 508 | |
| 697 | 509 | <script type="text/javascript" > |
| 698 | 510 | |
| @@ -697,75 +509,8 @@ | ||
| 697 | 509 | <script type="text/javascript" > |
| 698 | 510 | |
| 699 | 511 | jQuery(document).ready(function($) { |
| 700 | 512 | |
| 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 | 513 | $('body').on( 'click', '.wpgetapi-test-area .test-button', function(){//delegated |
| 769 | 514 | |
| 770 | 515 | var $this = $(this); |
| 771 | 516 | var area = $this.parents( '.wpgetapi-test-area' ); |
| @@ -785,11 +530,16 @@ | ||
| 785 | 530 | jQuery.post(ajaxurl, data, function( response ) { |
| 786 | 531 | |
| 787 | 532 | var output = JSON.parse( response ); |
| 788 | 533 | |
| 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); | |
| 534 | + jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show(); | |
| 791 | 535 | |
| 536 | + jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( | |
| 537 | + '<div class="side-notice"><p>These results contain the raw output of your API call as well as extra debugging information for testing purposes. <br>' + | |
| 538 | + 'Using the shortcode or the template tag on the front end will display the Data Output section as shown below. The data can be formatted any way you like, depending on your requirements.</p></div>' + | |
| 539 | + output.data | |
| 540 | + ); | |
| 541 | + | |
| 792 | 542 | // enable button |
| 793 | 543 | $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .test-button' ).attr( 'disabled', false ); |
| 794 | 544 | |
| 795 | 545 | }); |
| @@ -821,9 +571,9 @@ | ||
| 821 | 571 | |
| 822 | 572 | ?> |
| 823 | 573 | |
| 824 | 574 | <div class="box"> |
| 825 | - <h4><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h4> | |
| 575 | + <strong><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></strong> | |
| 826 | 576 | <ol> |
| 827 | 577 | <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li> |
| 828 | 578 | <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li> |
| 829 | 579 | <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li> |
| @@ -833,10 +583,34 @@ | ||
| 833 | 583 | <li><?php _e( 'Copy the Template Tag or Shortcode & paste into page, post or theme file', 'wpgetapi' ); ?></li> |
| 834 | 584 | </ol> |
| 835 | 585 | </div> |
| 836 | 586 | |
| 837 | - <?php echo $this->help_box(); ?> | |
| 587 | + <hr> | |
| 838 | 588 | |
| 589 | + <div class="box"> | |
| 590 | + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong> | |
| 591 | + <ul> | |
| 592 | + <li><?php | |
| 593 | + printf( | |
| 594 | + esc_html__( 'View the %1$s', 'cmb2' ), | |
| 595 | + '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">Quick Start Guide</a>' | |
| 596 | + ); | |
| 597 | + ?></li> | |
| 598 | + <li><?php | |
| 599 | + printf( | |
| 600 | + esc_html__( 'View the %1$s', 'cmb2' ), | |
| 601 | + '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>' | |
| 602 | + ); | |
| 603 | + ?></li> | |
| 604 | + <li><?php | |
| 605 | + printf( | |
| 606 | + esc_html__( 'Do more with the %1$s', 'cmb2' ), | |
| 607 | + '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">PRO Plugin</a>' | |
| 608 | + ); | |
| 609 | + ?></li> | |
| 610 | + </ul> | |
| 611 | + </div> | |
| 612 | + | |
| 839 | 613 | <?php |
| 840 | 614 | $content = ob_get_contents(); |
| 841 | 615 | ob_end_clean(); |
| 842 | 616 | return $content; |
| @@ -853,9 +627,9 @@ | ||
| 853 | 627 | ob_start(); |
| 854 | 628 | ?> |
| 855 | 629 | |
| 856 | 630 | <div class="box"> |
| 857 | - <h4><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h4> | |
| 631 | + <strong><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></strong> | |
| 858 | 632 | <ol> |
| 859 | 633 | <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li> |
| 860 | 634 | <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li> |
| 861 | 635 | <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li> |
| @@ -863,31 +637,12 @@ | ||
| 863 | 637 | <li><?php _e( 'Visit the new tab that will be created', 'wpgetapi' ); ?></li> |
| 864 | 638 | </ol> |
| 865 | 639 | </div> |
| 866 | 640 | |
| 867 | - <?php echo $this->help_box(); ?> | |
| 868 | - | |
| 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 | 641 | <hr> |
| 887 | 642 | |
| 888 | - <div class="box help-box"> | |
| 889 | - <h4><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></h4> | |
| 643 | + <div class="box"> | |
| 644 | + <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong> | |
| 890 | 645 | <ul> |
| 891 | 646 | <li><?php |
| 892 | 647 | printf( |
| 893 | 648 | esc_html__( 'View the %1$s', 'cmb2' ), |
| @@ -899,12 +654,14 @@ | ||
| 899 | 654 | esc_html__( 'View the %1$s', 'cmb2' ), |
| 900 | 655 | '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>' |
| 901 | 656 | ); |
| 902 | 657 | ?></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 } ?> | |
| 658 | + <li><?php | |
| 659 | + printf( | |
| 660 | + esc_html__( 'Do more with the %1$s', 'cmb2' ), | |
| 661 | + '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">PRO Plugin</a>' | |
| 662 | + ); | |
| 663 | + ?></li> | |
| 907 | 664 | </ul> |
| 908 | 665 | </div> |
| 909 | 666 | |
| 910 | 667 | <?php |
| @@ -920,9 +677,9 @@ | ||
| 920 | 677 | * @since 0.1.0 |
| 921 | 678 | */ |
| 922 | 679 | public function redirect( $object_id, $updated ) { |
| 923 | 680 | |
| 924 | - if( strpos( $object_id, 'wpgetapi_' ) !== false && strpos( $object_id, 'wpgetapi_api_importer' ) == false ) { | |
| 681 | + if( $object_id == 'wpgetapi_setup' ) { | |
| 925 | 682 | |
| 926 | 683 | add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' ); |
| 927 | 684 | settings_errors( 'wpgetapi-notices' ); |
| 928 | 685 | ?> |
| @@ -929,13 +686,19 @@ | ||
| 929 | 686 | |
| 930 | 687 | <script> |
| 931 | 688 | setTimeout(function() { |
| 932 | 689 | location.reload(); |
| 933 | - }, 200); | |
| 690 | + }, 1000); | |
| 934 | 691 | </script> |
| 935 | 692 | <?php |
| 936 | 693 | |
| 937 | - } | |
| 694 | + } else if ( strpos( $object_id, 'wpgetapi_' ) !== false ) { | |
| 695 | + | |
| 696 | + $text = apply_filters( 'wpgetapi_admin_notice_text', __( 'Saved.', 'wpgetapi' ), $object_id ); | |
| 697 | + add_settings_error( 'wpgetapi-notices', '', $text, 'updated' ); | |
| 698 | + settings_errors( 'wpgetapi-notices' ); | |
| 699 | + | |
| 700 | + } | |
| 938 | 701 | |
| 939 | 702 | } |
| 940 | 703 | |
| 941 | 704 | |