是的,有一种方法可以通过编程获得这些信息。
WordPress Version Info
这个
WordPress version 作为全局存在,但您也可以使用
get_bloginfo()
功能:
global $wp_version;
echo $wp_version;
// OR
$wordpress_version = get_bloginfo( \'version\' );
echo $wordpress_version;
Plugin Info
要检索插件信息,请使用
get_plugins()
作用您需要确保还包括wp admin/includes/plugin。不能认为在每个用例中都加载了将其用作此文件的php文件。
include_once( \'wp-admin/includes/plugin.php\' );
$plugins = get_plugins();
从Codex文章
get_plugins()
您可以看到,上述内容将为您提供一个数组,其中包含所有已安装插件的信息:
Array
(
[hello-dolly/hello.php] => Array
(
[Name] => Hello Dolly
[PluginURI] => http://wordpress.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
)
获取有关的信息
active plugins, 使用以下选项:
$active_plugins = get_option( \'active_plugins\' );
$active_plugins
将是一个活动插件数组,如下所示(继续上面的示例):
Array
(
[0] => hello-dolly/hello.php
)
将这些东西放在一起,您可以使用下面的实用程序函数获取所有已安装的插件和所有活动插件,并将结果放入包含插件名称、版本以及是否活动的数组中:
function my_get_plugin_info() {
// Get all plugins
include_once( \'wp-admin/includes/plugin.php\' );
$all_plugins = get_plugins();
// Get active plugins
$active_plugins = get_option(\'active_plugins\');
// Assemble array of name, version, and whether plugin is active (boolean)
foreach ( $all_plugins as $key => $value ) {
$is_active = ( in_array( $key, $active_plugins ) ) ? true : false;
$plugins[ $key ] = array(
\'name\' => $value[\'Name\'],
\'version\' => $value[\'Version\'],
\'active\' => $is_active,
);
}
return $plugins;
}
这将为您提供一个数组结果:
[akismet/akismet.php] => Array
(
[name] => Akismet Anti-Spam
[version] => 4.08
[active] => 1
)
[gutenberg/gutenberg.php] => Array
(
[name] => Gutenberg
[version] => 3.9.0
[active] => 1
)
[hello-dolly/hello.php] => Array
(
[name] => Hello Dolly
[version] => 1.6
[active] =>
)
请注意,我将“active”设置为布尔值,但在实用程序函数中,可以将其设置为“active”/“inactive”或其他任何形式。此外,我只在数组中包括名称、版本和活动,因为您在OP中提到了这一点,但是
get_plugins()
结果可以包括在内。
我将上述实用程序函数和一个备用版本放在一起,该版本只需向返回的数组添加一个“Active”键get_plugins()
并将其保存为a gist for anyone who needs it.