TwentyTwenty_Walker_Page::start_el( string $output, WP_Post $data_object, int $depth = 0, array $args = array(), int $current_object_id = 0 )
- Since
- Twenty Twenty 1.0, Twenty Twenty 1.9 Renamed <code>$page</code> to <code>$data_object</code> and <code>$current_page</code> to <code>$current_object_id</code> to match parent class for PHP 8 named parameter support.
- Source
wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-page.php:34
Compatibility
- WordPress
- since Twenty Twenty 1.9 Renamed <code>$page</code> to <code>$data_object</code> and <code>$current_page</code> to <code>$current_object_id</code> to match parent class for PHP 8 named parameter support.
- 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 TwentyTwenty_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
- 118–199
- 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 270.
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 TwentyTwenty_Walker_Page::start_el() - serializeserialisation
maybe_unserialize()one call below TwentyTwenty_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 TwentyTwenty_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) | 118–144 | get_option(), apply_filters(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && empty($args) | 123–149 | get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && empty($args) | 129–155 | get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) | 132–160 | get_option(), apply_filters(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && empty($current_page_id) && $current_page_id !== false | 134–157 | get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters() |
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) | 137–165 | get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) | 143–171 | get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) && $current_page_id !== false | 148–173 | get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date() |
empty($current_page_id) && empty($args) | 157–170 | get_option(), apply_filters(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters() |
empty($current_page_id) && empty($args) | 162–175 | get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters() |
empty($current_page_id) && empty($args) | 168–181 | get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters() |
empty($current_page_id) && !empty($args) | 171–186 | get_option(), apply_filters(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters(), mysql2date() |
4 further outcomes, up to 199 instructions
empty($current_page_id) && $current_page_id !== false | 173–183 | get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters() |
empty($current_page_id) && !empty($args) | 176–191 | get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters(), mysql2date() |
empty($current_page_id) && !empty($args) | 182–197 | get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters(), mysql2date() |
empty($current_page_id) && !empty($args) && $current_page_id !== false | 187–199 | get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), 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 | 268 | 118–199 | 29 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 270 | 118–199 | 29 | |
| 8.4 | 270 | 118–199 | 29 | 5 fewer instructions than PHP 8.3 |
| 8.3 | 275 | 120–201 | 29 | |
| 8.2 | 275 | 120–201 | 29 | |
| 8.1 | 275 | 120–201 | 29 | 4 fewer instructions than PHP 7.4 |
| 7.4 | 279 | 122–204 | 29 |
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 TwentyTwenty_Walker_Page::start_el() runs, in this order:
- apply_filters( page_css_class )filterline 71 (+37 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 87 (+53 into the body)
Filters the HTML attributes applied to a page menu item's anchor element.
Uses · 11
- 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.
- twentytwenty_toggle_duration()Toggles animation duration in milliseconds.
- absint()Converts a value to non-negative integer.
- twentytwenty_get_theme_svg()Gets information about the SVG icon.
- 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"; } else { $t = ''; } 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 === $current_page_id ) { $css_class[] = 'current_page_item'; } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) { $css_class[] = 'current_page_parent'; } } elseif ( get_option( 'page_for_posts' ) === $page->ID ) { $css_class[] = 'current_page_parent'; } /** This filter is documented in wp-includes/class-walker-page.php */ $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)', 'twentytwenty' ), $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 === $current_page_id ) ? 'page' : ''; /** This filter is documented in wp-includes/class-walker-page.php */ $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id ); $attributes = ''; foreach ( $atts as $attr => $value ) { if ( ! empty( $value ) ) { $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); $attributes .= ' ' . $attr . '="' . $value . '"'; } } $args['list_item_before'] = ''; $args['list_item_after'] = ''; // Wrap the link in a div and append a sub menu toggle. if ( isset( $args['show_toggles'] ) && true === $args['show_toggles'] ) { // Wrap the menu item link contents in a div, used for positioning. $args['list_item_before'] = '<div class="ancestor-wrapper">'; $args['list_item_after'] = ''; // Add a toggle to items with children. if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { $toggle_target_string = '.menu-modal .page-item-' . $page->ID . ' > ul'; $toggle_duration = twentytwenty_toggle_duration(); // Add the sub menu toggle. $args['list_item_after'] .= '<button class="toggle sub-menu-toggle fill-children-current-color" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="' . absint( $toggle_duration ) . '" aria-expanded="false"><span class="screen-reader-text">' .Changelog
Introduced in Twenty Twenty 1.9 Renamed <code>$page</code> to <code>$data_object</code> and <code>$current_page</code> to <code>$current_object_id</code> to match parent class for PHP 8 named parameter support.. 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-content/themes/twentytwenty/classes/class-twentytwenty-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.