diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 502bc880ec8..f22a17df7c6 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7496,13 +7496,22 @@ function get_plugins_with_function($function, $file = 'lib.php', $include = true $key = $function . '_' . clean_param($file, PARAM_ALPHA); $pluginfunctions = $cache->get($key); + // Use the plugin manager to check that plugins are currently installed. + $pluginmanager = \core_plugin_manager::instance(); + if ($pluginfunctions !== false) { // Checking that the files are still available. foreach ($pluginfunctions as $plugintype => $plugins) { $allplugins = \core_component::get_plugin_list($plugintype); - foreach ($plugins as $plugin => $fullpath) { + $installedplugins = $pluginmanager->get_installed_plugins($plugintype); + foreach ($plugins as $plugin => $function) { + if (!isset($installedplugins[$plugin])) { + // Plugin code is still present on disk but it is not installed. + unset($pluginfunctions[$plugintype][$plugin]); + continue; + } // Cache might be out of sync with the codebase, skip the plugin if it is not available. if (empty($allplugins[$plugin])) { @@ -7531,8 +7540,13 @@ function get_plugins_with_function($function, $file = 'lib.php', $include = true // We need to include files here. $pluginswithfile = \core_component::get_plugin_list_with_file($plugintype, $file, true); + $installedplugins = $pluginmanager->get_installed_plugins($plugintype); foreach ($pluginswithfile as $plugin => $notused) { + if (!isset($installedplugins[$plugin])) { + continue; + } + $fullfunction = $plugintype . '_' . $plugin . '_' . $function; $pluginfunction = false;