wppaste
WordPress

WP_Screen::get( string|WP_Screen $hook_name = '' ): WP_Screen

Since
3.3.0
Source
wp-admin/includes/class-wp-screen.php:210
Fetches a screen object.

Compatibility

WordPress
since 3.3.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$hook_namestring|WP_Screenoptional
The hook name (also known as the hook suffix) used to determine the screen.
Defaults to the current $hook_suffix global.Default: ''

Return value

WP_Screen
Screen object.

Performance profile

How much work a call to WP_Screen::get() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
47–141

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 320.

Plugin surface
1 hook

Third-party callbacks on 'replace_editor' run inside this call, and their cost is not bounded by anything here.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 24 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Screen::get() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && isset($id)47–112str_ends_with(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && empty($post_id) && isset($id)57–106str_ends_with(), use_block_editor_for_post_type(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && isset($value) && isset($id)64–122str_ends_with(), post_type_exists(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($id)69–111str_ends_with()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && isset($id)70–117str_ends_with(), get_post(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && empty($post_id) && !isset($id)79–105str_ends_with(), use_block_editor_for_post_type()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && isset($id)79–126str_ends_with(), get_post(), apply_filters(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && empty($post_id) && isset($id)80–111str_ends_with(), get_post(), use_block_editor_for_post_type(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && isset($id)84–131str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && isset($value) && !isset($id)86–121str_ends_with(), post_type_exists()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && isset($id)87–127str_ends_with(), get_post(), post_type_exists(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && empty($post_id) && isset($id)89–120str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post_type(), get_current_screen()
12 further outcomes, up to 140 instructions
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && !isset($id)92–116str_ends_with(), get_post()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && empty($post_id) && isset($id)94–125str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post(), use_block_editor_for_post_type(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && isset($id)96–136str_ends_with(), get_post(), apply_filters(), post_type_exists(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && !isset($id)101–125str_ends_with(), get_post(), apply_filters()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && isset($id)101–141str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post(), post_type_exists(), get_current_screen()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && empty($post_id) && !isset($id)102–110str_ends_with(), get_post(), use_block_editor_for_post_type()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && !isset($id)106–130str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && !isset($id)109–126str_ends_with(), get_post(), post_type_exists()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && empty($post_id) && !isset($id)111–119str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post_type()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && !isset($value) && empty($post_id) && !isset($id)116–124str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post(), use_block_editor_for_post_type()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && !isset($id)118–135str_ends_with(), get_post(), apply_filters(), post_type_exists()
!($hook_name instanceof) && empty($value) && !str_ends_with() && !defined('WP_NETWORK_ADMIN') && !defined('WP_USER_ADMIN') && $id !== "index" && $id !== "front" && $post_type === null && !isset($id)123–140str_ends_with(), get_post(), apply_filters(), use_block_editor_for_post(), post_type_exists()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev32047–14160
8.532047–14160
8.432047–1416019 fewer instructions than PHP 8.3
8.333947–14160
8.233947–141602 more instructions than PHP 8.1
8.133747–140604 fewer instructions than PHP 7.4
7.434148–14160

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Screen::get() runs, in this order:

  1. apply_filters( replace_editor )filterline 312 (+102 into the body)

    Allows replacement of the editor.

Uses · 14

Show all 14

Used by · 3

Source code

	public static function get( $hook_name = '' ) {		if ( $hook_name instanceof WP_Screen ) {			return $hook_name;		} 		$id              = '';		$post_type       = null;		$taxonomy        = null;		$in_admin        = false;		$action          = '';		$is_block_editor = false; 		if ( $hook_name ) {			$id = $hook_name;		} elseif ( ! empty( $GLOBALS['hook_suffix'] ) ) {			$id = $GLOBALS['hook_suffix'];		} 		// For those pesky meta boxes.		if ( $hook_name && post_type_exists( $hook_name ) ) {			$post_type = $id;			$id        = 'post'; // Changes later. Ends up being $base.		} else {			if ( str_ends_with( $id, '.php' ) ) {				$id = substr( $id, 0, -4 );			} 			if ( in_array( $id, array( 'post-new', 'link-add', 'media-new', 'user-new' ), true ) ) {				$id     = substr( $id, 0, -4 );				$action = 'add';			}		} 		if ( ! $post_type && $hook_name ) {			if ( str_ends_with( $id, '-network' ) ) {				$id       = substr( $id, 0, -8 );				$in_admin = 'network';			} elseif ( str_ends_with( $id, '-user' ) ) {				$id       = substr( $id, 0, -5 );				$in_admin = 'user';			} 			$id = sanitize_key( $id );			if ( 'edit-comments' !== $id && 'edit-tags' !== $id && str_starts_with( $id, 'edit-' ) ) {				$maybe = substr( $id, 5 );				if ( taxonomy_exists( $maybe ) ) {					$id       = 'edit-tags';					$taxonomy = $maybe;				} elseif ( post_type_exists( $maybe ) ) {					$id        = 'edit';					$post_type = $maybe;				}			} 			if ( ! $in_admin ) {				$in_admin = 'site';			}		} else {			if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) {				$in_admin = 'network';			} elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) {				$in_admin = 'user';			} else {				$in_admin = 'site';			}		} 		if ( 'index' === $id ) {			$id = 'dashboard';		} elseif ( 'front' === $id ) {			$in_admin = false;		} 		$base = $id; 		// If this is the current screen, see if we can be more accurate for post types and taxonomies.		if ( ! $hook_name ) {			if ( isset( $_REQUEST['post_type'] ) ) {				$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;			}

Changelog

Introduced in 3.3.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-admin/includes/class-wp-screen.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.