#10529 closed enhancement (wontfix)
API to retrieve current WordPress version
Reported by: | stephanreiter | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | Plugins | Keywords: | close version query |
Focuses: | Cc: |
Description
Sometimes it's necessary in plug-ins to check whether a certain functionality or behavior is supported by the current WP version or not. For this purpose I currently use the following code in the Scissors plugin:
function _minimalWpVersion($major, $minor) { global $wp_version; $version = preg_replace("/[^\\.0-9\s]/", "", $wp_version); // keep only '0' .. '9' and '.' $version = explode('.', $version); return (count($version) >= 2 && ($version[0] > $major || $version[0] == $major && $version[1] >= $minor)); }
I would love to see the introduction of an API that allows plug-in authors to easily query the current version of WordPress and get a result in the form of an array('major' => 2, 'minor' => 8, 'revision' => 2) (to give an example). This would eliminate potential problems when the format of the version-string changed.
Change History (4)
Note: See
TracTickets for help on using
tickets.
php's version_compare() works well:
the good thing about this, is that it understands major, minor and point release, as well as dealing with -dev -alpha -etc.. nativly.