wppaste
WordPress

do_meta_boxes( string|WP_Screen $screen, string $context, mixed $data_object ): int

Since
2.5.0
Source
wp-admin/includes/template.php:1306
Meta-Box template function.

Compatibility

WordPress
since 2.5.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|WP_Screen
The screen identifier. If you have used add_menu_page() or add_submenu_page() to create a new screen (and hence screen_id) make sure your menu slug conforms to the limits of sanitize_key() otherwise the 'screen' menu may not correctly render on your page.
$contextstring
The screen context for which to display meta boxes.
$data_objectmixed
Gets passed to the meta box callback function as the first parameter.
Often this is the object that's the focus of the current screen, for example a WP_Post or WP_Comment object.

Return value

int
Number of meta_boxes.

Performance profile

How much work a call to do_meta_boxes() 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
34–37

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below do_meta_boxes()

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 · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost do_meta_boxes() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!empty($screen) && !is_string($screen)34–37get_hidden_meta_boxes(), esc_attr(), printf(), get_user_option()

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-dev30634–3739
8.530634–3739
8.430634–37393 fewer instructions than PHP 8.3
8.330934–3739
8.230934–3739
8.130934–3739
7.430934–3739

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

Used by · 2

Source code

function do_meta_boxes( $screen, $context, $data_object ) {	global $wp_meta_boxes;	static $already_sorted = false; 	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 ); 	printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) ); 	/*	 * Grab the ones the user has manually sorted.	 * Pull them out of their previous context/priority and into the one the user chose.	 */	$sorted = get_user_option( "meta-box-order_$page" ); 	if ( ! $already_sorted && $sorted ) {		foreach ( $sorted as $box_context => $ids ) {			foreach ( explode( ',', $ids ) as $id ) {				if ( $id && 'dashboard_browser_nag' !== $id ) {					add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );				}			}		}	} 	$already_sorted = true; 	$i = 0; 	if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {		foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {			if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {				foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {					if ( false === $box || ! $box['title'] ) {						continue;					} 					$block_compatible = true;					if ( is_array( $box['args'] ) ) {						// If a meta box is just here for back compat, don't show it in the block editor.						if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {							continue;						} 						if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {							$block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];							unset( $box['args']['__block_editor_compatible_meta_box'] );						} 						// If the meta box is declared as incompatible with the block editor, override the callback function.						if ( ! $block_compatible && $screen->is_block_editor() ) {							$box['old_callback'] = $box['callback'];							$box['callback']     = 'do_block_editor_incompatible_meta_box';						} 						if ( isset( $box['args']['__back_compat_meta_box'] ) ) {							$block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];							unset( $box['args']['__back_compat_meta_box'] );						}					} 					++$i;					// get_hidden_meta_boxes() doesn't apply in the block editor.					$hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : '';					echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . ' role="region" aria-label="' . esc_attr( wp_strip_all_tags( $box['title'] ) ) . '">' . "\n"; 					echo '<div class="postbox-header">';					echo '<h2 class="hndle" id="' . $box['id'] . '-title">';					if ( 'dashboard_php_nag' === $box['id'] ) {						echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>';						echo '<span class="screen-reader-text">' .							/* translators: Hidden accessibility text. */							__( 'Warning:' ) .

Changelog

Introduced in 2.5.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 7.1.0 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.