set_screen_options()
- Since
- 2.8.0
- Source
wp-admin/includes/misc.php:694
Compatibility
- WordPress
- since 2.8.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 set_screen_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
- 4–130
- Plugin surface
- 2 hooks
- Called by
- 0
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 145.
Third-party callbacks on 'set-screen-option', 'set_screen_option_{$option}' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach serialize, cache, option, query 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 · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost set_screen_options() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4–8 | none |
isset($value) | 16 | check_admin_referer(), wp_get_current_user() |
isset($value) && $option !== false | 27 | check_admin_referer(), wp_get_current_user(), sanitize_key() |
isset($value) && $option === false && $type && $value | 45–75 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies() |
isset($value) && $option === false && !$type && $value | 50–81 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types() |
isset($value) && $option === false && $type && !str_ends_with() && $option !== "layout_columns" && $value === false | 59–87 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), str_ends_with(), apply_filters() |
isset($value) && $option === false && !$type && !str_ends_with() && $option !== "layout_columns" && $value === false | 64–93 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), str_ends_with(), apply_filters() |
isset($value) && $option === false && $type && $value === false | 64–94 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), str_ends_with(), apply_filters(), apply_filters() |
isset($value) && $option === false && !$type && $value === false | 69–100 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), str_ends_with(), apply_filters(), apply_filters() |
$option === false && $type && !$value | 69–97 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), update_user_meta(), wp_get_referer(), remove_query_arg(), wp_safe_redirect(), exit() |
$option === false && !$type && !$value | 74–103 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), update_user_meta(), wp_get_referer(), remove_query_arg(), wp_safe_redirect(), exit() |
isset($value) && $option === false && $type && !$value | 77–105 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), update_user_meta(), wp_get_referer(), remove_query_arg(), mode(), wp_safe_redirect(), exit() |
9 further outcomes, up to 130 instructions
$option === false && $type && !str_ends_with() && $option !== "layout_columns" && $value !== false | 81–109 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), str_ends_with(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), wp_safe_redirect(), exit() |
isset($value) && $option === false && !$type && !$value | 82–111 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), update_user_meta(), wp_get_referer(), remove_query_arg(), mode(), wp_safe_redirect(), exit() |
$option === false && !$type && !str_ends_with() && $option !== "layout_columns" && $value !== false | 86–115 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), str_ends_with(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), wp_safe_redirect(), exit() |
$option === false && $type && $value !== false | 86–116 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), str_ends_with(), apply_filters(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), wp_safe_redirect(), exit() |
isset($value) && $option === false && $type && !str_ends_with() && $option !== "layout_columns" && $value !== false | 89–117 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), str_ends_with(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), mode(), wp_safe_redirect(), exit() |
$option === false && !$type && $value !== false | 91–122 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), str_ends_with(), apply_filters(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), wp_safe_redirect(), exit() |
isset($value) && $option === false && !$type && !str_ends_with() && $option !== "layout_columns" && $value !== false | 94–123 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), str_ends_with(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), mode(), wp_safe_redirect(), exit() |
isset($value) && $option === false && $type && $value !== false | 94–124 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), str_ends_with(), apply_filters(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), mode(), wp_safe_redirect(), exit() |
isset($value) && $option === false && !$type && $value !== false | 99–130 | check_admin_referer(), wp_get_current_user(), sanitize_key(), get_taxonomies(), get_post_types(), str_ends_with(), apply_filters(), apply_filters(), update_user_meta(), wp_get_referer(), remove_query_arg(), mode(), wp_safe_redirect(), exit() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 145 | 4–130 | 27 | |
| 8.5 | 145 | 4–130 | 27 | |
| 8.4 | 145 | 4–130 | 27 | 14 fewer instructions than PHP 8.3 |
| 8.3 | 159 | 4–144 | 27 | |
| 8.2 | 159 | 4–144 | 27 | |
| 8.1 | 159 | 4–144 | 27 | |
| 7.4 | 159 | 4–144 | 27 |
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 · 2
2 hooks fire while set_screen_options() runs, in this order:
- apply_filters( set-screen-option )filterline 773 (+79 into the body)
Filters a screen option value before it is set.
- apply_filters( set_screen_option_{$option} )filterline 792 (+98 into the body)
Filters a screen option value before it is set.
Uses · 12
- check_admin_referer()Ensures intent by verifying that a user was referred from another admin page with the correct security nonce.
- wp_get_current_user()Retrieves the current user object.
- sanitize_key()Sanitizes a string key.
- get_taxonomies()Retrieves a list of registered taxonomy names or objects.
- get_post_types()Gets a list of all registered post type objects.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- update_user_meta()Updates user meta field based on user ID.
- remove_query_arg()Removes an item or items from a query string.
- wp_get_referer()Retrieves referer from '_wp_http_referer' or HTTP referer.
- add_query_arg()Retrieves a modified URL query string.
- wp_safe_redirect()Performs a safe (local) redirect, using wp_redirect().
Source code
function set_screen_options() { if ( ! isset( $_POST['wp_screen_options'] ) || ! is_array( $_POST['wp_screen_options'] ) ) { return; } check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); $user = wp_get_current_user(); if ( ! $user ) { return; } $option = $_POST['wp_screen_options']['option']; $value = $_POST['wp_screen_options']['value']; if ( sanitize_key( $option ) !== $option ) { return; } $map_option = $option; $type = str_replace( 'edit_', '', $map_option ); $type = str_replace( '_per_page', '', $type ); if ( in_array( $type, get_taxonomies(), true ) ) { $map_option = 'edit_tags_per_page'; } elseif ( in_array( $type, get_post_types(), true ) ) { $map_option = 'edit_per_page'; } else { $option = str_replace( '-', '_', $option ); } switch ( $map_option ) { case 'edit_per_page': case 'users_per_page': case 'edit_comments_per_page': case 'upload_per_page': case 'edit_tags_per_page': case 'plugins_per_page': case 'export_personal_data_requests_per_page': case 'remove_personal_data_requests_per_page': // Network admin. case 'sites_network_per_page': case 'users_network_per_page': case 'site_users_network_per_page': case 'plugins_network_per_page': case 'themes_network_per_page': case 'site_themes_network_per_page': $value = (int) $value; if ( $value < 1 || $value > 999 ) { return; } break; default: $screen_option = false; if ( str_ends_with( $option, '_page' ) || 'layout_columns' === $option ) { /** * Filters a screen option value before it is set. * * The filter can also be used to modify non-standard `[items]_per_page` * settings. See the parent function for a full list of standard options. * * Returning false from the filter will skip saving the current option. * * @since 2.8.0 * @since 5.4.2 Only applied to options ending with '_page', * or the 'layout_columns' option. * * @see set_screen_options() * * @param mixed $screen_option The value to save instead of the option value. * Default false (to skip saving the current option). * @param string $option The option name. * @param int $value The option value. */ $screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscoresChangelog
Introduced in 2.8.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/misc.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.