PluginProbe
WPGet API – Connect to any external REST API / 1.7.9
WPGet API – Connect to any external REST API v1.7.9
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
wpgetapi / includes / functions.php

functions.php in WPGet API – Connect to any external REST API 1.7.9, at includes/functions.php

89 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Pretty print when debugging is enabled in options
5 */
6 if (!function_exists('wpgetapi_pp')) {
7 function wpgetapi_pp( $array ) {
8 echo '<pre style="white-space:pre-wrap;">';
9 print_r( $array );
10 echo '</pre>' . "\n";
11 }
12 }
13
14
15 /**
16 * Dropdown options for results_format
17 * It is set up this way so we can easily add the filter to be able to add extra format options
18 *
19 */
20 function wpgetapi_results_format_options( $field ) {
21 $options = apply_filters( 'wpgetapi_results_format_options', array(
22 'json_string' => __( 'JSON string', 'wpgetapi' ),
23 'json_decoded' => __( 'PHP array data', 'wpgetapi' ),
24 ) );
25 return $options;
26 }
27
28
29 /**
30 * Recursive sanitation for text or array
31 *
32 * @param $array_or_string (array|string)
33 * @since 1.0.0
34 * @return mixed
35 */
36 function wpgetapi_sanitize_text_or_array($array_or_string) {
37 if( is_string($array_or_string) ){
38 $array_or_string = sanitize_text_field($array_or_string);
39 }elseif( is_array($array_or_string) ){
40 foreach ( $array_or_string as $key => &$value ) {
41 if ( is_array( $value ) ) {
42 $value = wpgetapi_sanitize_text_or_array($value);
43 }
44 else {
45 $value = sanitize_text_field( $value );
46 }
47 }
48 }
49
50 return $array_or_string;
51 }
52
53
54 /**
55 * wpgetapi_output_endpoint_test_area
56 *
57 */
58 function wpgetapi_output_top_of_endpoint( $field_args, $field ) {
59
60 ob_start();
61
62 $test_disabled = true;
63
64 if( $field->value )
65 $test_disabled = false;
66
67 ?>
68
69 <pre class="functions">
70 Template Tag: </span><span>wpgetapi_endpoint( '<?php esc_html_e( $field->args['api_id'] ); ?>', '<span class='endpoint_id'></span>', array('debug' => false) );</span><br>
71 Shortcode: <span>[wpgetapi_endpoint api_id='<?php esc_html_e( $field->args['api_id'] ); ?>' endpoint_id='<span class='endpoint_id'></span>' debug='false']</span>
72 </pre>
73
74 <div class="wpgetapi-test-area" data-endpoint="<?php esc_attr_e( $field->value ); ?>" data-api="<?php esc_attr_e( $field->args['api_id'] ); ?>">
75 <a class="test-button button-primary" href="#" <?php echo $test_disabled ? 'disabled' : ''; ?>><?php _e( 'Test Endpoint', 'wpgetapi' ); ?></a>
76 <span class="handle" style="display:none">Hide/Show Results</span>
77 <div class="wpgetapi-result"></div>
78 </div>
79
80 <?php
81
82 $content = ob_get_contents();
83 ob_end_clean();
84 return $content;
85
86 return $field_args;
87
88 }
89