WordPress at Your Fingertips
function is not described

WP_Site_Health::test_php_extension_availability() private WP 5.2.0

Check if the passed extension or function are available.

Make the check for available PHP modules into a simple boolean operator for a cleaner test runner.

{} It's a method of the class: WP_Site_Health{}

No Hooks.

Return

true|false. Whether or not the extension and function are available.

Usage

// private - for code of main (parent) class only
$result = $this->test_php_extension_availability( $extension, $function, $constant, $class );
$extension(string)
The extension name to test.
Default: null
$function(string)
The function name to test.
Default: null
$constant(string)
The constant name to test for.
Default: null
$class(string)
The class name to test for.
Default: null

Changelog

Since 5.2.0 Introduced.
Since 5.3.0 The $constant and $class parameters were added.

Code of WP_Site_Health::test_php_extension_availability() WP 5.8.2

private function test_php_extension_availability( $extension = null, $function = null, $constant = null, $class = null ) {
	// If no extension or function is passed, claim to fail testing, as we have nothing to test against.
	if ( ! $extension && ! $function && ! $constant && ! $class ) {
		return false;
	}

	if ( $extension && ! extension_loaded( $extension ) ) {
		return false;
	}
	if ( $function && ! function_exists( $function ) ) {
		return false;
	}
	if ( $constant && ! defined( $constant ) ) {
		return false;
	}
	if ( $class && ! class_exists( $class ) ) {
		return false;
	}

	return true;
}