julien731/wp-dismissible-notices-handler
Composer 安装命令:
composer require julien731/wp-dismissible-notices-handler
包简介
A simple library to handle Ajax-dismissible admin notices for WordPress
README 文档
README
Since version 4.2, WordPress has a built-in mechanism for handling dismissible admin notices. While this mechanism handles dismissing notices, the dismissal isn't persistent. This means that a user would see the notice on every page load, even though he or she dismissed the notice already.
What the Dismissible Notices Handler (DNH) library does is handle the persistent part of dismissing admin notices.
How It Works
The DNH library is extremely simple to use and yet has a couple of advanced options.
The basics of it is to register a new admin notice. You really need 3 things for registering a notice:
- a unique ID that will identify the notice (you will be warned in case of ID conflicts)
- a notice type
- a message to display in the notice
There is a handy helper function available for notice registration: dnh_register_notice()
This function takes 4 parameters:
$id(string): the unique ID of the notice$type(string): the type of notice you want to display. Currently it can beerrorfor an error notice orupdatedfor a success/update notice$content(string): the content of the admin notice$args(array): additional parameters that can be passed to the notice handler (see below)
Installation
The simpest way to use DNH is to add it as a Composer dependency:
composer require julien731/wp-dismissible-notices-handler
Example
Registering an admin notice would look like that:
dnh_register_notice( 'my_notice', 'updated', __( 'This is my notice' ) );
Advanced Parameters
The function takes an array of optional parameters allowing more control over the notices and how they're dismissed. Only 3 parameters are available so far but hopefully more will be coming soon.
Hereafter is the list of available parameters to be passed in the $args array. Please note that the $args parameter is optional.
| Parameter | Possible Value(s) | Default | Description |
|---|---|---|---|
| scope | user, global | user | Whether the notice should be dismissed for the current user only or globally on the site. A notice dismissed for a user will still show up for other users, while a notice dismissed globally will not be displayed anymore after being dismissed once. |
| cap | Any WordPress capability | If not empty, the handler will check if the current user has the specified before displaying the notice. | |
| class | string | Additional class to add to the notice wrapper |
julien731/wp-dismissible-notices-handler 适用场景与选型建议
julien731/wp-dismissible-notices-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.34k 次下载、GitHub Stars 达 45, 最近一次更新时间为 2016 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 julien731/wp-dismissible-notices-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 julien731/wp-dismissible-notices-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 45
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GNU
- 更新时间: 2016-03-04