Download the PHP package dsawardekar/wp-requirements without Composer
On this page you can find all versions of the php package dsawardekar/wp-requirements. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dsawardekar/wp-requirements
More information about dsawardekar/wp-requirements
Files in dsawardekar/wp-requirements
Package wp-requirements
Short Description Library for handling minimum system requirements in WordPress Plugins
License MIT
Homepage http://github.com/dsawardekar/wp-requirements
Informations about the package wp-requirements
WP Requirements
A small library to easily handle detection of minimum system requirements in WordPress plugins.
Features
- Detects PHP versions incompatible with your Plugin.
- Detects WordPress versions incompatible with your Plugin.
- Detects absence of PHP extensions.
- Displays errors to users without activating your Plugin.
- Simple API to support custom minimum requirements.
Getting Started
The library comes with a WP_Min_Requirements
class that can be used to
detect some basic system requirements like WordPress and PHP versions.
First we create a new instance of the class and call it's satisfied
method in a conditional. If the condition is satisfied you can
instantiate your plugin inside it.
Next we need to handle the case when the minimum requirements are not
satisfied. The library comes with a WP_Faux_Plugin
that does this by
notifying the user that the minimum requirements are not satisfied.
All you need to do is create it and passing it the name of your plugin and the results object from the requirements.
When the requirements are not met, users will see a message like shown above.
Detecting Specific Versions of PHP & WordPress
To create custom requirements you extend the WP_Requirements
class and
provide a custom getRequirements
method. It should return an array of
requirement objects.
Below is the WP_Min_Requirements
class that matches against PHP 5.3.2 and
WordPress 3.5.
Custom Requirements
You can also customize the requirements specific to your plugin. First you need to
create a custom Requirement
class with 2 methods, check
and message
.
Your check
method should perform your custom detection and return
true or false. And the message
method should return the message to
display to the user if the requirement is not met.
For example to check if the Akismet
plugin is in use,
Then wrap this up into a new class that extends the WP_Requirements
class
and put this requirement into use.
Other Requirements
Use the WP_Modern_Requirements class to ensure that PHP 5.5 and required extensions are present.
To test the requirements message, use the WP_Failing_Requirements class instead.
Usage
The library and all it's classes are bundled inside the Requirements.php file.
- Copy the Requirements.php file into your project.
- Use
require_once
to include this file into your plugin's main file. - Instantiate the Requirements object and call it's
satisfied
method as described above.
Making Changes
Please send pull requests instead of changing the requirements file directly inside your project.
If you must make modifications to the Requirements.php
do so my
renaming the WP_
prefix to something unique like your company name.
Eg:- Acme_Requirements
. A find and replace for WP_
to Acme_
will
do the trick.
Examples
Thanks
- Thanks to Square Penguin for the error message idea.
Contributing
Please include your system and environment details for faster resolution of bug reports. Failing tests alongside bug reports are awesome!
Pull Requests are Welcome!
The project comes with a test suite that is integrated with Travis. Please ensure that the test suite passes before submitting PRs. Also try to include tests alongside any major changes.
Also note, this project uses the git flow branching model. PRs should be made
against the develop
branch.
License
MIT License. Copyright © 2014 Darshan Sawardekar