WordPress 插件需求检查器
1.2.2
2023-06-23 09:01 UTC
Requires
- php: >=5.6
- micropackage/internationalization: ^1.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-23 11:45:00 UTC
README
🧬 关于需求
此微包允许您测试运行插件的环境需求。
它可以测试
- PHP 版本
- PHP 扩展
- SSL 状态
- WordPress 版本
- 活动插件
- 当前主题
- DocHooks 支持
但它也允许进行任何其他自定义检查。
💾 安装
composer require micropackage/requirements
🕹 使用
基本使用
在插件主文件中
<?php /* Plugin Name: My Test Plugin Version: 1.0.0 */ // Composer autoload. require_once __DIR__ . '/vendor/autoload.php' ; $requirements = new \Micropackage\Requirements\Requirements( 'My Test Plugin', array( 'php' => '7.0', 'php_extensions' => array( 'soap' ), 'wp' => '5.3', 'dochooks' => true, 'ssl' => 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.
高级使用
您也可以定义自己的自定义检查。
class CustomCheck extends \Micropackage\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 \Micropackage\Requirements\Requirements( 'My Test Plugin', array( 'custom-check' => 'something else', ) ); $requirements->register_checker( 'CustomCheck' ); $is_good = $requirements->satisfied();
📦 关于微包项目
微包 - 如其名所示 - 是包含少量可重用代码的微包,尤其在 WordPress 开发中非常有用。
目标是拥有多个包,通过定义结构可以组合在一起创建更大的东西。
微包由 BracketSpace 维护。
📖 更新日志
📃 许可证
此软件根据 MIT 许可证发布。有关更多信息,请参阅LICENSE 文件。