wppaste
WordPress

the_block_editor_meta_box_post_form_hidden_fields( WP_Post $post )

Since
5.0.0
Source
wp-admin/includes/post.php:2537
Renders the hidden form required for the meta boxes form.

Compatibility

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

Performance profile

How much work a call to the_block_editor_meta_box_post_form_hidden_fields() 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
Scales with input

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

Instructions
103–113

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

Plugin surface
3 hooks

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

Called by
1

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

What it touches

  • hookthird-party callbacksdo_action()called directly
  • querycontent queryget_post()one call below the_block_editor_meta_box_post_form_hidden_fields()

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 · 4 distinct outcomes

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

WhenInstructionsCalls it makes
always103–105esc_attr(), wp_get_referer(), wp_get_current_user(), wp_nonce_field(), ob_start(), do_action(), do_action(), ob_get_clean(), wp_html_split(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), get_post_status(), wp_nonce_field(), wp_nonce_field(), wp_nonce_field(), do_action()
always107–109esc_attr(), wp_get_referer(), wp_get_current_user(), wp_nonce_field(), ob_start(), do_action(), do_action(), ob_get_clean(), wp_html_split(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), get_post_status(), wp_original_referer_field(), wp_nonce_field(), wp_nonce_field(), wp_nonce_field(), do_action()
always107–109esc_attr(), wp_get_referer(), wp_get_current_user(), wp_nonce_field(), ob_start(), do_action(), do_action(), ob_get_clean(), wp_html_split(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_url(), get_post_status(), wp_nonce_field(), wp_nonce_field(), wp_nonce_field(), do_action()
always111–113esc_attr(), wp_get_referer(), wp_get_current_user(), wp_nonce_field(), ob_start(), do_action(), do_action(), ob_get_clean(), wp_html_split(), esc_attr(), esc_attr(), esc_attr(), esc_attr(), esc_url(), get_post_status(), wp_original_referer_field(), wp_nonce_field(), wp_nonce_field(), wp_nonce_field(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev119103–11271 fewer instruction than PHP 8.5
8.5120103–1137
8.4120103–11376 fewer instructions than PHP 8.3
8.3126103–1137
8.2126103–1137
8.1126103–1137
7.4126103–1137

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

3 hooks fire while the_block_editor_meta_box_post_form_hidden_fields() runs, in this order:

  1. do_action( edit_form_after_title )actionline 2557 (+20 into the body)

    Fires after the title field.

  2. do_action( edit_form_advanced )actionline 2559 (+22 into the body)

    Fires after 'normal' context meta boxes have been output for all post types other than 'page'.

  3. do_action( block_editor_meta_box_hidden_fields )actionline 2601 (+64 into the body)

    Adds hidden input fields to the meta box save form.

Uses · 10

Used by · 1

Source code

function the_block_editor_meta_box_post_form_hidden_fields( $post ) {	$form_extra = '';	if ( 'auto-draft' === $post->post_status ) {		$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";	}	$form_action  = 'editpost';	$nonce_action = 'update-post_' . $post->ID;	$form_extra  .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />";	$referer      = wp_get_referer();	$current_user = wp_get_current_user();	$user_id      = $current_user->ID;	wp_nonce_field( $nonce_action ); 	/*	 * Some meta boxes hook into these actions to add hidden input fields in the classic post form.	 * For backward compatibility, we can capture the output from these actions,	 * and extract the hidden input fields.	 */	ob_start();	/** This filter is documented in wp-admin/edit-form-advanced.php */	do_action( 'edit_form_after_title', $post );	/** This filter is documented in wp-admin/edit-form-advanced.php */	do_action( 'edit_form_advanced', $post );	$classic_output = ob_get_clean(); 	$classic_elements = wp_html_split( $classic_output ); 	foreach ( $classic_elements as $element ) {		if ( ! str_starts_with( $element, '<input ' ) ) {			continue;		} 		if ( preg_match( '/\stype=[\'"]hidden[\'"]\s/', $element ) ) {			echo $element;		}	}	?>	<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_id; ?>" />	<input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />	<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />	<input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post->post_type ); ?>" />	<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" />	<input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" /> 	<?php	if ( 'draft' !== get_post_status( $post ) ) {		wp_original_referer_field( true, 'previous' );	}	echo $form_extra;	wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );	wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );	// Permalink title nonce.	wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 	/**	 * Adds hidden input fields to the meta box save form.	 *	 * Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to	 * the server when meta boxes are saved.	 *	 * @since 5.0.0	 *	 * @param WP_Post $post The post that is being edited.	 */	do_action( 'block_editor_meta_box_hidden_fields', $post );}

Changelog

Introduced in 5.0.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/post.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.