set_current_screen

Definition:
function set_current_screen( $id = '' ) {}

Set the current screen object

Parameters

  • string $id: Screen id, optional.

Defined filters

  • current_screen
    apply_filters('current_screen', $current_screen)

Source code

function set_current_screen( $id =  '' ) {

	global $current_screen, $hook_suffix, $typenow, $taxnow;



	$action = '';



	if ( empty($id) ) {

		$current_screen = $hook_suffix;

		$current_screen = str_replace('.php', '', $current_screen);

		if ( preg_match('/-add|-new$/', $current_screen) )

			$action = 'add';

		$current_screen = str_replace('-new', '', $current_screen);

		$current_screen = str_replace('-add', '', $current_screen);

		$current_screen = array('id' => $current_screen, 'base' => $current_screen);

	} else {

		$id = sanitize_key($id);

		if ( false !== strpos($id, '-') ) {

			list( $id, $typenow ) = explode('-', $id, 2);

			if ( taxonomy_exists( $typenow ) ) {

				$id = 'edit-tags';

				$taxnow = $typenow;

				$typenow = '';

			}

		}

		$current_screen = array('id' => $id, 'base' => $id);

	}



	$current_screen = (object) $current_screen;



	$current_screen->action = $action;



	// Map index to dashboard

	if ( 'index' == $current_screen->base )

		$current_screen->base = 'dashboard';

	if ( 'index' == $current_screen->id )

		$current_screen->id = 'dashboard';



	if ( 'edit' == $current_screen->id ) {

		if ( empty($typenow) )

			$typenow = 'post';

		$current_screen->id .= '-' . $typenow;

		$current_screen->post_type = $typenow;

	} elseif ( 'post' == $current_screen->id ) {

		if ( empty($typenow) )

			$typenow = 'post';

		$current_screen->id = $typenow;

		$current_screen->post_type = $typenow;

	} elseif ( 'edit-tags' == $current_screen->id ) {

		if ( empty($taxnow) )

			$taxnow = 'post_tag';

		$current_screen->id = 'edit-' . $taxnow;

		$current_screen->taxonomy = $taxnow;

	}



	$current_screen->is_network = is_network_admin();

	$current_screen->is_user = is_user_admin();



	if ( $current_screen->is_network ) {

		$current_screen->base .= '-network';

		$current_screen->id .= '-network';

	} elseif ( $current_screen->is_user ) {

		$current_screen->base .= '-user';

		$current_screen->id .= '-user';

	}



	$current_screen = apply_filters('current_screen', $current_screen);

}

2841

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: