wppaste
WordPress

post_tags_meta_box( WP_Post $post, array $box )

Since
2.6.0
Source
wp-admin/includes/meta-boxes.php:572
Displays post tags 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
Tags meta box arguments.
  • $idstring

    Meta box 'id' attribute.
  • $titlestring

    Meta box title.
  • $callbackcallable

    Meta box display callback.
  • $argsarray

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

    Taxonomy.

Performance profile

How much work a call to post_tags_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 wp_get_object_terms().

Scaling
Constant

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

Instructions
80–115

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 post_tags_meta_box()
  • querycontent querywp_get_object_terms()one call below post_tags_meta_box()
  • cacheobject cachewp_cache_add()one call below post_tags_meta_box()

Further down the call graph this can also reach option, 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_tags_meta_box() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always80–96wp_parse_args(), esc_attr(), get_taxonomy(), current_user_can(), _x(), get_terms_to_edit(), disabled()
always104–115wp_parse_args(), esc_attr(), get_taxonomy(), current_user_can(), _x(), get_terms_to_edit(), disabled(), esc_attr_e()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev12380–1156
8.512380–1156
8.412380–11563 fewer instructions than PHP 8.3
8.312683–1186
8.212683–1186
8.112683–1186
7.412683–1186

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

  • wp_parse_args()Merges user defined arguments into defaults array.
  • esc_attr()Escaping for HTML attributes.
  • get_taxonomy()Retrieves the taxonomy object of $taxonomy.
  • current_user_can()Returns whether the current user has the specified capability.
  • _x()Retrieves translated string with gettext context.
  • get_terms_to_edit()Gets comma-separated list of terms available to edit for the given post ID.
  • disabled()Outputs the HTML disabled attribute.
  • esc_attr_e()Displays translated text that has been escaped for safe use in an attribute.

Source code

function post_tags_meta_box( $post, $box ) {	$defaults = array( 'taxonomy' => 'post_tag' );	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'] );	$user_can_assign_terms = current_user_can( $taxonomy->cap->assign_terms );	$comma                 = _x( ',', 'tag delimiter' );	$terms_to_edit         = get_terms_to_edit( $post->ID, $tax_name );	if ( ! is_string( $terms_to_edit ) ) {		$terms_to_edit = '';	}	?><div class="tagsdiv" id="<?php echo $tax_name; ?>">	<div class="jaxtag">	<div class="nojs-tags hide-if-js">		<label for="tax-input-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_or_remove_items; ?></label>		<p><textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php disabled( ! $user_can_assign_terms ); ?> aria-describedby="new-tag-<?php echo $tax_name; ?>-desc"><?php echo str_replace( ',', $comma . ' ', $terms_to_edit ); // textarea_escaped by esc_attr() ?></textarea></p>	</div>	<?php if ( $user_can_assign_terms ) : ?>	<div class="ajaxtag hide-if-no-js">		<label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>		<input data-wp-taxonomy="<?php echo $tax_name; ?>" type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" aria-describedby="new-tag-<?php echo $tax_name; ?>-desc" value="" />		<input type="button" class="button tagadd" value="<?php esc_attr_e( 'Add' ); ?>" />	</div>	<p class="howto" id="new-tag-<?php echo $tax_name; ?>-desc"><?php echo $taxonomy->labels->separate_items_with_commas; ?></p>	<?php elseif ( empty( $terms_to_edit ) ) : ?>		<p><?php echo $taxonomy->labels->no_terms; ?></p>	<?php endif; ?>	</div>	<ul class="tagchecklist" role="list"></ul></div>	<?php if ( $user_can_assign_terms ) : ?><p class="hide-if-no-js"><button type="button" class="button-link tagcloud-link" id="link-<?php echo $tax_name; ?>" aria-expanded="false"><?php echo $taxonomy->labels->choose_from_most_used; ?></button></p><?php endif; ?>	<?php}

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.