awesome9/notifications

WordPress 通知中心。

1.0.2 2021-07-10 02:03 UTC

This package is auto-updated.

Last update: 2024-09-10 09:55:16 UTC


README

Awesome9 Latest Stable Version PHP from Packagist Total Downloads License

📃 关于通知

此包为在 WordPress 中管理临时和永久通知提供了便利。

💾 安装

composer require awesome9/notifications

🕹 使用

首先,您需要为您的通知中心生成配置。

Awesome9\Notifications\Center::get()
	->set_storage( 'awesome9_plugin_notifications' );  // Option name to be save persistent notifications in DB.

现在,让我们添加和删除一些要在管理界面中输出的数据。

// This notification shows once its a temporary notification.
Awesome9\Notifications\Center::get()
	->add( 'Your message goes here.', array(
		'id'      => 'awesome9_some_id'
		'type'    => \Awesome9\Notifications\Notification::ERROR,
		'screen'  => 'post',
		'classes' => 'style-me-custom'
	) );

// Now let's add a persistent one which is dismissible by user.
Awesome9\Notifications\Center::get()
	->add( 'Your message goes here.', array(
		'id'         => 'awesome9_some_id_2'
		'type'       => \Awesome9\Notifications\Notification::ERROR,
		'persistent' => 'some_unique_Id',
		'screen'     => 'post',
		'classes'    => 'style-me-custom'
	) );

// Let's remove a notification.
Awesome9\Notifications\Center::get()
	->remove( 'awesome9_some_id' )

add 函数中可传递的可用选项

辅助函数

您也可以使用过程式方法

Awesome9\Notifications\add( $message, $options = array() );

Awesome9\Notifications\remove( $notification_id );

所有参数与 JSON 类的相同。

📖 更新日志

查看更新日志文件