wppaste
WordPress

block_core_accordion_item_render( array $attributes, string $content )

Source
wp-includes/blocks/accordion-item.php:13

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$attributesarray
$contentstring

Performance profile

How much work a call to block_core_accordion_item_render() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
5

Executed per call on PHP 8.5. The body compiles to 119.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

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

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 block_core_accordion_item_render() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always5wp_interactivity_get_context()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11957
8.511957
8.411957
8.311957
8.2119571 fewer instruction than PHP 8.1
8.112057
7.412057

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

Source code

function block_core_accordion_item_render( array $attributes, string $content ): string {	if ( '' === $content ) {		return $content;	} 	$p         = new WP_HTML_Tag_Processor( $content );	$unique_id = wp_unique_id( 'accordion-item-' ); 	// Initialize the state of the item on the server using a closure,	// since we need to get derived state based on the current context.	wp_interactivity_state(		'core/accordion',		array(			'isOpen' => function () {				$context = wp_interactivity_get_context();				return $context['openByDefault'];			},		)	); 	if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion-item' ) ) ) {		$open_by_default = $attributes['openByDefault'] ? 'true' : 'false';		$p->set_attribute( 'data-wp-context', '{ "id": "' . $unique_id . '", "openByDefault": ' . $open_by_default . ' }' );		$p->set_attribute( 'data-wp-class--is-open', 'state.isOpen' );		$p->set_attribute( 'data-wp-init', 'callbacks.initAccordionItems' );		$p->set_attribute( 'data-wp-on-window--hashchange', 'callbacks.hashChange' ); 		if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion-heading__toggle' ) ) ) {			$p->set_attribute( 'data-wp-on--click', 'actions.toggle' );			$p->set_attribute( 'id', $unique_id );			$p->set_attribute( 'aria-controls', $unique_id . '-panel' );			$p->set_attribute( 'data-wp-bind--aria-expanded', 'state.isOpen' ); 			if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion-panel' ) ) ) {				$p->set_attribute( 'id', $unique_id . '-panel' );				$p->set_attribute( 'aria-labelledby', $unique_id );				$p->set_attribute( 'data-wp-bind--hidden', 'state.isHidden' );				$p->set_attribute( 'data-wp-on--beforematch', 'actions.handleBeforeMatch' ); 				// Only modify content if all directives have been set.				$content = $p->get_updated_html();			}		}	} 	/*	 * If an Accordion Item is collapsed by default, ensure any contained IMG has fetchpriority=low to deprioritize it	 * from contending with resources in the critical rendering path. In contrast, remove the loading attribute to	 * prevent the image from not being available when the item is expanded.	 */	if ( ! $attributes['openByDefault'] ) {		$processor = new WP_HTML_Tag_Processor( $content );		while ( $processor->next_tag( 'IMG' ) ) {			$processor->set_attribute( 'fetchpriority', 'low' );		}		$content = $processor->get_updated_html();	} 	return $content;}

Changelog

2 changes between 6.9.7 and 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

7.0.4
Parameter $attributes retyped from untyped to array.verified against source
7.0.4
Parameter $content retyped from untyped to string.verified against source

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/blocks/accordion-item.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.