wppaste
WordPress

WP_List_Table::print_column_headers( bool $with_id = true )

Since
3.1.0
Source
wp-admin/includes/class-wp-list-table.php:1399
Prints column headers, accounting for hidden and sortable columns.

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 notDefault: 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
40–41

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

Plugin surface
None

Nothing here hands control to plugin code.

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()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.

WhenInstructionsCalls 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

PHPCompiledExecutedBranchesNotes
8.6-dev26140–4130
8.526140–4130
8.426140–41306 fewer instructions than PHP 8.3
8.326740–4130
8.226740–4130
8.126740–41307 fewer instructions than PHP 7.4
7.427440–4130

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

Used by · 1

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       = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';				$desc_first    = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;				$abbr          = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';				$orderby_text  = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';				$initial_order = isset( $sortable[ $column_key ][4] ) ? $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.

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