tribe_is_truthy( mixed $var )
Determines if the provided value should be regarded as ‘true’.
Contents
Parameters
- $var
-
(mixed) (Required)
Return
(bool)
Source
File: src/functions/utils.php
function tribe_is_truthy( $var ) {
if ( is_bool( $var ) ) {
return $var;
}
/**
* Provides an opportunity to modify strings that will be
* deemed to evaluate to true.
*
* @param array $truthy_strings
*/
$truthy_strings = (array) apply_filters( 'tribe_is_truthy_strings', array(
'1',
'enable',
'enabled',
'on',
'y',
'yes',
'true',
) );
// Makes sure we are dealing with lowercase for testing
if ( is_string( $var ) ) {
$var = strtolower( $var );
}
// If $var is a string, it is only true if it is contained in the above array
if ( in_array( $var, $truthy_strings, true ) ) {
return true;
}
// All other strings will be treated as false
if ( is_string( $var ) ) {
return false;
}
// For other types (ints, floats etc) cast to bool
return (bool) $var;
}