public function sortPlugins(array $plugins)
    {
        $global = $this->getPluginsBundledWithPiwik();
        if (empty($global)) {
            return $plugins;
        }

        // we need to make sure a possibly disabled plugin will be still loaded before any 3rd party plugin
        $global = array_merge($global, $this->corePluginsDisabledByDefault);

        $global = array_values($global);
        $plugins = array_values($plugins);

        $defaultPluginsLoadedFirst = array_intersect($global, $plugins);

        $otherPluginsToLoadAfterDefaultPlugins = array_diff($plugins, $defaultPluginsLoadedFirst);

        // sort by name to have a predictable order for those extra plugins
        natcasesort($otherPluginsToLoadAfterDefaultPlugins);

        $sorted = array_merge($defaultPluginsLoadedFirst, $otherPluginsToLoadAfterDefaultPlugins);

        return $sorted;
    }