checked( mixed $checked, mixed $current = true, bool $display = true ): string
- Since
- 1.0.0
- Source
wp-includes/general-template.php:5242
Description
Compares the first two arguments and if identical marks as checked.
Compatibility
- WordPress
- since 1.0.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.
Parameters
$checkedmixed- One of the values to compare.
$currentmixedoptional- The other value to compare if not just true.
Default true.Default:true $displaybooloptional- Whether to echo or just return the string.
Default true.Default:true
Return value
string- HTML attribute or empty string.
Performance profile
How much work a call to checked() 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
- 10
- Plugin surface
- None
- Called by
- 32
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. The body compiles to 10.
Nothing here hands control to plugin code.
32 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost checked() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 10 | __checked_selected_helper() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 10 instructions, 10 executed per call, 0 branches. The work does not change between versions.
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.
Uses · 1
- __checked_selected_helper()Private helper function for checked, selected, disabled and readonly.
Used by · 32
- Custom_Background::admin_page()Displays the custom background page.
- Custom_Image_Header::show_header_selector()Displays UI for selecting one of several default headers.
- Custom_Image_Header::step_1()Displays first step of custom header image page.
- WP_Customize_Control::render_content()Renders the control's content.
- WP_Screen::render_list_table_columns_preferences()Renders the list table columns preferences.
- WP_Screen::render_meta_boxes_preferences()Renders the meta boxes preferences.
- WP_Screen::render_screen_layout()Renders the option for number of columns on the page.
- WP_Screen::render_view_mode()Renders the list table view mode preferences.
- WP_Screen::show_screen_options()
- WP_Widget_Archives::form()Outputs the settings form for the Archives widget.
- WP_Widget_Categories::form()Outputs the settings form for the Categories widget.
- WP_Widget_Links::form()Outputs the settings form for the Links widget.
Show all 32
- WP_Widget_Recent_Posts::form()Outputs the settings form for the Recent Posts widget.
- WP_Widget_Tag_Cloud::form()Outputs the Tag Cloud widget settings form.
- WP_Widget_Text::form()Outputs the Text widget settings form.
- Walker_Category_Checklist::start_el()Start the element output.
- Walker_Nav_Menu_Edit::start_el()Start the element output.
- admin_color_scheme_picker()Displays the default administration color scheme picker (Used in user-edit.php).
- display_setup_form()Displays installer setup form.
- link_submit_meta_box()Displays link create form fields.
- meta_box_prefs()Prints the meta box preferences for screen meta.
- network_step1()Prints step 1 for Network installation process.
- post_comment_status_meta_box()Displays comments status form fields.
- post_format_meta_box()Displays post format form elements.
- post_submit_meta_box()Displays post submit form fields.
- request_filesystem_credentials()Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.
- signup_user()Shows a form for a visitor to sign up for a new user account.
- twentyeleven_settings_field_color_scheme()Renders the Color Scheme setting field.
- twentyeleven_settings_field_layout()Renders the Layout setting field.
- use_ssl_preference()Optional SSL preference that can be turned on by hooking to the 'personal_options' action.
- wp_media_insert_url_form()Creates the form for external url.
- wp_widget_rss_form()Displays RSS widget options form.
Source code
function checked( $checked, $current = true, $display = true ) { return __checked_selected_helper( $checked, $current, $display, 'checked' );}Changelog
Introduced in 1.0.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.9.7 tag, from
src/wp-includes/general-template.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.