Download the PHP package elhardoum/wp-php-compat-check without Composer
On this page you can find all versions of the php package elhardoum/wp-php-compat-check. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elhardoum/wp-php-compat-check
More information about elhardoum/wp-php-compat-check
Files in elhardoum/wp-php-compat-check
Package wp-php-compat-check
Short Description Helps check PHP and WordPress compatibility before running the plugin.
License GPL-3.0
Informations about the package wp-php-compat-check
Compatibility Check helper for WordPress plugins
Helps check PHP and WordPress compatibility before running the plugin.
You can wrap your main WordPress plugin code in this helper, and specify which minimum PHP version your plugin should run on, and also optionally which WordPress version to require as a minimum, and then the plugin should work with no fatal errors if all checks are met and the environment is compatible.
This helper requires PHP 5.0 at least, and should be working for multisite environments as well.
Usage:
In your main plugin file, e.g wp-content/plugins/my-plugin/my-plugin.php
, require this compat class:
For composer users:
Then, make sure to copy all of your main file code (except the plugin header comments of course) into the then
method:
Here's an example:
Here's another example, this time without using closures since they're supported as of PHP 5.3:
One last example, if you don't want to use then
method, there's isCompatible
to get you covered:
Options:
The following are called options, which you can pass to the check
method of the CompatCheckWP
class (CompatCheckWP::check( array( ...options ) )
):
php_version
: The minimum PHP version your plugin should work with, if needed.
wp_version
: The minimum WordPress version your plugin should work with, if needed.
deactivate_incompatible
: Deactivate the plugin right away if not compatible. Otherwise keep it active but the plugin code will not be running.
error_message
: Customize the incompatibility error message. It defaults to: The following plugin could not be activated due to a compatibility error: plugin-name/plugin-name.php. [PHP >= XX: ✓, WP >= XX: ×]
plugin_file
: Optional, pass a string of the plugin file in the format of this function return: plugin_basename
(e.g 'plugin_file' => plugin_basename(MY_PLUGIN_FILE)
). If you are calling the class from the main plugin file and not passing this argument, then the plugin file will be programatically extracted from the debug backtrace, otherwise if calling from another file then it would certainly fail and you'll want to pass in this argument.
php_version_operator
: The operator by default is >=
for checking the PHP version requirement.
wp_version_operator
: The operator by default is >=
for checking WP version requirement.