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
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
- Scaling
- Constant
- Instructions
- 74–94
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 105.
Third-party callbacks on 'media_upload_form_url' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below media_upload_type_form() - querycontent query
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 74–78 | media_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–92 | media_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–94 | media_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 105 | 74–94 | 4 | |
| 8.5 | 105 | 74–94 | 4 | |
| 8.4 | 105 | 74–94 | 4 | 1 more instruction than PHP 8.3 |
| 8.3 | 104 | 74–94 | 4 | |
| 8.2 | 104 | 74–94 | 4 | |
| 8.1 | 104 | 74–94 | 4 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 105 | 74–95 | 4 |
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:
- apply_filters( media_upload_form_url )filterline 2367 (+16 into the body)
Filters the media upload form action URL.
Uses · 14
- media_upload_header()Outputs the legacy media upload header.
- admin_url()Retrieves the URL to the admin area for the current site.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_user_setting()Retrieves user interface setting value based on setting name.
- esc_url()Checks and cleans a URL.
- submit_button()Echoes a submit button, with provided text and appropriate class(es).
- wp_nonce_field()Retrieves or display nonce hidden field for forms.
- _e()Displays translated text.
- media_upload_form()Outputs the legacy media upload form.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- add_filter()Adds a callback function to a filter hook.
- get_media_items()Retrieves HTML for media items of post gallery.
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.
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.