do_action( 'current_screen', WP_Screen $current_screen )

Fires after the current screen has been set.


Parameters Parameters

$current_screen

(WP_Screen) Current WP_Screen object.


Top ↑

More Information More Information

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 a parameter.

Top ↑

Parameter for hooked function 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
}




Top ↑

Source Source

File: wp-admin/includes/class-wp-screen.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Collins Mbaka
    /**
     * 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' );
    
  2. Skip to note 2 content
    Contributed by Mahdi Yazdani

    Hide the desired sidebar area from the Widgets admin page.

    /**
     * Hides out the desired sidebar area from the widgets admin page.
     *
     * @param   WP_Screen  $current_screen  Current WP_Screen object.
     * @return 	void.
     */
    function prefix_hide_sidebar( $current_screen ) {	
    	global $wp_registered_sidebars;
    	$sidebar_id = 'sidebar-1';
    
    	if ( 'widgets' === $current_screen->id ) {
    		if ( array_key_exists( $sidebar_id, $wp_registered_sidebars ) ) {
    			unset( $wp_registered_sidebars[ $sidebar_id ] );
    		}
    	}
    }
    add_action( 'current_screen', 'prefix_hide_sidebar', 10, 1 );
    

You must log in before being able to contribute a note or feedback.