Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What does it mean by a screen? I've had a look in the codex and don't understand (I'm a newbie). Thanks.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

$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
}
share|improve this answer

I know now. It retrieves the current settings page you are on. So for example, if you're on the the theme options page, it can check to make sure you are.

The $current_screen global variable contains the following elements:

'id' =>
   'base' =>
   'action' => 
   'parent_file' =>
   'parent_base' => 

So you can check if you're on a post type, for example:

function change_default_title ( $title ) {
$screen = get_current_screen() ; 
if ( ' POST_TYPE' == $screen->post_type ) {
$title = 'Enter Invoice title ';
}
return $title; 
}
add_filter ( 'enter_title_here', 'change_default_title' );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.