awesome9 / requirements
Requirements checker for WordPress.
1.0.2
2021-07-10 02:09 UTC
Requires
- php: >=5.6
This package is auto-updated.
Last update: 2024-11-10 09:53:13 UTC
README
📃 About Requirements
It's a fork of Requirements micropackage with some additional checking for auto-loading checkers.
This package allows you to test environment requirements to run your plugin.
It can test:
- PHP version
- PHP Extensions
- WordPress version
- Active plugins
- Current theme
💾 Installation
composer require awesome9/requirements
🕹 Usage
Basic usage
In the plugin main file:
<?php /* Plugin Name: My Test Plugin Version: 1.0.0 */ // Composer autoload. require_once __DIR__ . '/vendor/autoload.php' ; $requirements = new \Awesome9\Requirements\Requirements( 'My Test Plugin', array( 'php' => '7.0', 'php_extensions' => array( 'soap' ), 'wp' => '5.3', 'dochooks' => true, 'plugins' => array( array( 'file' => 'akismet/akismet.php', 'name' => 'Akismet', 'version' => '3.0' ), array( 'file' => 'hello-dolly/hello.php', 'name' => 'Hello Dolly', 'version' => '1.5' ) ), 'theme' => array( 'slug' => 'twentysixteen', 'name' => 'Twenty Sixteen' ), ) ); /** * Run all the checks and check if requirements has been satisfied. * If not - display the admin notice and exit from the file. */ if ( ! $requirements->satisfied() ) { $requirements->print_notice(); return; } // ... plugin runtime.
Advanced usage
You can also define your own custom checks.
<?php class CustomCheck extends \Awesome9\Requirements\Abstracts\Checker { /** * Checker name * * @var string */ protected $name = 'custom-check'; /** * Checks if the requirement is met * * @param string $value Requirement. * @return void */ public function check( $value ) { // Do your check here and if it fails, add the error. if ( 'something' === $value ) { $this->add_error( 'You need something!' ); } } } $requirements = new \Awesome9\Requirements\Requirements( 'My Test Plugin', array( 'custom-check' => 'something else', ) ); $requirements->register_checker( 'CustomCheck' ); $is_good = $requirements->satisfied();