wppaste
WordPress

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
Outputs the beginning of the current element in the tree.

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

Reaches the database via get_post().

Scaling
Scales with input

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

Instructions
118–199

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

Plugin surface
3 hooks

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.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below TwentyTwenty_Walker_Page::start_el()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
!isset($args) && !isset($value) && empty($current_page_id) && empty($args)118–144get_option(), apply_filters(), get_permalink(), apply_filters(), apply_filters()
!isset($args) && !isset($value) && empty($current_page_id) && empty($args)123–149get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters()
!isset($args) && !isset($value) && empty($current_page_id) && empty($args)129–155get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters()
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args)132–160get_option(), apply_filters(), get_permalink(), apply_filters(), apply_filters(), mysql2date()
!isset($args) && !isset($value) && empty($current_page_id) && $current_page_id !== false134–157get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters()
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args)137–165get_option(), apply_filters(), esc_attr(), get_permalink(), apply_filters(), apply_filters(), mysql2date()
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args)143–171get_option(), apply_filters(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date()
!isset($args) && !isset($value) && empty($current_page_id) && !empty($args) && $current_page_id !== false148–173get_option(), apply_filters(), esc_attr(), __(), sprintf(), get_permalink(), apply_filters(), apply_filters(), mysql2date()
empty($current_page_id) && empty($args)157–170get_option(), apply_filters(), get_permalink(), apply_filters(), twentytwenty_toggle_duration(), absint(), __(), twentytwenty_get_theme_svg(), apply_filters()
empty($current_page_id) && empty($args)162–175get_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–181get_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–186get_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 !== false173–183get_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–191get_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–197get_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 !== false187–199get_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

PHPCompiledExecutedBranchesNotes
8.6-dev268118–199292 fewer instructions than PHP 8.5
8.5270118–19929
8.4270118–199295 fewer instructions than PHP 8.3
8.3275120–20129
8.2275120–20129
8.1275120–201294 fewer instructions than PHP 7.4
7.4279122–20429

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:

  1. 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.

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

  3. apply_filters( the_title )filterline 138 (+104 into the body)

    Filters the post title.

Uses · 11

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.

  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.

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.
Twenty Twenty 1.9 Renamed $page to $data_object and $current_page to $current_object_id to match parent class for PHP 8 named parameter support.from the docblock
Twenty Twenty 1.0
Twenty Twenty 1.0from the docblock

About 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.