Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active October 18, 2017 19:38
Show Gist options
  • Save wpscholar/cffb53d6f26b9011e95675556c67ba95 to your computer and use it in GitHub Desktop.
Save wpscholar/cffb53d6f26b9011e95675556c67ba95 to your computer and use it in GitHub Desktop.
A function for converting callables to values, or allowing values to simply pass through.
<?php
/**
* Check if value is a callable, if so, covert the callable to a value.
* Accepts any number of additional arguments, all of which will be passed to the callable.
*
* @param callable|mixed $value
*
* @return mixed
*/
protected function maybe_convert_callable( $value ) {
if ( is_callable( $value ) ) {
$args = func_get_args();
array_shift( $args );
$value = call_user_func_array( $value, $args );
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment