get_plugins()

最后更新于:2021-11-26 11:32:45

get_plugins( string$plugin_folder=”)

Check the plugins directory and retrieve all plugin files with plugin data.

参数

$plugin_folder

(string) (Optional) Relative path to single plugin folder.

Default value: ”

响应

(array[]) Array of arrays of plugin data, keyed by plugin file name. See get_plugin_data().

源文件

文件: gc-admin/includes/plugin.php

function get_plugins( $plugin_folder = '' ) {

	$cache_plugins = gc_cache_get( 'plugins', 'plugins' );
	if ( ! $cache_plugins ) {
		$cache_plugins = array();
	}

	if ( isset( $cache_plugins[ $plugin_folder ] ) ) {
		return $cache_plugins[ $plugin_folder ];
	}

	$gc_plugins  = array();
	$plugin_root = GC_PLUGIN_DIR;
	if ( ! empty( $plugin_folder ) ) {
		$plugin_root .= $plugin_folder;
	}

	// Files in gc-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 $gc_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;
		}

		$gc_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data;
	}

	uasort( $gc_plugins, '_sort_uname_callback' );

	$cache_plugins[ $plugin_folder ] = $gc_plugins;
	gc_cache_set( 'plugins', $cache_plugins, 'plugins' );

	return $gc_plugins;
}
Array
(
    [hello-dolly/hello.php] => Array
        (
            [Name] => Hello Dolly
            [PluginURI] => https://gechiui.org/extend/plugins/hello-dolly/
            [Version] => 1.6
            [Description] => This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
            [Author] => Matt Mullenweg
            [AuthorURI] => http://ma.tt/
            [TextDomain] => 
            [DomainPath] => 
            [Network] => 
            [Title] => Hello Dolly
            [AuthorName] => Matt Mullenweg

)