| 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', |
| 23 |
'json_decoded' => 'PHP array data', |
| 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 |
} |