WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/current screen

Description

current_screen is an admin hook triggered after the necessary elements to identify a screen are set up. This hook provides a WP_Screen object as parameter.

Usage

<?php add_action( 'current_screen', 'function_name' ); ?>

where "function_name" is the name of the function to be called.

Parameter for hooked function

The following is a sample of the WP_Screen object passed as parameter to a function hooked to current_screen and called in a custom post type editing screen.

WP_Screen Object {
	["action"] => string(0) ""
	["base"] => string(4) "post"
	["columns":"WP_Screen":private] => int(0)
	["id"] => string(12) "someposttype"
	["in_admin":protected] => string(4) "site"
	["is_network"] => bool(false)
	["is_user"] => bool(false)
	["parent_base"] => NULL
	["parent_file"] => NULL
	["post_type"] => string(12) "someposttype"
	["taxonomy"] => string(0) ""
	["_help_tabs":"WP_Screen":private] => array(0) { }
	["_help_sidebar":"WP_Screen":private] => string(0) ""
	["_options":"WP_Screen":private] => array(0) { }
	["_show_screen_options":"WP_Screen":private] => NULL
	["_screen_settings":"WP_Screen":private] => NULL
}

and a sample of the object returned in a taxonomy list screen

WP_Screen Object {
	["action"] => string(0) ""
	["base"] => string(9) "edit-tags"
	["columns":"WP_Screen":private] => int(0)
	["id"] => string(10) "edit-mytax"
	["in_admin":protected] => string(4) "site"
	["is_network"] => bool(false)
	["is_user"] => bool(false)
	["parent_base"] => NULL
	["parent_file"] => NULL
	["post_type"] => string(12) "someposttype"
	["taxonomy"] => string(5) "mytax"
	["_help_tabs":"WP_Screen":private] => array(0) { }
	["_help_sidebar":"WP_Screen":private] =>	string(0) ""
	["_options":"WP_Screen":private] => array(0) { }
	["_show_screen_options":"WP_Screen":private] => NULL
	["_screen_settings":"WP_Screen":private] => NULL
}

Example

/**
 * Example of current_screen usage
 * @param $current_screen
 */
function wporg_current_screen_example( $current_screen ) {
	if ( 'someposttype' == $current_screen->post_type && 'post' == $current_screen->base ) {
		// Do something in the edit screen of this post type
	}
}
add_action( 'current_screen', 'wporg_current_screen_example' );

Source File

The current_screen hook is found in wp-admin/includes/screen.php within the set_current_screen() method of the WP_Screen() class.