szepeviktor/persistent-admin-notices

WordPress 持久性管理员通知。

v0.2.0 2019-11-03 18:26 UTC

This package is auto-updated.

Last update: 2024-09-14 06:32:18 UTC


README

本软件包用于显示针对网站事件的行政通知,而非针对单个用户交易。以下是一些示例。

  • [WP-Cron] XYZ API 的认证令牌已过期。
  • 所有编辑!请在晚上8点前完成您的文章。
  • 我们有一个新版本 v3.2.1。请查看新功能:http://example.com/
  • CSV 导入失败。我们不同步了!
  • 不完整的 ACF 选项:x, y, z
  • 所有产品均已售罄!
  • 最大 X 限制已达到。请减少 X!
  • John Doe 被解雇了!请不要再联系他。
// Use Composer instead:  composer require szepeviktor/persistent-admin-notices
// require __DIR__ . '/vendor/szepeviktor/persistent-admin-notices/src/PersistentNotices.php';

use WordPress\Admin\PersistentNotices;

// Fire it up!
\add_action('init', function () {
    new PersistentNotices();
});
// Or HookConstructorTo::init(PersistentNotices::class, 0);

// New notice.
PersistentNotices::add('slug', 'Something needs your attention!');

// New error notice.
PersistentNotices::error('slug', 'An error needs to be resolved!');

// Check whether a notice is showing.
if (PersistentNotices::isActive('slug')) {}

// Delete notice.
PersistentNotices::remove('slug');

// Customize notice.
PersistentNotices::add(
    'slug',
    'Something very special needs your attention!',
    [
        'expiration' => PersistentNotices::PERSISTENT, // Expiration in seconds or PersistentNotices::ONCE
        'type'       => 'info',           // Notice type: info, succes, warning, error.
        'capability' => 'manage_options', // WordPress capability to receive notifications.
        'priority'   => 10,               // Used to order notices.
        'classes'    => '',               // Override CSS classes.
        'noticeHtml' => '',               // Override full notice HTML.
    ]
);

这里的目的是什么???

当您的插件或主题处理管理员通知时,您必须进行计算或决策并每次都显示通知。

如果您使用此软件包,则只需进行一次计算,

  1. 留下通知
  2. 或者让通知过期
  3. 或者稍后的事件中删除它

额外的好处是可以在 WordPress cron 作业、AJAX 操作或 REST 调用中显示通知。

为什么不……?

  • 可忽略的通知可以非常容易地被忽略。
  • 特定管理员页面上的通知可能会被忽视。
  • 向特定用户显示通知会使此软件包成为消息系统。

类似项目