Is there an API I can call, inside my plug-in, to determine the plug-in’s version?
I just want to have my plug-in emit a html comment with it’s own version number … for diagnostic purposes.
Is there an API I can call, inside my plug-in, to determine the plug-in’s version?
I just want to have my plug-in emit a html comment with it’s own version number … for diagnostic purposes.
You must be logged in to post a comment.
@david: Both @Adam Backtrom and @Viper007Bond give some good advice so I thought I’d take their advice and see if I couldn’t implement something, see below.
What follows iS a plugin called WP Active Plugins Data that parses the header metadata for all active plugins anytime any plugin is activated and it stores all the metadata for each plugin into an array option in
wp_options
. I designed it for both regular WordPress plugins and multisite site-wide plugins. You can download it here from gist but I’ve also copied the code here for your review:Want to see how it works? Here’s a test file you can drop in the root of your WordPress site (
http://example.com/test.php
.) Make sure you have both this plugin and Akismet activated before you test it.If it’s not exactly what you need at least it should give you a good starting point. Hope this helps.
There is in the admin screens:
get_plugin_data()
. In templates, I think you will need the plugin to hold that data in PHP, e.g., set a constant or global or something, and keep that value synchronized with the plugin header version number.wp-settings.php
callswp_get_active_and_valid_plugins()
, which pulls data from theactive_plugins
site option. This option only contains the path to the plugin file, andwp-settings.php
only runsinclude_once
on the file, so it’s never parsed for the plugin metadata.You can parse your plugin’s meta data (that stuff at the top of the file), but it’s better for performance if you just set your own PHP variable with a matching version number. When you update the plugin, just update both version numbers.
It’s slightly more work for you in the short term, but a lot better in the long term.