wppaste
WordPress

media_upload_type_form( string $type = 'file', array $errors = null, int|WP_Error $id = null )

Since
2.5.0
Source
wp-admin/includes/media.php:2351
Outputs the legacy media upload form for a given media type.

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

$typestringoptional
Default: 'file'
$errorsarrayoptional
Default: null
$idint|WP_Erroroptional
Default: null

Performance profile

How much work a call to media_upload_type_form() 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
74–94

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

Plugin surface
1 hook

Third-party callbacks on 'media_upload_form_url' 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
  • optionoption read or writeget_option()one call below media_upload_type_form()
  • querycontent queryget_post()one call below media_upload_type_form()

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

WhenInstructionsCalls it makes
always74–78media_upload_header(), admin_url(), apply_filters(), get_user_setting(), esc_url(), submit_button(), wp_nonce_field(), _e(), media_upload_form(), __(), submit_button()
is_wp_error()88–92media_upload_header(), admin_url(), apply_filters(), get_user_setting(), esc_url(), submit_button(), wp_nonce_field(), _e(), media_upload_form(), is_wp_error(), ->get_error_message(), esc_html(), exit(), __(), submit_button()
!is_wp_error()90–94media_upload_header(), admin_url(), apply_filters(), get_user_setting(), esc_url(), submit_button(), wp_nonce_field(), _e(), media_upload_form(), is_wp_error(), add_filter(), get_media_items(), __(), submit_button()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10574–944
8.510574–944
8.410574–9441 more instruction than PHP 8.3
8.310474–944
8.210474–944
8.110474–9441 fewer instruction than PHP 7.4
7.410574–954

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 media_upload_type_form() runs, in this order:

  1. apply_filters( media_upload_form_url )filterline 2367 (+16 into the body)

    Filters the media upload form action URL.

Uses · 14

Show all 14
  • esc_html()Escaping for HTML blocks.
  • __()Retrieves the translation of $text.

Source code

function media_upload_type_form( $type = 'file', $errors = null, $id = null ) { 	media_upload_header(); 	$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" ); 	/**	 * Filters the media upload form action URL.	 *	 * @since 2.6.0	 *	 * @param string $form_action_url The media upload form action URL.	 * @param string $type            The type of media. Default 'file'.	 */	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );	$form_class      = 'media-upload-form type-form validate'; 	if ( get_user_setting( 'uploader' ) ) {		$form_class .= ' html-uploader';	} 	?>	<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">		<?php submit_button( '', 'hidden', 'save', false ); ?>	<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />		<?php wp_nonce_field( 'media-form' ); ?> 	<h3 class="media-title"><?php _e( 'Add media files from your computer' ); ?></h3> 	<?php media_upload_form( $errors ); ?> 	<script>	jQuery(function($){		var preloaded = $(".media-item.preloaded");		if ( preloaded.length > 0 ) {			preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});		}		updateMediaForm();	});	</script>	<div id="media-items">	<?php 	if ( $id ) {		if ( ! is_wp_error( $id ) ) {			add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 );			echo get_media_items( $id, $errors );		} else {			echo '<div id="media-upload-error">' . esc_html( $id->get_error_message() ) . '</div></div>';			exit;		}	} 	?>	</div> 	<p class="savebutton ml-submit">		<?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?>	</p>	</form>	<?php}

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/media.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.