Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created February 11, 2014 17:33
Show Gist options
  • Save wpscholar/8939803 to your computer and use it in GitHub Desktop.
Save wpscholar/8939803 to your computer and use it in GitHub Desktop.
Sanitize a value by passing it through one or more sanitization callbacks.
<?php
/**
* Sanitize a value by passing it through one or more sanitization callbacks.
*
* @param mixed $value
* @param callable|array $sanitize
* @return mixed
*/
function sanitize( $value, $sanitize ) {
$callbacks = is_callable( $sanitize ) ? array( $sanitize ) : (array) $sanitize;
foreach ( $callbacks as $callback ) {
if ( is_callable( $callback ) ) {
$value = call_user_func( $callback, $value );
}
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment