Posts

Showing posts from August, 2019

WORDPRESS: Get your plugin version number 'n things

Image
A quick and dirty "get plugin version number" example, borrowed from these guys: https://wordpress.stackexchange.com/questions/18268/i-want-to-get-a-plugin-version-number-dynamically A method like this will always be available. Unlike the admin only get_plugin_data() ( https://codex.wordpress.org/Function_Reference/get_plugin_data ) function get_fi_mi_plugin_version(){ if(preg_match('/version:[\s\t]+?([0-9.]+)/i',file_get_contents( __FILE__ ), $v)){ return $v[1]; } return ""; } Naturally, your regex '/version:[\s\t]+?([0-9.]+)/i' may vary. Depends on how your header comments are laid out. I typically do this: /* Plugin Name: WP Plugin Plugin URI: somewhere.com Description: Something something plugin header Version: 6.6.6 Author: some idiot Author URI: somewhere.com License: Creative Commons 'n things */