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
- Scaling
- Constant
- Instructions
- 5
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 119.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5 | wp_interactivity_get_context() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 119 | 5 | 7 | |
| 8.5 | 119 | 5 | 7 | |
| 8.4 | 119 | 5 | 7 | |
| 8.3 | 119 | 5 | 7 | |
| 8.2 | 119 | 5 | 7 | 1 fewer instruction than PHP 8.1 |
| 8.1 | 120 | 5 | 7 | |
| 7.4 | 120 | 5 | 7 |
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
- wp_unique_id()Gets unique ID.
- wp_interactivity_state()Gets and/or sets the initial state of an Interactivity API store for a given namespace.
- wp_interactivity_get_context()Gets the current Interactivity API context for a given namespace.
- WP_HTML_Tag_Processor::__construct()Constructor.
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.
Signature, return type and hooks compared across 3 parsed releases.
$attributes retyped from untyped to array.verified against source$content retyped from untyped to string.verified against sourceAbout 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.