shazzad / wp-admin-notice

WordPress中添加和显示管理员通知的库

安装: 69

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:wordpress-library

dev-master 2023-07-25 21:36 UTC

This package is auto-updated.

Last update: 2024-09-30 02:05:27 UTC


README

用于显示管理员通知的帮助类。

安装

composer require shazzad/wp-admin-notice

初始化

初始化服务提供者。

\Shazzad\WpAdminNotice\Provider::setup();

添加通知。

使用适当的参数调用函数do_action以添加通知。此代码必须放置在wp管理员区域开始渲染屏幕内容之前。使用admin_noticesall_admin_noticesnetwork_admin_notices动作钩子来添加通知。

do_action(
	'swpan_notice',
	array(
		'success' => __('You setting is stored successfully.'),
		'id'      => 'plugin-setting',
	)
);

do_action(
	'swpan_notice',
	array(
		'error' => __('Sorry, we could not save your settings.'),
	)
);

添加用户通知。

当你执行某些操作并重定向用户到页面时,使用用户通知。通知将保留直到显示给用户。向动作钩子添加第三个参数以添加用户通知。

do_action(
	'swpan_notice',
	array(
		'message' => __('You setting is stored successfully.'),
		'type'    => 'success',
		'id'      => 'my-notice-id',
	),
	'user'
);

do_action(
	'swpan_notice',
	array(
		'message' => __('Sorry, we could not save your settings.'),
		'type'    => 'error',
		'id'      => 'my-notice-id',
	),
	'user'
);

要求

  • WordPress: 6.0.1
  • PHP: 7.4
  • 测试: 6.2.2