wppaste
WordPress

WP_Posts_List_Table::_page_rows( array $children_pages, int $count, int $parent_page, int $level, int $pagenum, int $per_page, array $to_display )

Since
3.1.0, 4.2.0
Source
wp-admin/includes/class-wp-posts-list-table.php:960
Displays the nested hierarchy of sub-pages together with paging support, based on a top level page ID.

Compatibility

WordPress
since 4.2.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

$children_pagesarray
$countint
$parent_pageint
$levelint
$pagenumint
$per_pageint
$to_displayarray
List of pages to be displayed. Passed by reference.

Performance profile

How much work a call to WP_Posts_List_Table::_page_rows() 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_post().

Scaling
Scales with input

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

Instructions
10–20

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly

Further down the call graph this can also reach hook, option, cache, 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 · 1 distinct outcome

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

WhenInstructionsCalls it makes
always10–20none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7610–2011
8.57610–2011
8.47610–2011
8.37610–2011
8.27610–2011
8.17610–20111 fewer instruction than PHP 7.4
7.47710–2011

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

Used by · 2

Source code

	private function _page_rows( &$children_pages, &$count, $parent_page, $level, $pagenum, $per_page, &$to_display ) {		if ( ! isset( $children_pages[ $parent_page ] ) ) {			return;		} 		$start = ( $pagenum - 1 ) * $per_page;		$end   = $start + $per_page; 		foreach ( $children_pages[ $parent_page ] as $page ) {			if ( $count >= $end ) {				break;			} 			// If the page starts in a subtree, print the parents.			if ( $count === $start && $page->post_parent > 0 ) {				$my_parents = array();				$my_parent  = $page->post_parent; 				while ( $my_parent ) {					// Get the ID from the list or the attribute if my_parent is an object.					$parent_id = $my_parent; 					if ( is_object( $my_parent ) ) {						$parent_id = $my_parent->ID;					} 					$my_parent    = get_post( $parent_id );					$my_parents[] = $my_parent; 					if ( ! $my_parent->post_parent ) {						break;					} 					$my_parent = $my_parent->post_parent;				} 				$num_parents = count( $my_parents ); 				while ( $my_parent = array_pop( $my_parents ) ) {					$to_display[ $my_parent->ID ] = $level - $num_parents;					--$num_parents;				}			} 			if ( $count >= $start ) {				$to_display[ $page->ID ] = $level;			} 			++$count; 			$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );		} 		unset( $children_pages[ $parent_page ] ); // Required in order to keep track of orphans.	}

Changelog

Introduced in 4.2.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.

4.2.0
Added the $to_display parameter.from the docblock
3.1.0
(Standalone function exists since 2.6.0)from the docblock

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.