拦截 WordPress 管理仪表板以获取警报
如何让插件向仪表板右上角发送警报,该仪表板通常会出现 WordPress 升级通知?
我想我需要在插件代码中进行某种 add_filter() 或 add_action() 调用。
How can I make a plugin send an alert to one's dashboard at the top right below where the WordPress upgrade notice might normally appear?
I imagine I need some kind of add_filter() or add_action() call in the plugins' code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将以下代码插入主题的functions.php 或插件中。这是一个您可以调整并进一步采用的示例。在这个演示中,我想演示您可以在哪里发布一条消息,说明用户需要更新插件。
首先,它拦截 admin_head 以插入一些 Javascript。在 Javascript 中,由于我们知道当前的 WordPress 包含 jQuery,但使用 .noConflict() 选项加载它,因此我们可以将 jQuery 分配给 $j 以使其在代码中保持简短。当页面完全加载后,它会查找包含“Dashboard”的 H2,即仪表板页面。然后它会向上遍历 DOM 一点,到达一个可以插入警报的好位置,然后在那里添加一个警报。它以专业的 fadeIn() 调用结束。
Insert the following code in either a functions.php of your theme, or in a plugin. It's a sample that you can adapt and take further. In this demo, I wanted to demonstrate where you could post a message saying that the user needs to update a plugin.
First, it intercepts admin_head to insert some Javascript. In the Javascript, since we know that current WordPress's include jQuery, but loads it with the .noConflict() option, then we can assign the jQuery to $j to keep it short in our code. When the page has fully loaded, it looks for an H2 that contains "Dashboard", meaning the Dashboard page. It then traverses up the DOM a little to a nice slot where it can insert the alert and then adds one there. It concludes with a professional fadeIn() call.