josantonius / wp-notice
此包已被弃用且不再维护。未建议替代包。
在 WordPress 管理面板中显示通知。
1.0.2
2018-01-07 19:27 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3 || ^2.8
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^5.7 || ^6.0
- squizlabs/php_codesniffer: ^3.2.2
- wp-coding-standards/wpcs: ^0.14
This package is not auto-updated.
Last update: 2022-08-20 12:32:31 UTC
README
在 WordPress 管理面板中显示通知。
要求
此库支持 PHP 版本 5.6 或更高版本,并兼容 HHVM 版本 3.0 或更高版本。
安装
安装此扩展的首选方式是通过 Composer。
要安装 WP_Notice 库,请简单执行以下命令
composer require josantonius/wp-notice
前面的命令将仅安装必要的文件,如果您希望 下载整个源代码,则可以使用
composer require josantonius/wp-notice --prefer-source
您也可以使用 Git 克隆完整的仓库
git clone https://github.com/josantonius/wp-notice.git
或 手动安装
wget https://raw.githubusercontent.com/josantonius/wp-notice/master/src/class-wp-notice.php
可用方法
此库中的可用方法
- 生成成功通知
WP_Notice::success($message, $dismissable);
属性 | 描述 | 类型 | 必需 | 默认 |
---|---|---|---|---|
$message | 通知消息。 | 字符串 | 是 | |
$dismissable | 可忽略的通知。 | 布尔型 | 否 | true |
返回 (布尔型 true)
- 生成警告通知
WP_Notice::warning($message, $dismissable);
属性 | 描述 | 类型 | 必需 | 默认 |
---|---|---|---|---|
$message | 通知消息。 | 字符串 | 是 | |
$dismissable | 可忽略的通知。 | 布尔型 | 否 | true |
返回 (布尔型 true)
- 生成错误通知
WP_Notice::error($message, $dismissable);
属性 | 描述 | 类型 | 必需 | 默认 |
---|---|---|---|---|
$message | 通知消息。 | 字符串 | 是 | |
$dismissable | 可忽略的通知。 | 布尔型 | 否 | true |
返回 (布尔型 true)
快速入门
要使用 Composer 与此库一起使用
require __DIR__ . '/vendor/autoload.php'; use Josantonius\WP_Notice;
如果您已手动安装,请使用它
require_once __DIR__ . '/class-wp-notice.php'; use Josantonius\WP_Notice\WP_Notice;
用法
此库的使用示例
- 生成成功通知
WP_Notice::success('Success example'); WP_Notice::success('Success not dismissable', false);
- 生成警告通知
WP_Notice::warning('Warning example'); WP_Notice::warning('Warning not dismissable', false);
- 生成错误通知
$error = new \WP_Error('error', 'Example of error creation from WP_Error'); WP_Notice::error($error); WP_Notice::error('Example of error creation without going through WP_Error'); WP_Notice::error('Error not dismissable', false);
测试
git clone https://github.com/josantonius/wp-notice.git
cd WP_Notice
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
composer install
使用 PHPUnit 运行单元测试
composer phpunit
composer phpcs
运行 PHP Mess Detector 测试以检测代码风格的冲突
composer phpmd
运行所有之前的测试
composer tests
赞助商
如果这个项目帮助您减少了开发时间,您可以赞助我以支持我的开源工作 😊
许可证
此仓库遵循MIT 许可协议。
版权所有 © 2017-2022, Josantonius