mundschenk-at/check-wp-requirements

一个类,允许WordPress插件在激活前检查某些运行时要求。

v2.0.0 2019-06-25 17:42 UTC

This package is auto-updated.

Last update: 2024-08-26 04:54:11 UTC


README

Build Status Latest Stable Version Scrutinizer Code Quality Code Coverage License

WordPress插件的辅助类,用于检查PHP版本和其他要求。

要求

  • PHP 5.6.0 或更高版本
  • WordPress 5.2 或更高版本。

安装

通过Composer使用此包是最佳方式

$ composer require mundschenk-at/check-wp-requirements

基本用法

  1. 创建一个 \Mundschenk\WP_Requirements 对象,并在构造函数中设置要求。
  2. 调用 \Mundschenk\WP_Requirements::check() 方法,如果返回 true 则正常启动插件。
// Set up autoloader.
require_once __DIR__ . '/vendor/autoload.php';

/**
 * Load the plugin after checking for the necessary PHP version.
 *
 * It's necessary to do this here because main class relies on namespaces.
 */
function run_your_plugin() {

	$requirements = new \Mundschenk\WP_Requirements( 'Your Plugin Name', __FILE__, 'your-textdomain', [
		'php'       => '5.6.0',
		'multibyte' => true,
		'utf-8'     => false,
	] );

	if ( $requirements->check() ) {
		// Autoload the rest of your classes.

		// Create and start the plugin.
		...
	}
}
run_your_plugin();

许可证

check-wp-requirements 在GNU通用公共许可证2或更高版本下授权 - 请参阅LICENSE文件获取详细信息。