render_block_core_page_list( array $attributes, string $content, WP_Block $block ): string
- Since
- 5.8.0
- Source
wp-includes/blocks/page-list.php:257
core/page-list block on server.Compatibility
- WordPress
- since 5.8.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
$attributesarray- The block attributes.
$contentstring- The saved content.
$blockWP_Block- The parsed block.
Return value
string- Returns the page list markup.
Performance profile
How much work a call to render_block_core_page_list() 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
- Scaling
- Scales with input
- Instructions
- 16–97
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_pages().
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 147.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_pages()called directly - hookthird-party callbacks
apply_filters()one call below render_block_core_page_list() - optionoption read or write
get_option()one call below render_block_core_page_list()
Further down the call graph this can also reach 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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_page_list() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($all_pages) | 16 | get_pages() |
!empty($all_pages) && $parent_page_id !== 0 && !$parent_page_id | 46–47 | get_pages(), block_core_page_list_build_css_colors(), array_merge(), block_core_page_list_nest_pages() |
!empty($all_pages) && $parent_page_id === 0 | 78–82 | get_pages(), block_core_page_list_build_css_colors(), array_merge(), block_core_page_list_nest_pages(), block_core_page_list_render_nested_page_list(), class(), sprintf() |
!empty($all_pages) && $parent_page_id === 0 | 84–88 | get_pages(), block_core_page_list_build_css_colors(), array_merge(), block_core_page_list_nest_pages(), block_core_page_list_get_submenu_visibility(), block_core_page_list_render_nested_page_list(), class(), sprintf() |
!empty($all_pages) && $parent_page_id !== 0 && $parent_page_id | 87–91 | get_pages(), block_core_page_list_build_css_colors(), array_merge(), block_core_page_list_nest_pages(), block_core_page_list_nest_pages(), block_core_page_list_render_nested_page_list(), class(), sprintf() |
!empty($all_pages) && $parent_page_id !== 0 && $parent_page_id | 93–97 | get_pages(), block_core_page_list_build_css_colors(), array_merge(), block_core_page_list_nest_pages(), block_core_page_list_nest_pages(), block_core_page_list_get_submenu_visibility(), block_core_page_list_render_nested_page_list(), class(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 146 | 16–96 | 11 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 147 | 16–97 | 11 | |
| 8.4 | 147 | 16–97 | 11 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 153 | 16–103 | 11 | |
| 8.2 | 153 | 16–103 | 11 | |
| 8.1 | 153 | 16–103 | 11 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 154 | 16–104 | 11 |
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 · 9
- get_pages()Retrieves an array of pages (or hierarchical post type items).
- get_queried_object_id()Retrieves the ID of the currently queried object.
- get_post_ancestors()Retrieves the IDs of the ancestors of a post.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- block_core_page_list_build_css_colors()Build an array with CSS classes and inline styles defining the colors which will be applied to the pages markup in the front-end when it is a descendant of navigation.
- block_core_page_list_nest_pages()Outputs nested array of pages
- block_core_page_list_get_submenu_visibility()Returns the submenu visibility value with backward compatibility for the deprecated openSubmenusOnClick attribute.
- block_core_page_list_render_nested_page_list()Outputs Page list markup from an array of pages with nested children.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
Source code
function render_block_core_page_list( $attributes, $content, $block ) { static $block_id = 0; ++$block_id; $parent_page_id = $attributes['parentPageID']; $is_nested = ! empty( $block->context['core/isInsideSubmenu'] ); $all_pages = get_pages( array( 'sort_column' => 'menu_order,post_title', 'order' => 'asc', ) ); // If there are no pages, there is nothing to show. if ( empty( $all_pages ) ) { return; } $top_level_pages = array(); $pages_with_children = array(); $active_page_ancestor_ids = array(); foreach ( (array) $all_pages as $page ) { $is_active = ! empty( $page->ID ) && ( get_queried_object_id() === $page->ID ); if ( $is_active ) { $active_page_ancestor_ids = get_post_ancestors( $page->ID ); } if ( $page->post_parent ) { $pages_with_children[ $page->post_parent ][ $page->ID ] = array( 'page_id' => $page->ID, 'title' => $page->post_title, 'link' => get_permalink( $page ), 'is_active' => $is_active, ); } else { $top_level_pages[ $page->ID ] = array( 'page_id' => $page->ID, 'title' => $page->post_title, 'link' => get_permalink( $page ), 'is_active' => $is_active, ); } } $colors = block_core_page_list_build_css_colors( $attributes, $block->context ); $classes = array_merge( $colors['css_classes'] ); $style_attribute = $colors['inline_styles']; $css_classes = trim( implode( ' ', $classes ) ); $nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children ); if ( 0 !== $parent_page_id ) { // If the parent page has no child pages, there is nothing to show. if ( ! array_key_exists( $parent_page_id, $pages_with_children ) ) { return; } $nested_pages = block_core_page_list_nest_pages( $pages_with_children[ $parent_page_id ], $pages_with_children ); } $is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context ); // Get submenu visibility with backward compatibility for openSubmenusOnClick. $submenu_visibility = $is_navigation_child ? block_core_page_list_get_submenu_visibility( $block->context ) : 'hover'; $show_submenu_icons = array_key_exists( 'showSubmenuIcon', $block->context ) ? $block->context['showSubmenuIcon'] : false; $wrapper_markup = $is_nested ? '%2$s' : '<ul %1$s>%2$s</ul>';Changelog
Introduced in 5.8.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-includes/blocks/page-list.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.