WP_Site_Health::test_php_extension_availability()privateWP 5.2.0

Checks 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.

{} Это метод класса: WP_Site_Health{}

Хуков нет.

Возвращает

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

Использование

// private - только в коде основоного (родительского) класса
$result = $this->test_php_extension_availability( $extension_name, $function_name, $constant_name, $class_name );
$extension_name(строка)
The extension name to test.
По умолчанию: null
$function_name(строка)
The function name to test.
По умолчанию: null
$constant_name(строка)
The constant name to test for.
По умолчанию: null
$class_name(строка)
The class name to test for.
По умолчанию: null

Список изменений

С версии 5.2.0 Введена.
С версии 5.3.0 The $constant_name and $class_name parameters were added.

Код WP_Site_Health::test_php_extension_availability() WP 6.1.1

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

	if ( $extension_name && ! extension_loaded( $extension_name ) ) {
		return false;
	}

	if ( $function_name && ! function_exists( $function_name ) ) {
		return false;
	}

	if ( $constant_name && ! defined( $constant_name ) ) {
		return false;
	}

	if ( $class_name && ! class_exists( $class_name ) ) {
		return false;
	}

	return true;
}