wppaste
WordPress

WP_Posts_List_Table::_display_rows_hierarchical( array $pages, int $pagenum = 1, int $per_page = 20 )

Source
wp-admin/includes/class-wp-posts-list-table.php:850

Compatibility

WordPress
core
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

$pagesarray
$pagenumintoptional
Default: 1
$per_pageintoptional
Default: 20

Performance profile

How much work a call to WP_Posts_List_Table::_display_rows_hierarchical() 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
Heavy

Reaches the database via get_pages().

Scaling
Scales with input

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

Instructions
12–63

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

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

  • querycontent queryget_pages()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Posts_List_Table::_display_rows_hierarchical()
  • cacheobject cachewp_cache_delete()one call below WP_Posts_List_Table::_display_rows_hierarchical()

Further down the call graph this can also reach option, 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 · 5 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Posts_List_Table::_display_rows_hierarchical() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always12get_pages()
isset($value)38–53array_keys(), _prime_post_caches(), array_map(), update_post_author_caches()
!isset($value)43–58array_keys(), _prime_post_caches(), array_map(), update_post_author_caches(), reset()
isset($value)43–58get_pages(), array_keys(), _prime_post_caches(), array_map(), update_post_author_caches()
!isset($value)48–63get_pages(), array_keys(), _prime_post_caches(), array_map(), update_post_author_caches(), reset()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev13312–6323
8.513312–6323
8.413312–6323
8.313312–6323
8.213312–6323
8.113312–63232 fewer instructions than PHP 7.4
7.413512–6523

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 · 6

Used by · 1

Source code

	private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {		global $wpdb; 		$level = 0; 		if ( ! $pages ) {			$pages = get_pages( array( 'sort_column' => 'menu_order' ) ); 			if ( ! $pages ) {				return;			}		} 		/*		 * Arrange pages into two parts: top level pages and children_pages.		 * children_pages is two dimensional array. Example:		 * children_pages[10][] contains all sub-pages whose parent is 10.		 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations		 * If searching, ignore hierarchy and treat everything as top level		 */		if ( empty( $_REQUEST['s'] ) ) {			$top_level_pages = array();			$children_pages  = array(); 			foreach ( $pages as $page ) {				// Catch and repair bad pages.				if ( $page->post_parent === $page->ID ) {					$page->post_parent = 0;					$wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );					clean_post_cache( $page );				} 				if ( $page->post_parent > 0 ) {					$children_pages[ $page->post_parent ][] = $page;				} else {					$top_level_pages[] = $page;				}			} 			$pages = &$top_level_pages;		} 		$count      = 0;		$start      = ( $pagenum - 1 ) * $per_page;		$end        = $start + $per_page;		$to_display = array(); 		foreach ( $pages as $page ) {			if ( $count >= $end ) {				break;			} 			if ( $count >= $start ) {				$to_display[ $page->ID ] = $level;			} 			++$count; 			if ( isset( $children_pages ) ) {				$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );			}		} 		// If it is the last pagenum and there are orphaned pages, display them with paging as well.		if ( isset( $children_pages ) && $count < $end ) {			foreach ( $children_pages as $orphans ) {				foreach ( $orphans as $op ) {					if ( $count >= $end ) {						break;					} 					if ( $count >= $start ) {						$to_display[ $op->ID ] = 0;					} 					++$count;				}			}		}

Changelog

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.8.8 tag, from src/wp-admin/includes/class-wp-posts-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.