如果您知道插件主文件的函数或类,可以使用Reflection API.
add_action( \'plugins_loaded\', function()
{
$class = \'T5_Taxonomy_Location\';
if ( ! class_exists( $class ) )
return;
add_action( \'admin_footer\', function() use ( $class )
{
$reflection = new ReflectionClass( $class );
$file = $reflection->getFileName();
$data = get_plugin_data( $file );
print \'<pre>$data = \' . esc_html( var_export( $data, TRUE ) ) . \'</pre>\';
});
});
结果
$data = array (
\'Name\' => \'T5 Taxonomy Location\',
\'PluginURI\' => \'https://github.com/toscho/t5-taxonomy-location\',
\'Version\' => \'2012.09.11\',
\'Description\' => \'Creates a new taxonomy for locations. <cite>By <a href="http://toscho.de" title="Visit author homepage">Thomas Scholz </a>.</cite>\',
\'Author\' => \'<a href="http://toscho.de" title="Visit author homepage">Thomas Scholz </a>\',
\'AuthorURI\' => \'http://toscho.de\',
\'TextDomain\' => \'plugin_t5_tax_location\',
\'DomainPath\' => \'/languages\',
\'Network\' => false,
\'Title\' => \'<a href="https://github.com/toscho/t5-taxonomy-location" title="Visit plugin homepage">T5 Taxonomy Location</a>\',
\'AuthorName\' => \'Thomas Scholz \',
)
对于函数,使用
ReflectionFunction
. 它继承了方法
getFileName()
也