awesome9/需求

WordPress 的需求检查器。

1.0.2 2021-07-10 02:09 UTC

This package is auto-updated.

Last update: 2024-09-10 09:29:41 UTC


README

Awesome9 Codacy Badge Latest Stable Version PHP from Packagist Total Downloads License

📃 关于需求

它是 需求微包 的分支,增加了一些自动加载检查器的额外检查。

此包允许您测试运行插件的环境需求。

它可以测试

  • PHP 版本
  • PHP 扩展
  • WordPress 版本
  • 活动插件
  • 当前主题

💾 安装

composer require awesome9/requirements

🕹 使用

基本使用

在插件主文件中

<?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.

高级使用

您也可以定义自己的自定义检查。

<?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();

📖 更新日志

查看更新日志文件