Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking to get meta data about an installed plugin from another plugin. Theoretically, to get the version, I could do:

$data = get_plugin_data( 'expected_plugin_folder_name');
$version = $data['version'];

But, this wouldn't work if the end user had changed the name of the plugin that I'm looking to get the meta data on was installed in.

I think the solution is to search in the array returned from get_plugins(). The sticky part is the array keys are named for the path, relative to the plugin directory of the plugin file, which brings me back to the same issue as before--the end-user might have changed the directory name of the plugin.

Is there anyway to get the meta data without having to specify the plugin folder? Possibly by specifying slug, uri, name, etc...

share|improve this question
    
Do you know a function name from the plugin’s main file? –  toscho Nov 30 '13 at 19:40
add comment

1 Answer

If you know a function or class of the plugin’s main file, you can use the Reflection API.

Example with my plugin T5 Taxonomy Location

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

Result

$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 ',
)

For a function, use ReflectionFunction. It inherits the method getFileName() too.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.