Skip to content

Instantly share code, notes, and snippets.

@jimboobrien
Forked from wpscholar/sanitize.php
Created September 20, 2017 23:18
Show Gist options
  • Save jimboobrien/eb2919c0e2ca5e189d0d761e0d8e009f to your computer and use it in GitHub Desktop.
Save jimboobrien/eb2919c0e2ca5e189d0d761e0d8e009f 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