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 comments
Comments are closed.
What does it mean by a screen? I’ve had a look in the codex and don’t understand (I’m a newbie). Thanks.
Comments are closed.
$current_screen
is a global variable in admin screens. It holds the result ofWP_Screen::get( $hook_name )->set_current_screen();
.WP_Screen
is a class,get()
is a static method that returns a real object â an instance ofWP_Screen
with some predefined properties:$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:
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:So you can check if you’re on a post type, for example: