get_plugins

The timeline below displays how wordpress function get_plugins has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Checks the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 * and must be found in those two locations. It is recommended to keep your
 * plugin files in their own directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array[] Array of arrays of plugin data, keyed by plugin file name. See get_plugin_data().
 */
function get_plugins($plugin_folder = '')
{
    $cache_plugins = wp_cache_get('plugins', 'plugins');
    if (!$cache_plugins) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory.
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if (str_starts_with($file, '.')) {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if (str_starts_with($subfile, '.')) {
                            continue;
                        }
                        if (str_ends_with($subfile, '.php')) {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if (str_ends_with($file, '.php')) {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        // Do not apply markup/translate as it will be cached.
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}

WordPress Version: 6.1

/**
 * Checks the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 * and must be found in those two locations. It is recommended to keep your
 * plugin files in their own directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array[] Array of arrays of plugin data, keyed by plugin file name. See get_plugin_data().
 */
function get_plugins($plugin_folder = '')
{
    $cache_plugins = wp_cache_get('plugins', 'plugins');
    if (!$cache_plugins) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory.
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if ('.' === substr($file, 0, 1)) {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if ('.' === substr($subfile, 0, 1)) {
                            continue;
                        }
                        if ('.php' === substr($subfile, -4)) {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if ('.php' === substr($file, -4)) {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        // Do not apply markup/translate as it will be cached.
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}

WordPress Version: 5.5

/**
 * Check the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 * and must be found in those two locations. It is recommended to keep your
 * plugin files in their own directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array[] Array of arrays of plugin data, keyed by plugin file name. See `get_plugin_data()`.
 */
function get_plugins($plugin_folder = '')
{
    $cache_plugins = wp_cache_get('plugins', 'plugins');
    if (!$cache_plugins) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory.
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if ('.' === substr($file, 0, 1)) {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if ('.' === substr($subfile, 0, 1)) {
                            continue;
                        }
                        if ('.php' === substr($subfile, -4)) {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if ('.php' === substr($file, -4)) {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        // Do not apply markup/translate as it will be cached.
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}

WordPress Version: 5.4

/**
 * Check the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 * and must be found in those two locations. It is recommended to keep your
 * plugin files in their own directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array[] Array of arrays of plugin data, keyed by plugin file name. See `get_plugin_data()`.
 */
function get_plugins($plugin_folder = '')
{
    $cache_plugins = wp_cache_get('plugins', 'plugins');
    if (!$cache_plugins) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory.
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if (substr($subfile, 0, 1) == '.') {
                            continue;
                        }
                        if (substr($subfile, -4) == '.php') {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if (substr($file, -4) == '.php') {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        // Do not apply markup/translate as it will be cached.
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}

WordPress Version: 5.3

/**
 * Check the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 * and must be found in those two locations. It is recommended to keep your
 * plugin files in their own directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array Key is the plugin file path and the value is an array of the plugin data.
 */
function get_plugins($plugin_folder = '')
{
    $cache_plugins = wp_cache_get('plugins', 'plugins');
    if (!$cache_plugins) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory.
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if (substr($subfile, 0, 1) == '.') {
                            continue;
                        }
                        if (substr($subfile, -4) == '.php') {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if (substr($file, -4) == '.php') {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        //Do not apply markup/translate as it'll be cached.
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}

WordPress Version: 5.1

/**
 * Check the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 * and must be found in those two locations. It is recommended to keep your
 * plugin files in their own directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array Key is the plugin file path and the value is an array of the plugin data.
 */
function get_plugins($plugin_folder = '')
{
    $cache_plugins = wp_cache_get('plugins', 'plugins');
    if (!$cache_plugins) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if (substr($subfile, 0, 1) == '.') {
                            continue;
                        }
                        if (substr($subfile, -4) == '.php') {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if (substr($file, -4) == '.php') {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        //Do not apply markup/translate as it'll be cached.
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}

WordPress Version: 4.3

/**
 * Check the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 * and must be found in those two locations. It is recommended to keep your
 * plugin files in their own directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array Key is the plugin file path and the value is an array of the plugin data.
 */
function get_plugins($plugin_folder = '')
{
    if (!$cache_plugins = wp_cache_get('plugins', 'plugins')) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if (substr($subfile, 0, 1) == '.') {
                            continue;
                        }
                        if (substr($subfile, -4) == '.php') {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if (substr($file, -4) == '.php') {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        //Do not apply markup/translate as it'll be cached.
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}

WordPress Version: 3.7

/**
 * Check the plugins directory and retrieve all plugin files with plugin data.
 *
 * WordPress only supports plugin files in the base plugins directory
 * (wp-content/plugins) and in one directory above the plugins directory
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data and
 * must be found in those two locations. It is recommended that do keep your
 * plugin files in directories.
 *
 * The file with the plugin data is the file that will be included and therefore
 * needs to have the main execution for the plugin. This does not mean
 * everything must be contained in the file and it is recommended that the file
 * be split for maintainability. Keep everything in one file for extreme
 * optimization purposes.
 *
 * @since 1.5.0
 *
 * @param string $plugin_folder Optional. Relative path to single plugin folder.
 * @return array Key is the plugin file path and the value is an array of the plugin data.
 */
function get_plugins($plugin_folder = '')
{
    if (!$cache_plugins = wp_cache_get('plugins', 'plugins')) {
        $cache_plugins = array();
    }
    if (isset($cache_plugins[$plugin_folder])) {
        return $cache_plugins[$plugin_folder];
    }
    $wp_plugins = array();
    $plugin_root = WP_PLUGIN_DIR;
    if (!empty($plugin_folder)) {
        $plugin_root .= $plugin_folder;
    }
    // Files in wp-content/plugins directory
    $plugins_dir = @opendir($plugin_root);
    $plugin_files = array();
    if ($plugins_dir) {
        while (($file = readdir($plugins_dir)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            if (is_dir($plugin_root . '/' . $file)) {
                $plugins_subdir = @opendir($plugin_root . '/' . $file);
                if ($plugins_subdir) {
                    while (($subfile = readdir($plugins_subdir)) !== false) {
                        if (substr($subfile, 0, 1) == '.') {
                            continue;
                        }
                        if (substr($subfile, -4) == '.php') {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    closedir($plugins_subdir);
                }
            } else if (substr($file, -4) == '.php') {
                $plugin_files[] = $file;
            }
        }
        closedir($plugins_dir);
    }
    if (empty($plugin_files)) {
        return $wp_plugins;
    }
    foreach ($plugin_files as $plugin_file) {
        if (!is_readable("{$plugin_root}/{$plugin_file}")) {
            continue;
        }
        $plugin_data = get_plugin_data("{$plugin_root}/{$plugin_file}", false, false);
        //Do not apply markup/translate as it'll be cached.
        if (empty($plugin_data['Name'])) {
            continue;
        }
        $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
    }
    uasort($wp_plugins, '_sort_uname_callback');
    $cache_plugins[$plugin_folder] = $wp_plugins;
    wp_cache_set('plugins', $cache_plugins, 'plugins');
    return $wp_plugins;
}