WP_List_Table::print_column_headers( bool $with_id = true )
- Since
- 3.1.0
- Source
wp-admin/includes/class-wp-list-table.php:1408
Compatibility
- WordPress
- since 3.1.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
$with_idbooloptional- Whether to set the ID attribute or not. Default true.Default:
true
Performance profile
How much work a call to WP_List_Table::print_column_headers() 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
- Light
- Scaling
- Scales with input
- Instructions
- 40–41
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 244.
Nothing here hands control to plugin code.
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()one call below WP_List_Table::print_column_headers()
Further down the call graph this can also reach option, cache, serialize, 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_List_Table::print_column_headers() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) && empty($columns) | 40–41 | ->get_column_info(), set_url_scheme(), remove_query_arg() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 244 | 40–41 | 29 | |
| 8.5 | 244 | 40–41 | 29 | |
| 8.4 | 244 | 40–41 | 29 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 250 | 40–41 | 29 | |
| 8.2 | 250 | 40–41 | 29 | |
| 8.1 | 250 | 40–41 | 29 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 252 | 40–41 | 29 |
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 · 7
- set_url_scheme()Sets the scheme for a URL.
- remove_query_arg()Removes an item or items from a query string.
- __()Retrieves the translation of $text.
- esc_attr()Escaping for HTML attributes.
- esc_url()Checks and cleans a URL.
- add_query_arg()Retrieves a modified URL query string.
- WP_List_Table::get_column_info()Gets a list of all, hidden, and sortable columns, with filter applied.
Used by · 1
- WP_List_Table::display()Displays the table.
Source code
public function print_column_headers( $with_id = true ) { list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); $current_url = remove_query_arg( 'paged', $current_url ); // When users click on a column header to sort by other columns. if ( isset( $_GET['orderby'] ) ) { $current_orderby = $_GET['orderby']; // In the initial view there's no orderby parameter. } else { $current_orderby = ''; } // Not in the initial view and descending order. if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) { $current_order = 'desc'; } else { // The initial view is not always 'asc', we'll take care of this below. $current_order = 'asc'; } if ( ! empty( $columns['cb'] ) ) { static $cb_counter = 1; $columns['cb'] = '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" /> <label for="cb-select-all-' . $cb_counter . '">' . '<span class="screen-reader-text">' . /* translators: Hidden accessibility text. */ __( 'Select All' ) . '</span>' . '</label>'; ++$cb_counter; } foreach ( $columns as $column_key => $column_display_name ) { $class = array( 'manage-column', "column-$column_key" ); $aria_sort_attr = ''; $abbr_attr = ''; $order_text = ''; if ( in_array( $column_key, $hidden, true ) ) { $class[] = 'hidden'; } if ( 'cb' === $column_key ) { $class[] = 'check-column'; } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) { $class[] = 'num'; } if ( $column_key === $primary ) { $class[] = 'column-primary'; } if ( isset( $sortable[ $column_key ] ) ) { $orderby = $sortable[ $column_key ][0] ?? ''; $desc_first = $sortable[ $column_key ][1] ?? false; $abbr = $sortable[ $column_key ][2] ?? ''; $orderby_text = $sortable[ $column_key ][3] ?? ''; $initial_order = $sortable[ $column_key ][4] ?? ''; /* * We're in the initial view and there's no $_GET['orderby'] then check if the * initial sorting information is set in the sortable columns and use that. */ if ( '' === $current_orderby && $initial_order ) { // Use the initially sorted column $orderby as current orderby. $current_orderby = $orderby; // Use the initially sorted column asc/desc order as initial order. $current_order = $initial_order; } /* * True in the initial view when an initial orderby is set via get_sortable_columns() * and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby. */ if ( $current_orderby === $orderby ) { // The sorted column. The `aria-sort` attribute must be set only on the sorted column. if ( 'asc' === $current_order ) { $order = 'desc';Changelog
Introduced in 3.1.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 7.1.0 tag, from
src/wp-admin/includes/class-wp-list-table.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.