Develop plugins without restricting yourself to the minimum WordPress requirements

The minimum PHP requirement for WordPress is PHP 5.2.4. This version has been unsupported since early 2011 and is potentially insecure. WordPress supports it to maintain backward compatibility for sites that still use this version.

Diagram of PHP version usage for WordPress

PHP versions currently used for WordPress sites

As a WordPress user I’m a big fan of backward compatibility. But as a WordPress plugin developer I don’t want to support PHP 5.2 anymore. There’s so much cool stuff you can use that’s introduced in later versions.

If you set higher PHP requirements for your plugins you’ll have to make sure it fails elegantly in the versions you don’t support. Otherwise it might produce fatal errors. The WPupdatePHP library from @CoenJacobs can help you with that. This library shows an admin notice in case your plugin’s minimum PHP version requirement isn’t met.

Admin notice

Note: I recommend you download the class manually, rename the class with your plugin acronym and put it in your plugin directory. The library itself recommends to install it with composer. My personal opinion is that WordPress isn’t designed to handle 3rd party dependencies with composer.

[UPDATE 2017-06-06] @CoenJacobs has created an excellent way to bundle third-party packages in your plugin with composer. Checkout Mozart

Here’s an example of how to use this library in your root plugin file. In this example the WPUpdatePhp class (from the library) is renamed to MR_Update_Php and included in the ‘includes’ directory

 * Plugin Name: Minimum Requirement
 * Description: Example plugin to use a minimum requirement of PHP version 5.3

// This file needs to be PHP 5.2 safe!
// No PHP namespaces or other stuff introduced in PHP 5.3 or higher

// We need to require the WPUpdatePhp.php file.
require plugin_dir_path( __FILE__ ) . 'includes/WPUpdatePhp.php';

// Instantiate the renamed class with a minimum required PHP version of 5.3.0.
$updatePhp = new MR_Update_Php( '5.3.0' );

// Check if the current version meets our minimum required PHP version.
if ( $updatePhp->does_it_meet_required_php_version( PHP_VERSION ) ) {

	// Install the plugin

	// Yay! The install.php file doesn't need to be PHP 5.2 safe!
	// All other files in your plugin don't need to be PHP 5.2 safe!
	require plugin_dir_path( __FILE__ ) . 'includes/install.php';

That’s it, your plugin works with PHP 5.3 and up! It shows an admin notice for all older versions.


If you use PHPUnit to test your plugins, you can use the phpVersion and phpVersionOperator attributes in your phpunit.xml configuration file to tell it what PHP versions to use for the tests.

The next example tells PHPUnit to use all php files with the “test-” prefix for the PHP 5.3 and up tests. For the PHP 5.2 and older tests it uses the outdated-php-versions.php file.

	<testsuite name="My Test Suite">
		<directory phpVersion="5.3.0" phpVersionOperator=">=" prefix="test-" suffix=".php">./tests/</directory>
		<file phpVersion="5.3.0" phpVersionOperator="&lt;">./tests/outdated-php-versions.php</file>

If you need more fine-grained control use the @requires precondition.

Let’s make our WordPress plugins require a more recent version of PHP! The minimum version for WordPress is no longer supported and potentially insecure.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s