General: Correct the fallback logic in apache_mod_loaded().

If the `apache_get_modules()` function is redeclared to return an empty array, `apache_mod_loaded()` would assume that no Apache modules are installed and activated, which may not be correct.

This commit improves the logic by using pre-existing `phpinfo()` fallback to check for loaded modules in that case.

Includes replacing a hardcoded number passed as a flag to `phpinfo()` with the `INFO_MODULES` predefined constant for clarity.

Follow-up to [7441], [7508], [29330].

Props engahmeds3ed, audrasjb, Clorith, SergeyBiryukov.
Fixes #56010.

git-svn-id: https://develop.svn.wordpress.org/trunk@54299 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-09-24 13:51:22 +00:00
parent 865870e332
commit 4f58e18cba
+15 -6
View File
@@ -5888,15 +5888,24 @@ function apache_mod_loaded( $mod, $default = false ) {
return false;
}
$loaded_mods = array();
if ( function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
if ( in_array( $mod, $mods, true ) ) {
$loaded_mods = apache_get_modules();
if ( in_array( $mod, $loaded_mods, true ) ) {
return true;
}
} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
ob_start();
phpinfo( 8 );
$phpinfo = ob_get_clean();
}
if ( empty( $loaded_mods )
&& function_exists( 'phpinfo' )
&& false === strpos( ini_get( 'disable_functions' ), 'phpinfo' )
) {
ob_start();
phpinfo( INFO_MODULES );
$phpinfo = ob_get_clean();
if ( false !== strpos( $phpinfo, $mod ) ) {
return true;
}