2017 © Pedro Peláez
 

library wp-requirements

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

image

nekojira/wp-requirements

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

  • Monday, September 19, 2016
  • by unfulvio
  • Repository
  • 3 Watchers
  • 19 Stars
  • 161 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

This project is retired and you should not use it., (*1)

For reference only., (*2)


WP Requirements

GitHub version Scrutinizer Code Quality, (*3)

Hi! I'm a little utility that you can use in your WordPress plugin development., (*4)

Include me in your plugin and I will check if the PHP version or the installed WordPress version is the right one. If not, I will let you know and you can halt your script and display a message in WordPress dashboard so the admin will know why your plugin can't be activated., (*5)

Necessary foreword - WordPress doesn't have - sadly - a dependency management system nor supports Composer. This makes the usage of Composer packages or redistributing/reusing libraries such as this one pointless and even dangerous as more plugins sharing the same library in different versions will collide, resulting in impredictable behavior and errors. Since this is a little library, it's best that you fork it and "namespace" your own the WordPress way (i.e. rename WP_Requirements with Your_Plugin_Prefix_Requirements for example) while including in your plugin or theme., (*6)

Usage

Pass the requirements to a new instance of this class like so:, (*7)

$my_plugin_requirements = new WP_Requirements(
  'My Plugin Name',
  plugin_basename( __FILE__ ),
  array(
    'PHP' => 'x.y.z',
    'WordPress => 'x.y.z.',
    'Extensions' => array(
        'extension_name',
        'another_extension',
    )
  )
);

Replace 'x.y.z' with the semantic version number you want to require. For PHP extension, just pass the extension name as array string values., (*8)

You need to specify at least one value in the arguments array. Mind the casing in the array keys., (*9)

Then, you can use the following method to know if it passed (will return bool):, (*10)

$my_requirements_check->pass();

Implementation

There are two ways you can include WP Requirements in your project., (*11)

You can copy the class found in /src/wp-requirements.php in this project., (*12)

Important! If you choose to do so, please rename this class with the prefix used by your project (for example: from WP_Requirements to My_Plugin_Requirements ). In this way there is less risk of a naming collision between projects., (*13)

Include this library with:, (*14)

$ composer require nekojira/wp-requirements

However, if you choose to do so, remind that Composer can only work with PHP 5.3.0 onwards. If your goal is to require a PHP version check against older versions of PHP, but want to use Composer, you need a workaround., (*15)

You could specify an additional autoloader compatible with PHP 5.2, for example using the PHP 5.2 Autoloading for Composer, by including in your package.json file the following:, (*16)

 "require": {
     "xrstf/composer-php52": "1.*"
 },
 "scripts": {
     "post-install-cmd": [
         "xrstf\\Composer52\\Generator::onPostInstallCmd"
     ],
     "post-update-cmd": [
         "xrstf\\Composer52\\Generator::onPostInstallCmd"
     ],
     "post-autoload-dump": [
         "xrstf\\Composer52\\Generator::onPostInstallCmd"
     ]
 }

Note: it looks like Composer52 has been abandoned and currently moved to https://github.com/composer-php52/composer-php52 - as the current maintainer puts it: "Please do not use this, if you can avoid it. It's a horrible hack, often breaks and is extremely tied to Composer's interna. This package was originally developed in 2012, when PHP 5.2 was much more common on cheap webhosts." -- Just update your freackin' server to use a decent version of PHP., (*17)

Usage example

Either require with include_once or with Composer first, then at the beginning of your plugin, after the plugin headers, place some code like this:, (*18)

$my_plugin_requirements = new WP_Requirements(
  'My Plugin Name',
    plugin_basename( __FILE__ ),
    array(
        'PHP'       => '5.3.2',
        'WordPress' => '3.9.0',
    ) 
);

if ( $my_plugin_requirements->pass() === false ) {
    // Deactivate the plugin and print an admin notice.
    $my_plugin_requirements->halt();
    // Halt the execution of the rest of the plugin.
    return;
}

// Then from here on, continue with your code.
// Perhaps with `include_once 'includes/main_class.php'`
// which may contain potentially incompatible PHP code.

Resources

WP Requirements was inspired by a post appeared on wordpress.org at https://make.wordpress.org/plugins/2015/06/05/policy-on-php-versions/, (*19)

You can also try WP Update PHP which however only checks for PHP but provides insightful explanations for the users on why they should keep their PHP version up to date., (*20)

The Versions

19/09 2016

dev-master

9999999-dev https://github.com/unfulvio/wp-requirements/

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

  Sources   Download

GPL-2.0+

wordpress php version requirements

05/10 2015

1.4.1

1.4.1.0 https://github.com/nekojira/wp-requirements/

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

  Sources   Download

GPL-2.0+

wordpress php version requirements

30/08 2015

1.4.0

1.4.0.0 https://github.com/nekojira/wp-requirements/

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

  Sources   Download

GPL-2.0+

wordpress php version requirements

30/08 2015

1.3.0

1.3.0.0 https://github.com/nekojira/wp-requirements/

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

  Sources   Download

GPL-2.0+

wordpress php version requirements

18/08 2015

1.1.0

1.1.0.0

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

  Sources   Download

GPL-2.0+

wordpress

15/07 2015

1.0.0

1.0.0.0

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

  Sources   Download

GPL-2.0+

wordpress