wp_validate_boolean( mixed $value ): bool

Filters/validates a variable as a boolean.

Description

Alternative to filter_var( $value, FILTER_VALIDATE_BOOLEAN ).

Parameters

$valuemixedrequired
Boolean value to validate.

Return

bool Whether the value is validated.

Source

		array_push( $encodings, $encoding );
		mb_internal_encoding( 'ISO-8859-1' );
	}

	if ( $reset && $encodings ) {
		$encoding = array_pop( $encodings );
		mb_internal_encoding( $encoding );
	}
}

/**

Changelog

VersionDescription
4.0.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    wp_validate_boolean() tests:

    wp_validate_boolean(true)); //returns bool(true)
    wp_validate_boolean(false)); //returns bool(false)
    wp_validate_boolean('true')); //returns bool(true)
    wp_validate_boolean('false')); //returns bool(false)
    wp_validate_boolean('test')); //returns bool(true)
    wp_validate_boolean(123)); //returns bool(true)
    wp_validate_boolean(0)); //returns bool(false)
    wp_validate_boolean(null)); //returns bool(false)
    wp_validate_boolean([]); //returns bool(false)
    wp_validate_boolean(['test']); //returns bool(true)
    wp_validate_boolean([123]); //returns bool(true)
    wp_validate_boolean(new StdClass()) //returns bool(true)
    wp_validate_boolean()); //returns Error

You must log in before being able to contribute a note or feedback.