do_accordion_sections( string|object $screen, string $context, mixed $data_object ): int
- Since
- 3.6.0
- Source
wp-admin/includes/template.php:1537
Description
Largely made up of abstracted code from do_meta_boxes(), this function serves to build meta boxes as list items for display as a collapsible accordion.
Compatibility
- WordPress
- since 3.6.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
$screenstring|object- The screen identifier.
$contextstring- The screen context for which to display accordion sections.
$data_objectmixed- Gets passed to the section callback function as the first parameter.
Return value
int- Number of meta boxes as accordion sections.
Performance profile
How much work a call to do_accordion_sections() 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
- Light
- Scaling
- Scales with input
- Instructions
- 24–31
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
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 123.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below do_accordion_sections()
Further down the call graph this can also reach option, query, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost do_accordion_sections() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($screen) && !is_string($screen) | 24–27 | wp_enqueue_script(), get_hidden_meta_boxes() |
empty($screen) | 26–29 | wp_enqueue_script(), get_current_screen(), get_hidden_meta_boxes() |
!empty($screen) && is_string($screen) | 28–31 | wp_enqueue_script(), convert_to_screen(), get_hidden_meta_boxes() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 123 | 24–31 | 13 | |
| 8.5 | 123 | 24–31 | 13 | |
| 8.4 | 123 | 24–31 | 13 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 126 | 24–31 | 13 | |
| 8.2 | 126 | 24–31 | 13 | |
| 8.1 | 126 | 24–31 | 13 | |
| 7.4 | 126 | 24–31 | 13 |
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 · 7
- wp_enqueue_script()Enqueues a script.
- get_current_screen()Get the current screen object
- convert_to_screen()Converts a screen string to a screen object.
- get_hidden_meta_boxes()Gets an array of IDs of hidden meta boxes.
- esc_attr()Escaping for HTML attributes.
- esc_html()Escaping for HTML blocks.
- postbox_classes()Returns the list of classes to be used by a meta box.
Source code
function do_accordion_sections( $screen, $context, $data_object ) { global $wp_meta_boxes; wp_enqueue_script( 'accordion' ); if ( empty( $screen ) ) { $screen = get_current_screen(); } elseif ( is_string( $screen ) ) { $screen = convert_to_screen( $screen ); } $page = $screen->id; $hidden = get_hidden_meta_boxes( $screen ); ?> <div id="side-sortables" class="accordion-container"> <ul class="outer-border"> <?php $i = 0; $first_open = false; if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { if ( false === $box || ! $box['title'] ) { continue; } ++$i; $hidden_class = in_array( $box['id'], $hidden, true ) ? 'hide-if-js' : ''; $open_class = ''; $aria_expanded = 'false'; if ( ! $first_open && empty( $hidden_class ) ) { $first_open = true; $open_class = 'open'; $aria_expanded = 'true'; } ?> <li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"> <h3 class="accordion-section-title hndle"> <button type="button" class="accordion-trigger" aria-expanded="<?php echo $aria_expanded; ?>" aria-controls="<?php echo esc_attr( $box['id'] ); ?>-content"> <span class="accordion-title"> <?php echo esc_html( $box['title'] ); ?> <span class="dashicons dashicons-arrow-down" aria-hidden="true"></span> </span> </button> </h3> <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>-content"> <div class="inside"> <?php call_user_func( $box['callback'], $data_object, $box ); ?> </div><!-- .inside --> </div><!-- .accordion-section-content --> </li><!-- .accordion-section --> <?php } } } } ?> </ul><!-- .outer-border --> </div><!-- .accordion-container --> <?php return $i;}Changelog
Introduced in 3.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/template.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.