[wp-hackers] Best way to detect post type in admin

Lox lox.dev at knc.nc
Thu Jul 15 07:14:09 UTC 2010

2010/7/15 Andrew Nacin <wp at andrewnacin.com>:
> $typenow will contain the post type. See the $current_screen object for more
> context. (There's also $taxnow, $pagenow, and others. $current_screen
> definitely the best thing to inspect.)

Nice thks. But $current_screen object is not available at init and
admin_init time.

I ended up by using admin_enqueue_scripts hook like this:

        function admin_enqueue_scripts ()
		global $current_screen;
		if( $current_screen->post_type !== 'winner') return;
		if( $current_screen->action !== 'add' && (!isset($_GET['action']) ||
$_GET['action'] !== 'edit') ) return;

Something weird, when creating a new post, $current_screen->action is
set to 'add' whereas when editing it, it is empty...
Shouldn't it be set to 'edit' ? Is that a bug that needs to be reported?

lox.dev at knc.nc

More information about the wp-hackers mailing list