1

I'm currently writing a script that is running on a server and is supposed to get information about a) the WordPress version b) the plugins c) the plugin versions.

The WordPress version number is no problem, but I'm not sure how to reliably obtain the required plugin information. I've located the plugin folder (wp-content/plugins). Does this folder contain all plugins?

Even if it does, I don't know if there is a fixed structure to get a) the official name b) the official version number of all plugins.

For example, one plugin I checked had the version number in a .php file with an @version annotation, but the version of the second plugin I checked was just part of the comments (Version = 2.66 or something like this).

Is there a reliable way to obtain this information without using PHP (because the script I'm writing is not limited to WordPress and must run on servers without PHP)? Something like a common structure, or a central file with collected information on the plugins?

1

The bad news WP doesn't track this information persistently. It only keeps the technical representation of active plugins to load them. The rest is only looked up in specific contexts (such as plugin management admin panel), because it's relatively heavy on resources.

The good news is that you can certainly rebuild this functionality in arbitrary program. The canonical version of WP plugin is contained in its File Header in a form of PHP comment. Unfortunately it's not too machine-friendly format.

You can have your script scan for headers, keeping in mind several quirks:

  1. Version isn't mandatory and might be missing altogether.
  2. Plugins folder might or might not be in default location (it's customizable).
  3. Plugins might or might not be in a subfolder (they can be directly in plugins folder).
  4. There might be multiple plugins in a single subfolder.
  • Thank you, that brings me a bit closer to a solution. I'm not very familiar with WordPress, so here's another question: Are the plugin main files always named [plugin name].php? – R.G. Sep 17 '15 at 9:58
  • No, the name is arbitrary. All PHP files at fitting folder levels need to be scanned for the file header near the start. – Rarst Sep 17 '15 at 10:11
1

You can look in source to see how WordPress does it. Start at get_plugins, which uses get_plugin_data which uses get_file_data to read the header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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