get_plugins() doesn’t work after plugins_loaded

Possibly you’re trying to use that code in a non-admin page. The functon get_plugins is only available on admin side and if you ant to use it somewhere else you have to load the file “plugin.php” manually.

To solve this error add that check at the beginning of your function:

    if ( ! function_exists( 'get_plugins' ) ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }