[wp-hackers] How to determine which admin screen I'm currently viewing
24-7 at gmx.net
Fri Dec 2 17:05:16 UTC 2011
> Indeed. In 3.3 we fixed a lot of issues with the screen object not being
decorated with enough information, or worse, lying to you.
Sounds good. Thanks for that.
> Instead of checking $pagenow for 'post.php' or 'post-new.php', you can
check $screen->base (which will be 'post' for all post types, as it is the
base). You can check $screen->action, which will be 'add' for post-new.php.
Instead of checking $pagenow for 'edit.php', get_current_screen()->base
will return 'edit'
I simply don't get around why there's no argument in $current_screen that
align with what was given in the $submenu or $menu global. Comparing those
on a consistent base would allow to improve and simplify the admin_menu.
> The best way to determine what post type or taxonomy you are viewing is to
check $screen->post_type, $screen->taxonomy (instead of $typenow and
$taxnow, or checking $_GET, etc.). You can obviously combine these to check
both base and post_type and what not, to get a very clear picture of the
page you're trying to attach something to (for example). And of course
there is $screen->id which pulls together the base along with the post type
or taxonomy, depending on whether you are on edit.php, post(-new)?.php,
edit-tags.php, or elsewhere.
My point is that it's extremly hard to get around where you're really are.
It's not like "if condition X is met: print title". It's more like "Compare
combined $menu/submenu array with $current_screen match", as this allows to
determine _any_ location/screen. And imho this should be easily achievable
to give full control over your plugins/themes admin UI additions related to
menus. I'm currently trying to write sort of an tutorial about it to
explain where the shortcomings are.
Did comments.php find it's way into the admin_menu somehow? So far there's
nothing about it in $menu/submenu and $current_screen is only filled with
id/base, rest empty.
> There's a lot of good stuff here. I would dig in.
Sorry, but I guess I got this one wrong. What are you trying to tell me?
More information about the wp-hackers