wppaste
WordPress

WP_Screen::render_per_page_options()

Since
3.3.0
Source
wp-admin/includes/class-wp-screen.php:1233
Renders the items per page option.

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.

Performance profile

How much work a call to WP_Screen::render_per_page_options() 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
6–101

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

Plugin surface
4 hooks

Third-party callbacks on 'comments_per_page', 'edit_categories_per_page', '{$option}' 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 · 17 distinct outcomes

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

WhenInstructionsCalls it makes
always6->get_option()
$per_page_label !== null && !empty($per_page) && !$per_page && !isset($value)55–64->get_option(), ->get_option(), ->get_option(), get_user_option(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label !== null && !isset($value)59–71->get_option(), ->get_option(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label === null && !empty($per_page) && !$per_page && !isset($value)59–68->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label !== null && !empty($per_page) && !$per_page && isset($value)63–72->get_option(), ->get_option(), ->get_option(), get_user_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label === null && !isset($value)63–75->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label !== null && isset($value)67–79->get_option(), ->get_option(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label === null && !empty($per_page) && !$per_page && isset($value)67–76->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label === null && isset($value)71–83->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr()
$per_page_label !== null && !empty($per_page) && !$per_page && !isset($value)73–82->get_option(), ->get_option(), ->get_option(), get_user_option(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
$per_page_label !== null && !isset($value)77–89->get_option(), ->get_option(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
$per_page_label === null && !empty($per_page) && !$per_page && !isset($value)77–86->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
5 further outcomes, up to 101 instructions
$per_page_label !== null && !empty($per_page) && !$per_page && isset($value)81–90->get_option(), ->get_option(), ->get_option(), get_user_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
$per_page_label === null && !isset($value)81–93->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
$per_page_label !== null && isset($value)85–97->get_option(), ->get_option(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
$per_page_label === null && !empty($per_page) && !$per_page && isset($value)85–94->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
$per_page_label === null && isset($value)89–101->get_option(), ->get_option(), __(), ->get_option(), get_user_option(), ->get_option(), apply_filters(), apply_filters(), add_filter(), _e(), esc_attr(), esc_attr(), esc_attr(), esc_attr()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1166–10111
8.51166–10111
8.41166–101113 fewer instructions than PHP 8.3
8.31196–10411
8.21196–10411
8.11196–10411
7.41196–10411

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 · 4

4 hooks fire while WP_Screen::render_per_page_options() runs, in this order:

  1. apply_filters( comments_per_page )filterline 1260 (+27 into the body)

    Filters the number of comments listed per page in the comments list table.

  2. apply_filters( edit_categories_per_page )filterline 1263 (+30 into the body)

    Filters the number of terms displayed per page for the Categories list table.

  3. apply_filters( {$option} )filterline 1266 (+33 into the body)

    Filters the number of items to be displayed on each page of the list table.

  4. apply_filters( edit_posts_per_page )filterline 1272 (+39 into the body)

    Filters the number of posts displayed per page when specifically listing "posts".

Uses · 7

Used by · 1

Source code

	public function render_per_page_options() {		if ( null === $this->get_option( 'per_page' ) ) {			return;		} 		$per_page_label = $this->get_option( 'per_page', 'label' );		if ( null === $per_page_label ) {			$per_page_label = __( 'Number of items per page:' );		} 		$option = $this->get_option( 'per_page', 'option' );		if ( ! $option ) {			$option = str_replace( '-', '_', "{$this->id}_per_page" );		} 		$per_page = (int) get_user_option( $option );		if ( empty( $per_page ) || $per_page < 1 ) {			$per_page = $this->get_option( 'per_page', 'default' );			if ( ! $per_page ) {				$per_page = 20;			}		} 		if ( 'edit_comments_per_page' === $option ) {			$comment_status = $_REQUEST['comment_status'] ?? 'all'; 			/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */			$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );		} elseif ( 'categories_per_page' === $option ) {			/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */			$per_page = apply_filters( 'edit_categories_per_page', $per_page );		} else {			/** This filter is documented in wp-admin/includes/class-wp-list-table.php */			$per_page = apply_filters( "{$option}", $per_page );		} 		// Back compat.		if ( isset( $this->post_type ) ) {			/** This filter is documented in wp-admin/includes/post.php */			$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );		} 		// This needs a submit button.		add_filter( 'screen_options_show_submit', '__return_true' ); 		?>		<fieldset class="screen-options">		<legend><?php _e( 'Pagination' ); ?></legend>			<?php if ( $per_page_label ) : ?>				<label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>				<input type="number" step="1" min="1" max="999" class="screen-per-page small-text" name="wp_screen_options[value]"					id="<?php echo esc_attr( $option ); ?>"					value="<?php echo esc_attr( $per_page ); ?>" />			<?php endif; ?>				<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />		</fieldset>		<?php	}

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