WP_Screen::render_view_mode()
- Since
- 4.4.0
- Source
wp-admin/includes/class-wp-screen.php:1297
Compatibility
- WordPress
- since 4.4.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.
Performance profile
How much work a call to WP_Screen::render_view_mode() 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
- Trivial
- Scaling
- Constant
- Instructions
- 11–61
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
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 63.
Third-party callbacks on 'view_mode_post_types' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, 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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Screen::render_view_mode() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 11 | get_current_screen() |
!$view_mode_post_types | 24–27 | get_current_screen(), get_post_types(), apply_filters() |
isset($mode) | 49–56 | get_current_screen(), get_post_types(), apply_filters(), add_filter(), _e(), checked(), _e(), checked(), _e() |
!isset($mode) | 54–61 | get_current_screen(), get_post_types(), apply_filters(), get_user_setting(), add_filter(), _e(), checked(), _e(), checked(), _e() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 63 | 11–61 | 5 | |
| 8.5 | 63 | 11–61 | 5 | |
| 8.4 | 63 | 11–61 | 5 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 66 | 11–64 | 5 | |
| 8.2 | 66 | 11–64 | 5 | |
| 8.1 | 66 | 11–64 | 5 | |
| 7.4 | 66 | 11–64 | 5 |
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::render_view_mode() runs, in this order:
- apply_filters( view_mode_post_types )filterline 1317 (+20 into the body)
Filters the post types that have different view mode options.
Uses · 7
- get_current_screen()Get the current screen object
- get_post_types()Gets a list of all registered post type objects.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_user_setting()Retrieves user interface setting value based on setting name.
- add_filter()Adds a callback function to a filter hook.
- _e()Displays translated text.
- checked()Outputs the HTML checked attribute.
Used by · 1
- WP_Screen::render_screen_options()Renders the screen options tab.
Source code
public function render_view_mode() { global $mode; $screen = get_current_screen(); // Currently only enabled for posts and comments lists. if ( 'edit' !== $screen->base && 'edit-comments' !== $screen->base ) { return; } $view_mode_post_types = get_post_types( array( 'show_ui' => true ) ); /** * Filters the post types that have different view mode options. * * @since 4.4.0 * * @param string[] $view_mode_post_types Array of post types that can change view modes. * Default post types with show_ui on. */ $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types ); if ( 'edit' === $screen->base && ! in_array( $this->post_type, $view_mode_post_types, true ) ) { return; } if ( ! isset( $mode ) ) { $mode = get_user_setting( 'posts_list_mode', 'list' ); } // This needs a submit button. add_filter( 'screen_options_show_submit', '__return_true' ); ?> <fieldset class="metabox-prefs view-mode"> <legend><?php _e( 'View mode' ); ?></legend> <label for="list-view-mode"> <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> /> <?php _e( 'Compact view' ); ?> </label> <label for="excerpt-view-mode"> <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> /> <?php _e( 'Extended view' ); ?> </label> </fieldset> <?php }Changelog
Introduced in 4.4.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.