Testing WordPress version

We demonstrated this in our chapter about Social Networking, but here it is again, this time adapted for use in a testing class. You can add this to your plugin's dedicated testing class and reference it by name in your loader.php file:

/** * Tests that the current version of WP is greater than $ver. * * @param string $ver the version of WordPress your plugin requires in order to work, e.g. '3.0.1' * @return none Registers an error in the self::$errors array. */ public static function wp_version_gt($ver) { global $wp_version; $exit_msg = __("MyPlugin requires WordPress $ver or newer. <a href='http://codex.wordpress.org/Upgrading_WordPress'>Please update!</a>"); if (version_compare($wp_version,$ver,'<')) { self::$errors[] ...

Get WordPress 3 Plugin Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.