| 1 |
# Requirements |
| 2 |
|
| 3 |
[](https://bracketspace.com](https://bracketspace.com](https://bracketspace.com) |
| 4 |
[](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements) |
| 5 |
[](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements) |
| 6 |
[](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements) |
| 7 |
[](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements](https://packagist.org/packages/micropackage/requirements) |
| 8 |
|
| 9 |
<p align="center"> |
| 10 |
<img src="https://bracketspace.com/extras/micropackage/micropackage-small.png" alt="Micropackage logo"/> |
| 11 |
</p> |
| 12 |
|
| 13 |
## 🧬 About Requirements |
| 14 |
|
| 15 |
This micropackage allows you to test environment requirements to run your plugin. |
| 16 |
|
| 17 |
It can test: |
| 18 |
|
| 19 |
- PHP version |
| 20 |
- PHP Extensions |
| 21 |
- SSL state |
| 22 |
- WordPress version |
| 23 |
- Active plugins |
| 24 |
- Current theme |
| 25 |
- [](https://github.com/micropackage/dochooksDocHooks](https://github.com/micropackage/dochooks](https://github.com/micropackage/dochooks) support |
| 26 |
|
| 27 |
But it's open for any other custom check. |
| 28 |
|
| 29 |
## 💾 Installation |
| 30 |
|
| 31 |
``` bash |
| 32 |
composer require micropackage/requirements |
| 33 |
``` |
| 34 |
|
| 35 |
## 🕹 Usage |
| 36 |
|
| 37 |
## Basic usage |
| 38 |
|
| 39 |
In the plugin main file: |
| 40 |
|
| 41 |
```php |
| 42 |
<?php |
| 43 |
/* |
| 44 |
Plugin Name: My Test Plugin |
| 45 |
Version: 1.0.0 |
| 46 |
*/ |
| 47 |
|
| 48 |
// Composer autoload. |
| 49 |
require_once __DIR__ . '/vendor/autoload.php' ; |
| 50 |
|
| 51 |
$requirements = new \Micropackage\Requirements\Requirements( 'My Test Plugin', array( |
| 52 |
'php' => '7.0', |
| 53 |
'php_extensions' => array( 'soap' ), |
| 54 |
'wp' => '5.3', |
| 55 |
'dochooks' => true, |
| 56 |
'ssl' => true, |
| 57 |
'plugins' => array( |
| 58 |
array( 'file' => 'akismet/akismet.php', 'name' => 'Akismet', 'version' => '3.0' ), |
| 59 |
array( 'file' => 'hello-dolly/hello.php', 'name' => 'Hello Dolly', 'version' => '1.5' ) |
| 60 |
), |
| 61 |
'theme' => array( |
| 62 |
'slug' => 'twentysixteen', |
| 63 |
'name' => 'Twenty Sixteen' |
| 64 |
), |
| 65 |
) ); |
| 66 |
|
| 67 |
/** |
| 68 |
* Run all the checks and check if requirements has been satisfied. |
| 69 |
* If not - display the admin notice and exit from the file. |
| 70 |
*/ |
| 71 |
if ( ! $requirements->satisfied() ) { |
| 72 |
$requirements->print_notice(); |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
// ... plugin runtime. |
| 77 |
``` |
| 78 |
|
| 79 |
## Advanced usage |
| 80 |
|
| 81 |
You can also define your own custom checks. |
| 82 |
|
| 83 |
```php |
| 84 |
class CustomCheck extends \Micropackage\Requirements\Abstracts\Checker { |
| 85 |
|
| 86 |
/** |
| 87 |
* Checker name |
| 88 |
* |
| 89 |
* @var string |
| 90 |
*/ |
| 91 |
protected $name = 'custom-check'; |
| 92 |
|
| 93 |
/** |
| 94 |
* Checks if the requirement is met |
| 95 |
* |
| 96 |
* @param string $value Requirement. |
| 97 |
* @return void |
| 98 |
*/ |
| 99 |
public function check( $value ) { |
| 100 |
|
| 101 |
// Do your check here and if it fails, add the error. |
| 102 |
if ( 'something' === $value ) { |
| 103 |
$this->add_error( 'You need something!' ); |
| 104 |
} |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
$requirements = new \Micropackage\Requirements\Requirements( 'My Test Plugin', array( |
| 111 |
'custom-check' => 'something else', |
| 112 |
) ); |
| 113 |
|
| 114 |
$requirements->register_checker( 'CustomCheck' ); |
| 115 |
|
| 116 |
$is_good = $requirements->satisfied(); |
| 117 |
``` |
| 118 |
|
| 119 |
## 📦 About the Micropackage project |
| 120 |
|
| 121 |
Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development. |
| 122 |
|
| 123 |
The aim is to have multiple packages which can be put together to create something bigger by defining only the structure. |
| 124 |
|
| 125 |
Micropackages are maintained by [](https://bracketspace.comBracketSpace](https://bracketspace.com](https://bracketspace.com). |
| 126 |
|
| 127 |
## 📖 Changelog |
| 128 |
|
| 129 |
[](./CHANGELOG.mdSee the changelog file](./CHANGELOG.md](./CHANGELOG.md). |
| 130 |
|
| 131 |
## 📃 License |
| 132 |
|
| 133 |
This software is released under MIT license. See the [](./LICENSELICENSE](./LICENSE](./LICENSE) file for more information. |
| 134 |
|