定制 nekojira/wp-requirements 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nekojira/wp-requirements

Composer 安装命令:

composer require nekojira/wp-requirements

包简介

Utility for WordPress plugin developers to check PHP version, WordPress version and presence of PHP extensions in current installation.

README 文档

README

This project is retired and you should not use it.

For reference only.

WP Requirements

GitHub version Scrutinizer Code Quality

Hi! I'm a little utility that you can use in your WordPress plugin development.

Include me in your plugin and I will check if the PHP version or the installed WordPress version is the right one. If not, I will let you know and you can halt your script and display a message in WordPress dashboard so the admin will know why your plugin can't be activated.

Necessary foreword - WordPress doesn't have - sadly - a dependency management system nor supports Composer. This makes the usage of Composer packages or redistributing/reusing libraries such as this one pointless and even dangerous as more plugins sharing the same library in different versions will collide, resulting in impredictable behavior and errors. Since this is a little library, it's best that you fork it and "namespace" your own the WordPress way (i.e. rename WP_Requirements with Your_Plugin_Prefix_Requirements for example) while including in your plugin or theme.

Usage

Pass the requirements to a new instance of this class like so:

$my_plugin_requirements = new WP_Requirements(
  'My Plugin Name',
  plugin_basename( __FILE__ ),
  array(
    'PHP' => 'x.y.z',
    'WordPress => 'x.y.z.',
    'Extensions' => array(
        'extension_name',
        'another_extension',
    )
  )
);

Replace 'x.y.z' with the semantic version number you want to require. For PHP extension, just pass the extension name as array string values.

You need to specify at least one value in the arguments array. Mind the casing in the array keys.

Then, you can use the following method to know if it passed (will return bool):

$my_requirements_check->pass();

Implementation

There are two ways you can include WP Requirements in your project.

Copy this class (recommended way)

You can copy the class found in /src/wp-requirements.php in this project.

Important! If you choose to do so, please rename this class with the prefix used by your project (for example: from WP_Requirements to My_Plugin_Requirements ). In this way there is less risk of a naming collision between projects.

Use Composer (not recommended)

Include this library with:

$ composer require nekojira/wp-requirements

However, if you choose to do so, remind that Composer can only work with PHP 5.3.0 onwards. If your goal is to require a PHP version check against older versions of PHP, but want to use Composer, you need a workaround.

You could specify an additional autoloader compatible with PHP 5.2, for example using the PHP 5.2 Autoloading for Composer, by including in your package.json file the following:

 "require": {
	 "xrstf/composer-php52": "1.*"
 },
 "scripts": {
	 "post-install-cmd": [
		 "xrstf\\Composer52\\Generator::onPostInstallCmd"
	 ],
	 "post-update-cmd": [
		 "xrstf\\Composer52\\Generator::onPostInstallCmd"
	 ],
	 "post-autoload-dump": [
		 "xrstf\\Composer52\\Generator::onPostInstallCmd"
	 ]
 }

Note: it looks like Composer52 has been abandoned and currently moved to https://github.com/composer-php52/composer-php52 - as the current maintainer puts it: "Please do not use this, if you can avoid it. It's a horrible hack, often breaks and is extremely tied to Composer's interna. This package was originally developed in 2012, when PHP 5.2 was much more common on cheap webhosts." -- Just update your freackin' server to use a decent version of PHP.

Usage example

Either require with include_once or with Composer first, then at the beginning of your plugin, after the plugin headers, place some code like this:

$my_plugin_requirements = new WP_Requirements(
  'My Plugin Name',
	plugin_basename( __FILE__ ),
	array(
		'PHP'       => '5.3.2',
		'WordPress' => '3.9.0',
	) 
);

if ( $my_plugin_requirements->pass() === false ) {
	// Deactivate the plugin and print an admin notice.
	$my_plugin_requirements->halt();
	// Halt the execution of the rest of the plugin.
	return;
}

// Then from here on, continue with your code.
// Perhaps with `include_once 'includes/main_class.php'`
// which may contain potentially incompatible PHP code.

Resources

WP Requirements was inspired by a post appeared on wordpress.org at https://make.wordpress.org/plugins/2015/06/05/policy-on-php-versions/

You can also try WP Update PHP which however only checks for PHP but provides insightful explanations for the users on why they should keep their PHP version up to date.

nekojira/wp-requirements 适用场景与选型建议

nekojira/wp-requirements 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 199 次下载、GitHub Stars 达 21, 最近一次更新时间为 2015 年 08 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「version」 「wordpress」 「requirements」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nekojira/wp-requirements 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nekojira/wp-requirements 我们能提供哪些服务?
定制开发 / 二次开发

基于 nekojira/wp-requirements 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 199
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2015-08-30