Last active
October 18, 2017 19:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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