wppaste
WordPress

post_categories_meta_box( WP_Post $post, array $box )

Since
2.6.0
Source
wp-admin/includes/meta-boxes.php:635
Displays post categories form fields.

Compatibility

WordPress
since 2.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

$postWP_Post
Current post object.
$boxarray
Categories meta box arguments.
  • $idstring

    Meta box 'id' attribute.
  • $titlestring

    Meta box title.
  • $callbackcallable

    Meta box display callback.
  • $argsarray

    { Extra meta box arguments.
  • $taxonomystringdefault: 'category'. }

    Taxonomy.

Performance profile

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

Reaches the database via get_post().

Scaling
Constant

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

Instructions
92–184

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

Plugin surface
1 hook

Third-party callbacks on 'post_edit_category_parent_dropdown_args' run inside this call, and their cost is not bounded by anything here.

Called by
0

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

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • querycontent queryget_post()one call below post_categories_meta_box()

Further down the call graph this can also reach option, 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 · 2 distinct outcomes

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

WhenInstructionsCalls it makes
!current_user_can()92–95wp_parse_args(), esc_attr(), get_taxonomy(), esc_html(), wp_popular_terms_checklist(), taxonomy(), current_user_can()
current_user_can()181–184wp_parse_args(), esc_attr(), get_taxonomy(), esc_html(), wp_popular_terms_checklist(), taxonomy(), current_user_can(), __(), printf(), esc_attr(), apply_filters(), wp_dropdown_categories(), esc_attr(), wp_nonce_field()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev18792–1844
8.518792–1844
8.418792–1844
8.318792–1844
8.218792–1844
8.118792–18441 fewer instruction than PHP 7.4
7.418892–1854

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.

Hooks and filters fired · 1

One hook fires while post_categories_meta_box() runs, in this order:

  1. apply_filters( post_edit_category_parent_dropdown_args )filterline 724 (+89 into the body)

    Filters the arguments for the taxonomy parent dropdown on the Post Edit page.

Uses · 11

Source code

function post_categories_meta_box( $post, $box ) {	$defaults = array( 'taxonomy' => 'category' );	if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {		$args = array();	} else {		$args = $box['args'];	}	$parsed_args = wp_parse_args( $args, $defaults );	$tax_name    = esc_attr( $parsed_args['taxonomy'] );	$taxonomy    = get_taxonomy( $parsed_args['taxonomy'] );	?>	<div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">		<ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs" role="tablist">			<li class="tabs"><a href="#<?php echo $tax_name; ?>-all" role="tab" aria-selected="true" aria-controls="<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>			<li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop" role="tab" aria-controls="<?php echo $tax_name; ?>-pop"><?php echo esc_html( $taxonomy->labels->most_used ); ?></a></li>		</ul> 		<div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;" role="tabpanel">			<ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >				<?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>			</ul>		</div> 		<div id="<?php echo $tax_name; ?>-all" class="tabs-panel" role="tabpanel">			<?php			$name = ( 'category' === $tax_name ) ? 'post_category' : 'tax_input[' . $tax_name . ']';			// Allows for an empty term set to be sent. 0 is an invalid term ID and will be ignored by empty() checks.			echo "<input type='hidden' name='{$name}[]' value='0' />";			?>			<ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">				<?php				wp_terms_checklist(					$post->ID,					array(						'taxonomy'     => $tax_name,						'popular_cats' => $popular_ids,					)				);				?>			</ul>		</div>	<?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>			<div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">				<a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js taxonomy-add-new">					<?php						/* translators: %s: Add New taxonomy label. */						printf( __( '+ %s' ), $taxonomy->labels->add_new_item );					?>				</a>				<p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">					<label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>					<input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true" />					<label class="screen-reader-text" for="new<?php echo $tax_name; ?>_parent">						<?php echo $taxonomy->labels->parent_item_colon; ?>					</label>					<?php					$parent_dropdown_args = array(						'taxonomy'         => $tax_name,						'hide_empty'       => 0,						'name'             => 'new' . $tax_name . '_parent',						'orderby'          => 'name',						'hierarchical'     => 1,						'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',					); 					/**					 * Filters the arguments for the taxonomy parent dropdown on the Post Edit page.					 *					 * @since 4.4.0					 *					 * @param array $parent_dropdown_args {					 *     Optional. Array of arguments to generate parent dropdown.					 *					 *     @type string   $taxonomy         Name of the taxonomy to retrieve.					 *     @type bool     $hide_if_empty    True to skip generating markup if no					 *                                      categories are found. Default 0.					 *     @type string   $name             Value for the 'name' attribute					 *                                      of the select element.					 *                                      Default "new{$tax_name}_parent".					 *     @type string   $orderby          Which column to use for ordering

Changelog

Introduced in 2.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 7.1.0 tag, from src/wp-admin/includes/meta-boxes.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.