开发者

How Do I Detect A WordPress Admin Panel in my Plugin?

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, 开发者_StackOverflow中文版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.


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() 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, and is_admin() is failing to behave as expected, evidently because I'm simultaneously logged in as administrator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜