WP_Screen::get( string|WP_Screen $hook_name = '' ): WP_Screen
- Since
- 3.3.0
- Source
wp-admin/includes/class-wp-screen.php:210
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
- Scaling
- Constant
- Instructions
- 47–141
- Plugin surface
- 1 hook
- Called by
- 3
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 320.
Third-party callbacks on 'replace_editor' run inside this call, and their cost is not bounded by anything here.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_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.
| When | Instructions | Calls 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–112 | str_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–106 | str_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–122 | str_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–111 | str_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–117 | str_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–105 | str_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–126 | str_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–111 | str_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–131 | str_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–121 | str_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–127 | str_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–120 | str_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–116 | str_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–125 | str_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–136 | str_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–125 | str_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–141 | str_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–110 | str_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–130 | str_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–126 | str_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–119 | str_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–124 | str_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–135 | str_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–140 | str_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 320 | 47–141 | 60 | |
| 8.5 | 320 | 47–141 | 60 | |
| 8.4 | 320 | 47–141 | 60 | 19 fewer instructions than PHP 8.3 |
| 8.3 | 339 | 47–141 | 60 | |
| 8.2 | 339 | 47–141 | 60 | 2 more instructions than PHP 8.1 |
| 8.1 | 337 | 47–140 | 60 | 4 fewer instructions than PHP 7.4 |
| 7.4 | 341 | 48–141 | 60 |
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:
Uses · 14
- post_type_exists()Determines whether a post type is registered.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- sanitize_key()Sanitizes a string key.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- taxonomy_exists()Determines whether the taxonomy name exists.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- __()Retrieves the translation of $text.
- get_post()Retrieves post data given a post ID or post object.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- use_block_editor_for_post()Returns whether the post can be edited in the block editor.
- is_object_in_taxonomy()Determines if the given object type is associated with the given taxonomy.
- use_block_editor_for_post_type()Returns whether a post type is compatible with the block editor.
Show all 14
- get_current_screen()Get the current screen object
- WP_Screen::__construct()Constructor
Used by · 3
- WP_Customize_Nav_Menus_Panel::render_screen_options()Render screen options for Menus.
- convert_to_screen()Converts a screen string to a screen object.
- set_current_screen()Set the current screen object
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.