wppaste
WordPress

WP_Screen::render_view_mode()

Since
4.4.0
Source
wp-admin/includes/class-wp-screen.php:1297
Renders the list table view mode preferences.

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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
11–61

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

Plugin surface
1 hook

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

Called by
1

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

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always11get_current_screen()
!$view_mode_post_types24–27get_current_screen(), get_post_types(), apply_filters()
isset($mode)49–56get_current_screen(), get_post_types(), apply_filters(), add_filter(), _e(), checked(), _e(), checked(), _e()
!isset($mode)54–61get_current_screen(), get_post_types(), apply_filters(), get_user_setting(), add_filter(), _e(), checked(), _e(), checked(), _e()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6311–615
8.56311–615
8.46311–6153 fewer instructions than PHP 8.3
8.36611–645
8.26611–645
8.16611–645
7.46611–645

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:

  1. apply_filters( view_mode_post_types )filterline 1317 (+20 into the body)

    Filters the post types that have different view mode options.

Uses · 7

Used by · 1

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.

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