WP_Screen::render_per_page_options()
- Since
- 3.3.0
- Source
wp-admin/includes/class-wp-screen.php:1231
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
- Scaling
- Constant
- Instructions
- 6–103
- Plugin surface
- 4 hooks
- 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 119.
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.
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 · 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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6 | ->get_option() |
$per_page_label !== null && !empty($per_page) && !$per_page && !isset($value) | 55–66 | ->get_option(), ->get_option(), ->get_option(), get_user_option(), apply_filters(), add_filter(), _e(), esc_attr() |
$per_page_label !== null && !isset($value) | 59–73 | ->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–70 | ->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–74 | ->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–77 | ->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–81 | ->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–78 | ->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–85 | ->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–84 | ->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–91 | ->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–88 | ->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 103 instructions
$per_page_label !== null && !empty($per_page) && !$per_page && isset($value) | 81–92 | ->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–95 | ->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–99 | ->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–96 | ->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–103 | ->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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 119 | 6–103 | 11 | |
| 8.5 | 119 | 6–103 | 11 | |
| 8.4 | 119 | 6–103 | 11 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 122 | 6–106 | 11 | |
| 8.2 | 122 | 6–106 | 11 | |
| 8.1 | 122 | 6–106 | 11 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 123 | 6–107 | 11 |
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:
- apply_filters( comments_per_page )filterline 1258 (+27 into the body)
Filters the number of comments listed per page in the comments list table.
- apply_filters( edit_categories_per_page )filterline 1261 (+30 into the body)
Filters the number of terms displayed per page for the Categories list table.
- apply_filters( {$option} )filterline 1264 (+33 into the body)
Filters the number of items to be displayed on each page of the list table.
- apply_filters( edit_posts_per_page )filterline 1270 (+39 into the body)
Filters the number of posts displayed per page when specifically listing "posts".
Uses · 7
- __()Retrieves the translation of $text.
- get_user_option()Retrieves user option that can be either per Site or per Network.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- add_filter()Adds a callback function to a filter hook.
- _e()Displays translated text.
- esc_attr()Escaping for HTML attributes.
- WP_Screen::get_option()Gets the arguments for an option for the screen.
Used by · 1
- WP_Screen::render_screen_options()Renders the screen options tab.
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 = isset( $_REQUEST['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" 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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.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.