Wordpress - I Want to Get A Plugin Version Number Dynamically
There is a function called get_plugin_data(). Try calling this from within the main plugin file if you need to:
$plugin_data = get_plugin_data( __FILE__ );
$plugin_version = $plugin_data['Version'];
But as is said in the answers to the other question, its better for performance to just define a PHP variable as you're doing.
An alternative to get_plugin_data()
is get_file_data() which is available without the overhead of loading additional files.
Simply add this to your main plugin file:
$plugin_data = get_file_data(__FILE__, array('Version' => 'Version'), false);
$plugin_version = $plugin_data['Version'];
Under the hood get_file_data
does some cleaver scanning to be quite performant.
And if needed define your constant:
define ( 'YOURPLUGIN_CURRENT_VERSION', $plugin_version );
Here is an answer with some code that will do what you want it to do: Is there a way for a plug-in to get it's own version number?