^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_plugins()用法示例

get_plugins( string $plugin_folder = '' )

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

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.


参数

$plugin_folder

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

Default value: ”


返回值

(array) Key is the plugin file path and the value is an array of the plugin data.


源代码

File: wp-admin/includes/plugin.php

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;
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

Uses

  • wp-admin/includes/plugin.php:
    get_plugin_data()
  • wp-includes/cache.php:
    wp_cache_get()
  • wp-includes/cache.php:
    wp_cache_set()
  • wp-includes/plugin.php:
    plugin_basename()

Used By

  • wp-admin/includes/ajax-actions.php:
    wp_ajax_update_plugin()
  • wp-admin/includes/class-language-pack-upgrader.php:
    Language_Pack_Upgrader::get_name_for_update()
  • wp-admin/includes/class-plugin-upgrader.php:
    Plugin_Upgrader::plugin_info()
  • wp-admin/includes/class-wp-plugins-list-table.php:
    WP_Plugins_List_Table::prepare_items()
  • wp-admin/includes/update.php:
    get_plugin_updates()
  • wp-admin/includes/plugin-install.php:
    install_plugin_install_status()
  • wp-admin/includes/deprecated.php:
    wp_dashboard_plugins_output()
  • wp-admin/includes/plugin.php:
    validate_plugin()
  • wp-includes/update.php:
    wp_update_plugins()
  • Show 4 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Get All Plugins

    The following code snippet returns all plugins installed on your site (not just activated ones).

    
    <?php 
    
    // Check if get_plugins() function exists. This is required on the front end of the
    // site, since it is in a file that is normally only loaded in the admin.
    if ( ! function_exists( 'get_plugins' ) ) {
    	require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }
    
    $all_plugins = get_plugins();
    
    // Save the data to the error log so you can see what the array format is like.
    error_log( print_r( $all_plugins, true ) );
    

    Example output:

    
    Array
    (
        [hello-dolly/hello.php] => Array
            (
                [Name] => Hello Dolly
                [PluginURI] => https://wordpress.org/extend/plugins/hello-dolly/
                [Version] => 1.6
                [描述] => 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 <code>Hello, Dolly</code> 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
    
    )
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈