Download the PHP package alessandrotesoro/wp-diagnostics without Composer
On this page you can find all versions of the php package alessandrotesoro/wp-diagnostics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alessandrotesoro/wp-diagnostics
More information about alessandrotesoro/wp-diagnostics
Files in alessandrotesoro/wp-diagnostics
Package wp-diagnostics
Short Description Utility library to handle detection of minimum system requirements in WordPress plugins.
License GPL-3.0-or-later
Informations about the package wp-diagnostics
ℹ️ About WP Diagnostics
WP Diagnostics is a utility library to handle detection of minimum system requirements in WordPress plugins.
✨ Benefits
- Validate PHP Version, WordPress version, active plugins, php extensions, class existance or use custom callbacks.
- Support for custom requirements validators.
✅ Requirements
- PHP 7.2 or higher.
- Composer
📖 Usage
1. Installation
2. Basic usage
- Create an instance of
Sematico\Diagnostics\Runner
. - Add checks using the
addCheck
method. - Verify that requirements are satisfied using the
satisfied
method. - Display an admin notice using the
printNotice
method if requirements are not met.
Example:
In the example above we're creating an instance of the Runner
by passing through the plugin's entry file path, the title of the plugin an array of checks to verify.
3. Display an admin notice
When a plugin's requirements are not satisfied, you can use the printNotice
method to display an error message in the admin panel and automatically disable the plugin. The notice will contain all errors found.
4. Setting up the name of the plugin
When creating an instance of the Runner
, the 2nd parameter takes in a string which is used as the name of your plugin. The name is used within the error notice displayed when requirements are not satisfied.
5. Checks configuration
The third parameter of the Runner
instance takes in an array containing instances of all checks required for your plugin.
In the above example, we're verifying that WordPress is at least running version 5.7 and that the php version is at least 7.2.
Alternatively you may add checks using the addCheck
method.
6. Stop execution on first fail
In some cases you may want to stop the checks verification process as soon as the first error occurs. To enable this, simply set the 4th parameter as "true".
Alternatively, you may use the setBreakOnFailure
method.
7. Messages customization
By default, the library does not provide support for internationalization. Should you wish to customize the default messages or add support for translation, you may use the setMessages
method and overwrite any or all messages used by the library.
In the above example, we're replacing one of the strings and adding translation support too.
You can find the full list of default strings by inspecting the getDefaultMessages
method of the Runner.php
file.
📖 Available checks
1. Callback
Run a function and use its return value as the result.
In order to pass the check, you must return a boolean value of true. To fail a check you must return an instance of WP_Error.
2. ClassExists
Check if a class or an array of classes exists. Example:
3. ExtensionLoaded
Check if a PHP extension or an array of extensions is loaded.
4. PHPVersion
Check if the current PHP version matches the given requirement. The check accepts 2 parameters: the version to test for and the comparison operator.
5. PluginActive
Check if plugin or an array of plugins are currently active on the site.
6. WPVersion
Check if the current WordPress version matches the given requirement. The check accepts 2 parameters: the version to test for and the comparison operator.
📖 Writing custom checks
Every check class must implement the CheckInterface
and extend the AbstractCheck
class. You can then provide the check
method which is responsible for performing the actual check.
The method must return either a true
boolean value to mark the check as passed or an instance of WP_Error to mark the check as failed.
Below is an example class that checks if the registrations are allowed on the site.
🚨 Security Issues
If you discover a security vulnerability within WP Diagnostics, please email [email protected]. All security vulnerabilities will be promptly addressed.
🔖 License
Distributed under the MIT License. See LICENSE
for more information.