pods_sanitize

Filter input and return sanitized output.

Description

(array|mixed|object|string|void) pods_sanitize( (mixed) $input, (array) $params = array() ); 

Returns (array|mixed|object|string|void)

Parameters (2)

0. $input (mixed)
The string, array, or object to sanitize
1. $params — Optional. (array) => array()
Additional options

Usage

  1. if ( !function_exists( 'pods_sanitize' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/data.php'; 
  3.  
  4. // The string, array, or object to sanitize 
  5. $input = null; 
  6.  
  7. // Additional options 
  8. $params = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pods_sanitize($input, $params); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/data.php  
  1. function pods_sanitize( $input, $params = array() ) { 
  2.  
  3. if ( '' === $input || is_int( $input ) || is_float( $input ) || empty( $input ) ) { 
  4. return $input; 
  5.  
  6. $output = array(); 
  7.  
  8. $defaults = array( 
  9. 'nested' => false,  
  10. 'type' => null // %s %d %f etc 
  11. ); 
  12.  
  13. if ( !is_array( $params ) ) { 
  14. $defaults[ 'type' ] = $params; 
  15.  
  16. $params = $defaults; 
  17. else { 
  18. $params = array_merge( $defaults, (array) $params ); 
  19.  
  20. if ( is_object( $input ) ) { 
  21. $input = get_object_vars( $input ); 
  22.  
  23. $n_params = $params; 
  24. $n_params[ 'nested' ] = true; 
  25.  
  26. foreach ( $input as $key => $val ) { 
  27. $output[ pods_sanitize( $key ) ] = pods_sanitize( $val, $n_params ); 
  28.  
  29. $output = (object) $output; 
  30. elseif ( is_array( $input ) ) { 
  31. $n_params = $params; 
  32. $n_params[ 'nested' ] = true; 
  33.  
  34. foreach ( $input as $key => $val ) { 
  35. $output[ pods_sanitize( $key ) ] = pods_sanitize( $val, $n_params ); 
  36. elseif ( !empty( $params[ 'type' ] ) && false !== strpos( $params[ 'type' ], '%' ) ) { 
  37. /** 
  38. * @var $wpdb wpdb 
  39. */ 
  40. global $wpdb; 
  41.  
  42. $output = $wpdb->prepare( $params[ 'type' ], $output ); 
  43. // @todo Switch this full over to esc_sql once we get sanitization sane again in PodsAPI so we *don't* have to unsanitize in various places 
  44. elseif ( function_exists( 'wp_slash' ) ) { 
  45. $output = wp_slash( $input ); 
  46. else { 
  47. $output = esc_sql( $input ); 
  48.  
  49. return $output; 
  50.