What does it mean by a screen? I’ve had a look in the codex and don’t understand (I’m a newbie). Thanks.
2 Answers
$current_screen
is a global variable in admin screens. It holds the result of WP_Screen::get( $hook_name )->set_current_screen();
.
WP_Screen
is a class, get()
is a static method that returns a real object – an instance of WP_Screen
with some predefined properties:
$screen->base = $base;
$screen->action = $action;
$screen->post_type = (string) $post_type;
$screen->taxonomy = (string) $taxonomy;
$screen->is_user = ( 'user' == $in_admin );
$screen->is_network = ( 'network' == $in_admin );
$screen->in_admin = $in_admin;
$hook_name
is a page specific variable for different admin pages.
set_current_screen()
pushes the object properties into the global variable. I consider this as a rather poor step. It is done for backwards compatibility, I guess.
You can use $current_screen
on plugin pages, in metaboxes and other places to get some context information.
Example:
if ( $GLOBALS['current_screen']->is_network and is_super_admin() )
{
// do something specific for network admins
}