PluginProbe
WPGet API – Connect to any external REST API / 1.1.0
WPGet API – Connect to any external REST API v1.1.0
1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.10 2.2.2 2.2.3 All 97 releases
← All changes | includes/class-admin-options.php +109 -650 2.2.01.1.0 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
@@ -89,26 +82,11 @@
89 82 public function hooks() {
90 83 add_action( 'admin_init', array( $this, 'init' ) );
91 84 add_action( 'admin_menu', array( $this, 'add_options_pages' ) );
92 85
93 - add_action( 'cmb2_admin_init', array( $this, 'init_custom_fields' ) );
94 -
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 -
86 + add_action( 'cmb2_init', array( $this, 'init_custom_fields' ) );
104 87 }
105 88
106 -
107 - /**
108 - * Setup our custom fields
109 - * @since 0.1.0
110 - */
111 89 public function init_custom_fields() {
112 90 require_once WPGETAPIDIR . 'includes/class-fields.php';
113 91 WpGetApi_Parameter_Field::init_parameter();
114 92 }
@@ -117,9 +95,8 @@
117 95 * Register our setting to WP
118 96 * @since 0.1.0
119 97 */
120 98 public function init() {
121 - $this->pro_plugin = is_plugin_active( 'wpgetapi-extras/wpgetapi-extras.php' ) ? true : false;
122 99 $option_tabs = self::option_fields();
123 100 foreach ($option_tabs as $index => $option_tab) {
124 101 register_setting( $option_tab['id'], $option_tab['id'] );
125 102 }
@@ -130,12 +107,16 @@
130 107 * Get our saved API's from setup
131 108 * @since 0.1.0
132 109 */
133 110 public function get_apis() {
111 +
134 112 $setup = get_option( 'wpgetapi_setup' );
113 +
135 114 if( empty( $setup ) || ! isset( $setup['apis'] ) || empty( $setup['apis'] ) )
136 115 return;
116 +
137 117 return $setup['apis'];
118 +
138 119 }
139 120
140 121
141 122 /**
@@ -148,15 +129,15 @@
148 129 if ( ! empty( $this->option_metabox ) ) {
149 130 return $this->option_metabox;
150 131 }
151 132
152 - // setup tab
133 + // sale tab
153 134 $option_metabox[] = array(
154 135 'title' => __( 'Setup', 'wpgetapi' ),
155 136 'menu_title' => __( 'Setup', 'wpgetapi' ),
156 137 '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' ),
158 - 'show_on' => array( 'key' => 'options-page', 'value' => array( 'wpgetapi_setup' ), ),
138 + 'desc' => __( 'Add the details of your API(s) below and hit the Save button.', 'wpgetapi' ),
139 + 'show_on' => array( 'key' => 'options-page', 'value' => array( 'setup' ), ),
159 140 'show_names' => true,
160 141 'fields' => $this->setup_fields(),
161 142 );
162 143
@@ -178,9 +159,9 @@
178 159 'id' => $metabox_id,
179 160 'desc' => '',
180 161 'show_on' => array( 'key' => 'options-page', 'value' => array( $metabox_id ), ),
181 162 'show_names' => true,
182 - 'fields' => $this->endpoint_fields( $type, $api_id, $base_url ),
163 + 'fields' => $this->api_fields( $type, $api_id, $base_url ),
183 164 );
184 165
185 166 }
186 167
@@ -185,14 +166,13 @@
185 166 }
186 167
187 168 }
188 169
189 - $option_metabox = apply_filters( 'wpgetapi_admin_pages', $option_metabox );
190 -
191 170 return $option_metabox;
192 171
193 172 }
194 173
174 +
195 175 public function setup_fields() {
196 176
197 177 $fields[] = array(
198 178 'id' => 'apis',
@@ -200,44 +180,42 @@
200 180 'name' => '',
201 181 'description' => '',
202 182 'options' => array(
203 183 'group_title' => __( 'API {#}', 'wpgetapi' ),
204 - 'add_button' => __( 'Add New API', 'wpgetapi' ),
184 + 'add_button' => __( 'Add API', 'wpgetapi' ),
205 185 'remove_button' => __( 'Remove API', 'wpgetapi' ),
206 186 'sortable' => true, // beta
207 187 ),
208 188 'fields' => array(
209 189 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>',
190 + 'name' => __( 'API Name', 'wpgetapi' ),
211 191 'id' => 'name',
212 192 'type' => 'text',
213 - 'classes' => 'api-name',
214 193 'attributes' => array(
215 194 'required' => true,
216 - 'placeholder' => 'Google Maps',
195 + 'placeholder' => 'New API Name',
217 196 ),
218 - 'desc' => '',
197 + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ),
219 198 ),
220 199 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>',
200 + 'name' => __( 'API ID', 'wpgetapi' ),
222 201 'id' => 'id',
223 202 'type' => 'text',
224 203 'attributes' => array(
225 204 'required' => true,
226 - 'placeholder' => 'google_maps',
205 + 'placeholder' => 'new_api_name',
227 206 ),
228 - 'desc' => '',
229 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
207 + 'desc' => __( 'A unique ID for your API. Once this is set you should not change this value.', 'wpgetapi' ),
230 208 ),
231 209 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>',
210 + 'name' => __( 'Base URL', 'wpgetapi' ),
233 211 'id' => 'base_url',
234 212 'type' => 'text',
235 213 'attributes' => array(
236 214 'required' => true,
237 - 'placeholder' => 'https://maps.googleapis.com/maps/api',
215 + 'placeholder' => 'https://newapiurl.com',
238 216 ),
239 - 'desc' => '',
217 + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ),
240 218 ),
241 219
242 220 )
243 221 );
@@ -247,52 +225,71 @@
247 225 }
248 226
249 227
250 228 /**
251 - * Endpoint settings.
229 + * Site wide info on the current sale.
252 230 * @return sale info array
253 231 *
254 232 */
255 - public function endpoint_fields( $type = '', $api_id = '', $base_url = '' ) {
233 + public function api_fields( $type = '', $api_id = '', $base_url = '' ) {
256 234
257 235 $fields = array();
258 236
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 -
237 + $fields[] = array(
238 + 'name' => __( 'Timeout', 'wpgetapi' ),
239 + 'id' => 'timeout',
240 + 'type' => 'text',
241 + 'desc' => __( 'Timeout of the API call.', 'wpgetapi' ),
242 + 'attributes' => array(
243 + 'placeholder' => '10'
244 + ),
245 + 'before_row' => '<pre class="url"><span>Base URL: </span>' . $base_url . '</pre>',
246 + );
247 + $fields[] = array(
248 + 'name' => __( 'SSL Verify', 'wpgetapi' ),
249 + 'id' => 'sslverify',
250 + 'type' => 'select',
251 + 'desc' => __( 'This should normally be set to true. If you are having issues, you can try false.', 'wpgetapi' ),
252 + 'options' => array(
253 + '1' => 'True',
254 + '0' => 'False'
255 + ),
256 + );
257 +
263 258 $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array(
264 259 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>',
260 + 'name' => __( 'Unique ID', 'wpgetapi' ),
266 261 'id' => 'id',
267 262 'type' => 'text',
268 - 'classes' => 'field-id field-half',
263 + 'classes' => 'field-id',
269 264 'attributes' => array(
270 265 'required' => true,
271 266 'placeholder' => 'new_endpoint',
272 267 ),
273 - 'desc' => '',
274 - 'before_row' => "wpgetapi_output_top_of_endpoint",
275 - 'api_id' => $api_id,
276 - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id'
277 -
268 + 'desc' => __( 'Choose a unique ID for this endpoint. Once this is set you should not change this value.', 'wpgetapi' ),
269 + 'before_row' => "
270 + <pre class='functions'>
271 + Template Function: </span><span>wpgetapi_endpoint( '" . $api_id . "', '<span class='endpoint_id'></span>', array('debug' => false) );</span><br>
272 + Shortcode: <span>[wpgetapi_endpoint api_id='" . $api_id . "' endpoint_id='<span class='endpoint_id'></span>' debug='false']</span>
273 + </pre>
274 + ",
278 275 ),
279 276 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>',
277 + 'name' => __( 'Endpoint', 'wpgetapi' ),
281 278 'id' => 'endpoint',
282 279 'type' => 'text',
283 - 'classes' => 'field-endpoint field-half',
280 + 'classes' => 'field-endpoint',
284 281 'attributes' => array(
285 282 'required' => true,
286 283 'placeholder' => '/newendpoint',
287 284 ),
288 - 'desc' => '',
285 + 'desc' => __( 'The endpoint that will be appended to the base URL to get the data. Include slash at beginning.', 'wpgetapi' ),
289 286 ),
290 287 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>',
288 + 'name' => __( 'Method', 'wpgetapi' ),
292 289 'id' => 'method',
293 290 'type' => 'select',
294 - 'classes' => 'field-method field-half',
291 + 'classes' => 'field-method',
295 292 'attributes' => array(
296 293 'required' => true,
297 294 ),
298 295 'options' => array(
@@ -297,164 +294,53 @@
297 294 ),
298 295 'options' => array(
299 296 'GET' => 'GET',
300 297 'POST' => 'POST',
301 - 'PUT' => 'PUT',
302 - 'PATCH' => 'PATCH',
303 - 'DELETE' => 'DELETE',
304 298 ),
305 - 'desc' => '',
299 + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ),
306 300 ),
307 -
308 301 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>',
302 + 'name' => __( 'Results Format', 'wpgetapi' ),
316 303 'id' => 'results_format',
317 304 'type' => 'select',
318 - 'classes' => 'field-results-format field-half',
305 + 'classes' => 'field-results-format',
319 306 'attributes' => array(
320 307 'required' => true,
321 308 ),
322 309 'options_cb' => 'wpgetapi_results_format_options',
323 - 'desc' => ''
310 + 'desc' => __( 'The format of the results.', 'wpgetapi' ),
324 311 ),
325 -
326 312 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>',
313 + 'name' => __( 'Query String', 'wpgetapi' ),
366 314 'id' => 'query_parameters',
367 315 'type' => 'parameter',
368 316 'classes' => 'field-query-parameters',
369 317 'repeatable' => true,
370 - 'desc' => '',
371 - 'before_row' => '<div class="fields-wrapper">'
318 + 'desc' => __( 'Parameters as name/value pairs that will be appended to the URL. ', 'wpgetapi' ),
372 319 ),
373 320 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>',
321 + 'name' => __( 'Headers', 'wpgetapi' ),
381 322 'id' => 'header_parameters',
382 323 'type' => 'parameter',
383 324 'classes' => 'field-header-parameters',
384 325 'repeatable' => true,
385 - 'desc' => ''
326 + 'desc' => __( 'Parameters as name/value pairs that will be included in the header. ', 'wpgetapi' ),
386 327 ),
387 328 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>',
329 + 'name' => __( 'Body', 'wpgetapi' ),
395 330 'id' => 'body_parameters',
396 331 'type' => 'parameter',
397 332 'classes' => 'field-body-parameters',
398 333 'repeatable' => true,
399 - 'desc' => ''
334 + 'desc' => __( 'Parameters as name/value pairs that will be included in the POST body. Only used when POST method is used and will be JSON encoded. ', 'wpgetapi' ),
400 335 ),
401 - array(
402 - 'name' => __( 'Encode Body', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Encoding of the above Body parameters.', 'wpgetapi' ) . '"></span>',
403 - 'id' => 'body_json_encode',
404 - 'type' => 'select',
405 - '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 -
413 - ),
414 - 'desc' => '',
415 - 'after_row' => '</div>',
416 - ),
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' ),
336 + ) );
433 337
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 338
451 - ) );
452 -
453 339 $fields[] = array(
454 340 'id' => 'endpoints',
455 341 'type' => 'group',
456 - 'name' => '',
342 + 'name' => __( 'Endpoints', 'wpgetapi' ),
457 343 'description' => '',
458 344 'options' => array(
459 345 'group_title' => __( 'Endpoint {#}', 'wpgetapi' ),
460 346 'add_button' => __( 'Add Endpoint', 'wpgetapi' ),
@@ -459,23 +345,18 @@
459 345 'group_title' => __( 'Endpoint {#}', 'wpgetapi' ),
460 346 'add_button' => __( 'Add Endpoint', 'wpgetapi' ),
461 347 'remove_button' => __( 'Remove Endpoint', 'wpgetapi' ),
462 348 'sortable' => true, // beta
463 - //'closed' => true,
464 349 ),
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>',
468 350 'fields' => $endpoint_fields,
469 351 );
470 352
471 - return apply_filters( 'wpgetapi_fields', $fields );
353 + return $fields;
472 354
473 355 }
474 356
475 357
476 358 public function add_options_pages() {
477 - add_thickbox();
478 359
479 360 $option_tabs = self::option_fields();
480 361
481 362 foreach ($option_tabs as $index => $option_tab) {
@@ -480,9 +361,9 @@
480 361
481 362 foreach ($option_tabs as $index => $option_tab) {
482 363 if ( $index == 0) {
483 364
484 - $this->options_pages[] = add_menu_page( $this->title, $this->menu_title, 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ), 'none'
365 + $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 366 ); //Link admin menu to first tab
486 367
487 368 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 369 } else {
@@ -510,66 +391,55 @@
510 391 <div class="wrap wpgetapi">
511 392
512 393 <div class="main_content_cell">
513 394
514 - <h1 class="wp-heading-inline">
515 - <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>
516 - </h1>
395 + <h2><?php esc_html_e( $this->title, 'wpgetapi' ) ?></h2>
396 + <!-- Options Page Nav Tabs -->
397 + <h2 class="nav-tab-wrapper">
398 + <?php foreach ($option_tabs as $option_tab) :
399 + $tab_slug = $option_tab['id'];
400 + $nav_class = 'nav-tab';
401 + if ( $tab_slug == $_GET['page'] ) {
402 + $nav_class .= ' nav-tab-active'; //add active class to current tab
403 + $tab_forms[] = $option_tab; //add current tab to forms to be rendered
404 + }
405 + ?>
406 + <a class="<?php esc_attr_e( $nav_class ); ?>" href="<?php esc_url( menu_page_url( $tab_slug ) ); ?>"><?php esc_attr_e( $option_tab['title'], 'wpgetapi' ); ?></a>
407 + <?php endforeach; ?>
408 + </h2>
409 + <!-- End of Nav Tabs -->
517 410
518 - <div class="outer-box">
519 - <!-- Options Page Nav Tabs -->
520 - <h2 class="nav-tab-wrapper">
521 - <?php foreach ($option_tabs as $option_tab) :
522 -
523 - $tab_slug = $option_tab['id'];
524 - $nav_class = 'nav-tab';
525 - if ( $tab_slug == $_GET['page'] ) {
526 - $nav_class .= ' nav-tab-active'; //add active class to current tab
527 - $tab_forms[] = $option_tab; //add current tab to forms to be rendered
528 - }
529 -
530 - ?>
531 -
532 - <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>
533 -
534 - <?php endforeach; ?>
535 - </h2>
536 - <!-- End of Nav Tabs -->
537 -
538 - <?php
539 - //render all tab forms (normaly just 1 form)
540 - foreach ($tab_forms as $tab_form) : ?>
541 -
542 - <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
543 - <div class="metabox-holder">
544 -
545 - <div id="my-content-id" style="display:none;">
546 - <div>
547 - <?php echo $this->get_import_export(); ?>
548 - </div>
549 - </div>
550 -
551 - <div class="pmpbox pad">
552 - <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
553 - <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
554 - <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?>
555 - </div>
411 + <?php foreach ($tab_forms as $tab_form) : //render all tab forms (normaly just 1 form) ?>
412 +
413 + <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group">
414 + <div class="metabox-holder">
415 + <div class="pmpbox pad">
416 + <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3>
417 + <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div>
418 + <?php cmb2_metabox_form( $tab_form, $tab_form['id'] ); ?>
556 419 </div>
557 420 </div>
421 + </div>
558 422
559 - <?php endforeach; ?>
423 + <?php endforeach; ?>
560 424
561 - </div>
562 -
563 425 </div>
564 426
565 427 <div class="sidebar_cell">
566 -
567 - <?php
568 - $sidebar = self::sidebar_display();
569 - echo apply_filters( 'wpgetapi_admin_sidebar_display', $sidebar );
570 - ?>
428 + <div class="box">
429 + <h3>Help & Tips</h3>
430 + <p><a target="_blank" href="https://wpgetapi.com/docs">View The Docs</a></p>
431 + <p>Using the Template Function within your theme is the most flexible option. It does require basic knowledge of PHP.</p>
432 + <p>Trying to 'echo' the data when using the 'JSON (as array data)' option will result in a PHP warning. You will need to use 'var_dump' instead to see the output.</p>
433 + <p>Using the Shortcode within a page (or post) becomes more flexible when used in conjunction with our <a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin">WPGetAPI Pro</a> plugin extension.</p>
571 434
435 + <p>You can easily get nested data from the array using our <a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin">WPGetAPI Pro</a> plugin extension using either Shortcode or Template Function.</p>
436 +
437 + </div>
438 + <div class="box">
439 + <h3>Contact Us</h3>
440 + <p>Please <a target="_blank" href="https://wpgetapi.com/">visit our website</a> for any questions, help or feature requests. We are more than happy to help you set up your API.</p>
441 + </div>
572 442 </div>
573 443
574 444 </div>
575 445
@@ -575,419 +445,8 @@
575 445
576 446 <?php
577 447
578 448 }
579 -
580 -
581 - public function test_the_endpoint() {
582 -
583 - $api_id = sanitize_text_field( $_POST['api_id'] );
584 - $endpoint_id = sanitize_text_field( $_POST['endpoint_id'] );
585 - $data = wpgetapi_endpoint( $api_id, $endpoint_id, array( 'test_endpoint' => true ) );
586 -
587 - $output = array(
588 - 'data' => $data,
589 - 'endpoint_id' => $endpoint_id
590 - );
591 - echo json_encode( $output );
592 -
593 - wp_die(); // this is required to terminate immediately and return a proper response
594 -
595 - }
596 -
597 - public function get_import_export() {
598 - ob_start(); ?>
599 -
600 - <div class="wpgetapi-export">
601 - <h3><span class="dashicons dashicons-download"></span> Export Endpoints</h3>
602 - <p>Export the endpoints for this API.<br>After clicking the button below, copy the entire contents of the export.</p>
603 - <button class="button button-primary">Export Endpoints</button>
604 - <div class="message"></div>
605 - </div>
606 -
607 - <div class="wpgetapi-import">
608 - <h3><span class="dashicons dashicons-upload"></span> Import Endpoints</h3>
609 - <p>Paste your exported JSON data into the field below to import endpoints into this API.</p>
610 - <textarea></textarea>
611 - <button class="button button-primary">Import Endpoints</button>
612 - <div class="message"></div>
613 - </div>
614 -
615 - <?php
616 - $content = ob_get_contents();
617 - ob_end_clean();
618 - return $content;
619 - }
620 -
621 - /**
622 - * AJAX function to get our endpoints for export.
623 - *
624 - */
625 - public function export_endpoints() {
626 - $api_id = sanitize_text_field( $_POST['api_id'] );
627 - $data = get_option( $api_id );
628 -
629 - if( ! isset( $data['endpoints'] ) )
630 - wp_die();
631 -
632 - $encryption = new WpGetApi_Encryption();
633 -
634 - foreach ( $data['endpoints'] as $i => $endpoint ) {
635 - if( isset( $endpoint['query_parameters'] ) ) {
636 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
637 - if( isset( $query_parameters['value'] ) )
638 - $data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->decrypt( $query_parameters['value'] );
639 - }
640 - }
641 - if( isset( $endpoint['header_parameters'] ) ) {
642 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
643 - if( isset( $header_parameters['value'] ) )
644 - $data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->decrypt( $header_parameters['value'] );
645 - }
646 - }
647 - if( isset( $endpoint['body_parameters'] ) ) {
648 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
649 - if( isset( $body_parameters['value'] ) )
650 - $data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->decrypt( $body_parameters['value'] );
651 - }
652 - }
653 - }
654 -
655 - echo json_encode( $data );
656 - wp_die(); // this is required to terminate immediately and return a proper response
657 - }
658 -
659 - /**
660 - * AJAX function to import our endpoints.
661 - *
662 - */
663 - public function import_endpoints() {
664 -
665 - $api_id = sanitize_text_field( $_POST['api_id'] );
666 - $textarea = sanitize_textarea_field( $_POST['textarea'] );
667 - $existing_data = get_option( $api_id );
668 -
669 - if( ! $textarea ) {
670 - echo 'No data found.';
671 - wp_die();
672 - }
673 -
674 - $new_data = json_decode( stripslashes( $textarea ), true );
675 - if( ! isset( $new_data['endpoints'] ) ){
676 - echo 'No endpoints found.';
677 - wp_die();
678 - }
679 -
680 - $encryption = new WpGetApi_Encryption();
681 -
682 - foreach ( $new_data['endpoints'] as $i => $endpoint ) {
683 - if( isset( $endpoint['query_parameters'] ) ) {
684 - foreach ( $endpoint['query_parameters'] as $i2 => $query_parameters ) {
685 - if( isset( $query_parameters['value'] ) )
686 - $new_data['endpoints'][ $i ]['query_parameters'][ $i2 ]['value'] = $encryption->encrypt( $query_parameters['value'] );
687 - }
688 - }
689 - if( isset( $endpoint['header_parameters'] ) ) {
690 - foreach ( $endpoint['header_parameters'] as $i2 => $header_parameters ) {
691 - if( isset( $header_parameters['value'] ) )
692 - $new_data['endpoints'][ $i ]['header_parameters'][ $i2 ]['value'] = $encryption->encrypt( $header_parameters['value'] );
693 - }
694 - }
695 - if( isset( $endpoint['body_parameters'] ) ) {
696 - foreach ( $endpoint['body_parameters'] as $i2 => $body_parameters ) {
697 - if( isset( $body_parameters['value'] ) )
698 - $new_data['endpoints'][ $i ]['body_parameters'][ $i2 ]['value'] = $encryption->encrypt( $body_parameters['value'] );
699 - }
700 - }
701 - }
702 -
703 - // if no existing endpoints, simply add it
704 - if( ! $existing_data ) {
705 - update_option( $api_id, $new_data, 'no' );
706 - } else {
707 -
708 - $merged['endpoints'] = array_merge( $existing_data['endpoints'], $new_data['endpoints'] );
709 - update_option( $api_id, $merged, 'no' );
710 - }
711 -
712 - echo 'Successfully imported. Reloading...';
713 - wp_die(); // this is required to terminate immediately and return a proper response
714 - }
715 -
716 -
717 - public function load_testing_javascript() { ?>
718 -
719 - <script type="text/javascript" >
720 -
721 - jQuery(document).ready(function($) {
722 -
723 - /**
724 - * Collapse the endpoints
725 - *
726 - */
727 - $('body').on( 'click', '.wpgetapi .collapse .button', function(){
728 -
729 - var $this = $(this);
730 - var $collapse = $(this).parents('.collapse');
731 - var status = 'open';
732 -
733 - $collapse.toggleClass('open');
734 -
735 - if( ! $collapse.hasClass( 'open' ) )
736 - status = 'closed';
737 -
738 - var $endpoints = $( '#endpoints_repeat .postbox.cmb-repeatable-grouping' );
739 - $endpoints.each( function() {
740 -
741 - if( status == 'closed' ) {
742 - $( this ).addClass('closed');
743 - } else {
744 - $( this ).removeClass('closed');
745 - }
746 -
747 - });
748 -
749 - });
750 -
751 - /**
752 - * Run the export
753 - *
754 - */
755 - $('body').on( 'click', '.wpgetapi-export .button', function(){
756 -
757 - var $this = $(this);
758 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
759 -
760 - // disable button
761 - $this.attr( 'disabled', true );
762 -
763 - var data = {
764 - 'action': 'wpgetapi_export_endpoints',
765 - 'api_id': api_id,
766 - };
767 -
768 - // send and get response
769 - jQuery.post(ajaxurl, data, function( response ) {
770 - $( '.wpgetapi-export .message' ).show().html( response );
771 - // enable button
772 - $( '.wpgetapi-export .button' ).attr( 'disabled', false );
773 -
774 - });
775 -
776 - });
777 -
778 - /**
779 - * Run the import
780 - *
781 - */
782 - $('body').on( 'click', '.wpgetapi-import .button', function(){
783 -
784 - var $this = $(this);
785 - var api_id = $('.wpgetapi.wrap').find( '.cmb-form.group' ).attr( 'id' );
786 - var textarea = $('.wpgetapi-import textarea').val();
787 -
788 - // disable button
789 - $this.attr( 'disabled', true );
790 -
791 - var data = {
792 - 'action': 'wpgetapi_import_endpoints',
793 - 'textarea': textarea,
794 - 'api_id': api_id,
795 - };
796 -
797 - // send and get response
798 - jQuery.post(ajaxurl, data, function( response ) {
799 -
800 - $( '.wpgetapi-import .message' ).html( response );
801 -
802 - if( response == 'Successfully imported. Reloading...' ) {
803 - setTimeout(function(){
804 - location.reload();
805 - }, 1000);
806 - } else {
807 - $( '.wpgetapi-import .button' ).attr( 'disabled', false );
808 - }
809 -
810 - });
811 -
812 - });
813 -
814 - /**
815 - * Run the endpoint test
816 - *
817 - */
818 - $('body').on( 'click', '.wpgetapi .test-endpoint-button', function(){//delegated
819 -
820 - var $this = $(this);
821 - var $parent = $this.closest( '.cmb-repeatable-grouping' );
822 - var area = $parent.find( '.wpgetapi-test-area' );
823 - var api_id = $( area ).data( 'api' );
824 - var endpoint_id = $( area ).data( 'endpoint' );
825 -
826 - // disable button
827 - $this.attr( 'disabled', true );
828 -
829 - var data = {
830 - 'action': 'wpgetapi_test_endpoint',
831 - 'api_id': api_id,
832 - 'endpoint_id': endpoint_id
833 - };
834 -
835 - // send and get response
836 - jQuery.post(ajaxurl, data, function( response ) {
837 -
838 - var output = JSON.parse( response );
839 -
840 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show();
841 - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( output.data);
842 -
843 - // enable button
844 - $( '.wpgetapi .test-endpoint-button' ).attr( 'disabled', false );
845 -
846 - });
847 -
848 - });
849 -
850 - $( '.wpgetapi-test-area .handle' ).on('click', function() {
851 - $('.wpgetapi-result').toggle();
852 - });
853 -
854 - });
855 -
856 - </script> <?php
857 -
858 - }
859 -
860 -
861 - /**
862 - * Sidebar markup.
863 - * @since 1.4.1
864 - */
865 - public function sidebar_display() {
866 -
867 - ob_start();
868 -
869 - // do our setup page
870 - if( isset( $_GET['page'] ) && $_GET['page'] === 'wpgetapi_setup' )
871 - return $this->sidebar_setup_page();
872 -
873 - ?>
874 -
875 - <div class="box">
876 - <h4><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></h4>
877 - <ol>
878 - <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
879 - <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li>
880 - <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li>
881 - <li><?php _e( 'Set the desired <b>Results Format</b>', 'wpgetapi' ); ?></li>
882 - <li><?php _e( 'Other fields are optional & will depend on your API', 'wpgetapi' ); ?></li>
883 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
884 - <li><?php _e( 'Copy the Template Tag or Shortcode & paste into page, post or theme file', 'wpgetapi' ); ?></li>
885 - </ol>
886 - </div>
887 -
888 - <?php echo $this->help_box(); ?>
889 -
890 - <?php
891 - $content = ob_get_contents();
892 - ob_end_clean();
893 - return $content;
894 -
895 - }
896 -
897 -
898 - /**
899 - * Sidebar for our setup page.
900 - * @since 1.4.4
901 - */
902 - public function sidebar_setup_page() {
903 -
904 - ob_start();
905 - ?>
906 -
907 - <div class="box">
908 - <h4><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></h4>
909 - <ol>
910 - <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li>
911 - <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li>
912 - <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li>
913 - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li>
914 - <li><?php _e( 'Visit the new tab that will be created', 'wpgetapi' ); ?></li>
915 - </ol>
916 - </div>
917 -
918 - <?php echo $this->help_box(); ?>
919 -
920 - <?php
921 - $content = ob_get_contents();
922 - ob_end_clean();
923 - return $content;
924 -
925 - }
926 -
927 -
928 - /**
929 - *
930 - * @since 1.4.4
931 - */
932 - public function help_box() {
933 -
934 - ob_start();
935 - ?>
936 -
937 - <div class="box help-box">
938 - <h4><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></h4>
939 - <ul>
940 - <li><?php
941 - printf(
942 - esc_html__( 'View the %1$s', 'cmb2' ),
943 - '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">Quick Start Guide</a>'
944 - );
945 - ?></li>
946 - <li><?php
947 - printf(
948 - esc_html__( 'View the %1$s', 'cmb2' ),
949 - '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>'
950 - );
951 - ?></li>
952 -
953 - <?php if( ! $this->pro_plugin ) { ?>
954 - <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>
955 - <?php } ?>
956 - </ul>
957 - </div>
958 -
959 - <?php
960 - $content = ob_get_contents();
961 - ob_end_clean();
962 - return $content;
963 -
964 - }
965 -
966 -
967 - /**
968 - * Tabs don't immmediately appear on save, so this hack!
969 - * @since 0.1.0
970 - */
971 - public function redirect( $object_id, $updated ) {
972 -
973 - if( strpos( $object_id, 'wpgetapi_' ) !== false && strpos( $object_id, 'wpgetapi_api_importer' ) == false ) {
974 -
975 - add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' );
976 - settings_errors( 'wpgetapi-notices' );
977 - ?>
978 -
979 - <script>
980 - setTimeout(function() {
981 - location.reload();
982 - }, 200);
983 - </script>
984 - <?php
985 -
986 - }
987 -
988 - }
989 -
990 449
991 450 /**
992 451 * Public getter method for retrieving protected/private variables
993 452 * @since 0.1.0