如何在我的插件中检测 WordPress 管理面板?
我的插件中有两个事件。一种是为前端运行的。另一个是为管理面板运行的。两者在一种特定情况下调用相同的函数,这会将内容回显到屏幕上。如何使该函数变得智能,调用 WordPress 中的某些内容,并检测它是否在前端而不是管理面板中加载?我不希望它在前端的屏幕上回显内容,但确实希望它在管理面板上这样做。现在,两者都在回响,这不是我想要的。
背景
对于前端(访问者看到的网站的一侧),我正在拦截“wp”事件并检查:
( is_single() || is_page() || is_home() || is_archive() || is_category() || is_tag())
对于管理面板,我正在拦截“admin_menu”事件。我尝试拦截上面的 is_*() 内容,但它似乎以某种方式回答 TRUE 或其他内容,没有给我前端和管理面板之间的区别。
I've got two events in my plugin. One is run for the front-end. The other is run for the admin panel. Both call the same function in one particular situation, and this echoes stuff to the screen. How do I make it such that the function is smart, calls something in WordPress, and detects whether it's being loaded in the front-end versus the admin panel? I don't want it to echo stuff to the screen on the front-end, but do want it to do so on the admin panel. Right now, it's echoing on both, which is not what I want.
Background
For the front end (the side of the site that the visitor sees), I'm intercepting the 'wp' event and checking for:
( is_single() || is_page() || is_home() || is_archive() || is_category() || is_tag())
For the admin panel, I'm intercepting the 'admin_menu' event. I tried intercepting the is_*() stuff above, but it seems to somehow answer TRUE or something, not giving me a difference between front-end and admin panel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
is_admin()
检测仪表板或管理面板何时显示。更多条件标签记录如下:http://codex.wordpress.org/Conditional_Tags
Use
is_admin()
to detect when the Dashboard or the administration panels are being displayed.More conditional tags documented here: http://codex.wordpress.org/Conditional_Tags
如果您以管理员身份登录但正在访问博客的前端页面,则
is_admin()
似乎返回 true。我还尝试让我的插件检测是否显示管理页面,并且is_admin()
未能按预期运行,显然是因为我同时以管理员身份登录。is_admin()
appears to return true, if you are logged in as administrator but are accessing a front-end page of the blog. I'm also trying to have my plugin detect if an admin page is displayed or not, andis_admin()
is failing to behave as expected, evidently because I'm simultaneously logged in as administrator.