Walker_Page::start_el( string $output, WP_Post $data_object, int $depth = 0, array $args = array(), int $current_object_id = 0 )
- Since
- 2.1.0, 5.9.0
- Source
wp-includes/class-walker-page.php:105
Compatibility
- WordPress
- since 5.9.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
$outputstring- Used to append additional content. Passed by reference.
$data_objectWP_Post- Page data object.
$depthintoptional- Depth of page. Used for padding. Default 0.Default:
0 $argsarrayoptional- Array of arguments. Default empty array.Default:
array() $current_object_idintoptional- ID of the current page. Default 0.Default:
0
Performance profile
How much work a call to Walker_Page::start_el() 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
- 107–157
- Plugin surface
- 3 hooks
- Called by
- 0
Reaches the database via get_post().
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 215.
Third-party callbacks on 'page_css_class', 'page_menu_link_attributes', 'the_title' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below Walker_Page::start_el() - serializeserialisation
maybe_unserialize()one call below Walker_Page::start_el()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Walker_Page::start_el() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($args) && !isset($value) && empty($current_page_id) && empty($args) | 107–113 | get_option(), apply_filters(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && !empty($current_page_id) && empty($args) | 110–128 | get_post(), apply_filters(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && empty($args) | 112–118 | get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && !empty($current_page_id) && empty($args) | 115–131 | get_post(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && empty($args) | 117–123 | get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && !empty($current_page_id) && empty($args) | 120–138 | get_post(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) | 121–129 | get_option(), apply_filters(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && empty($current_page_id) && empty($args) | 122–128 | get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && !empty($current_page_id) && !empty($args) | 124–144 | get_post(), apply_filters(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && !empty($current_page_id) && empty($args) | 125–141 | get_post(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) | 126–134 | get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && !empty($current_page_id) && !empty($args) | 129–147 | get_post(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
4 further outcomes, up to 157 instructions
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) | 131–139 | get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && !empty($current_page_id) && !empty($args) | 134–154 | get_post(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) | 136–144 | get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && !empty($current_page_id) && !empty($args) | 139–157 | get_post(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
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 | 213 | 107–157 | 25 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 215 | 107–157 | 25 | |
| 8.4 | 215 | 107–157 | 25 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 221 | 110–163 | 25 | |
| 8.2 | 221 | 110–163 | 25 | |
| 8.1 | 221 | 110–163 | 25 | 6 fewer instructions than PHP 7.4 |
| 7.4 | 227 | 112–164 | 25 |
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.
Hooks and filters fired · 3
3 hooks fire while Walker_Page::start_el() runs, in this order:
- apply_filters( page_css_class )filterline 159 (+54 into the body)
Filters the list of CSS classes to include with each page item in the list.
- apply_filters( page_menu_link_attributes )filterline 190 (+85 into the body)
Filters the HTML attributes applied to a page menu item's anchor element.
Uses · 8
- get_post()Retrieves post data given a post ID or post object.
- get_option()Retrieves an option value based on an option name.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- esc_attr()Escaping for HTML attributes.
- __()Retrieves the translation of $text.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- esc_url()Checks and cleans a URL.
- mysql2date()Converts given MySQL date string into a different format.
Source code
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) { // Restores the more descriptive, specific name for use within this method. $page = $data_object; $current_page_id = $current_object_id; if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { $t = "\t"; $n = "\n"; } else { $t = ''; $n = ''; } if ( $depth ) { $indent = str_repeat( $t, $depth ); } else { $indent = ''; } $css_class = array( 'page_item', 'page-item-' . $page->ID ); if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { $css_class[] = 'page_item_has_children'; } if ( ! empty( $current_page_id ) ) { $_current_page = get_post( $current_page_id ); if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) { $css_class[] = 'current_page_ancestor'; } if ( $page->ID === (int) $current_page_id ) { $css_class[] = 'current_page_item'; } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) { $css_class[] = 'current_page_parent'; } } elseif ( (int) get_option( 'page_for_posts' ) === $page->ID ) { $css_class[] = 'current_page_parent'; } /** * Filters the list of CSS classes to include with each page item in the list. * * @since 2.8.0 * * @see wp_list_pages() * * @param string[] $css_class An array of CSS classes to be applied to each list item. * @param WP_Post $page Page data object. * @param int $depth Depth of page, used for padding. * @param array $args An array of arguments. * @param int $current_page_id ID of the current page. */ $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page_id ) ); $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : ''; if ( '' === $page->post_title ) { /* translators: %d: ID of a post. */ $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); } $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; $atts = array(); $atts['href'] = get_permalink( $page->ID ); $atts['aria-current'] = ( $page->ID === (int) $current_page_id ) ? 'page' : ''; /** * Filters the HTML attributes applied to a page menu item's anchor element. * * @since 4.8.0 * * @param array $atts { * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. * * @type string $href The href attribute. * @type string $aria-current The aria-current attribute. * }Changelog
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$page to $data_object and $current_page to $current_object_id to match parent class for PHP 8 named parameter support.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-walker-page.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.