wppaste
WordPress

do_accordion_sections( string|object $screen, string $context, mixed $data_object ): int

Since
3.6.0
Source
wp-admin/includes/template.php:1537
Meta Box Accordion Template Function.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
24–31

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

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 it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
!empty($screen) && !is_string($screen)24–27wp_enqueue_script(), get_hidden_meta_boxes()
empty($screen)26–29wp_enqueue_script(), get_current_screen(), get_hidden_meta_boxes()
!empty($screen) && is_string($screen)28–31wp_enqueue_script(), convert_to_screen(), get_hidden_meta_boxes()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev12324–3113
8.512324–3113
8.412324–31133 fewer instructions than PHP 8.3
8.312624–3113
8.212624–3113
8.112624–3113
7.412624–3113

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

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.

  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.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 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.